Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
68 ashish 1
package in.shop2020.thrift.clients;
2
 
3
import java.util.Date;
4
import java.util.List;
5
 
6
import javax.annotation.PostConstruct;
7
import javax.annotation.PreDestroy;
8
 
767 rajveer 9
import org.apache.thrift.TException;
68 ashish 10
import org.apache.thrift.transport.TTransportException;
11
 
12
import in.shop2020.model.v1.order.Billing;
13
import in.shop2020.model.v1.order.BillingInfo;
14
import in.shop2020.model.v1.order.OrderInfo;
15
import in.shop2020.model.v1.order.ShipmentInfo;
16
import in.shop2020.model.v1.order.ShipmentStatus;
17
import in.shop2020.model.v1.order.Transaction;
18
import in.shop2020.model.v1.order.TransactionStatus;
19
import in.shop2020.model.v1.order.TransactionService.Client;
20
import in.shop2020.utils.ConfigClientKeys;
21
import in.shop2020.utils.Logger;
22
 
23
public class TransactionServiceClient extends GenericServiceClient{
24
 
25
	private Client client = null;
26
 
27
	public TransactionServiceClient(String clientIdentifier,
28
			String hostConfigKey, String portConfigKey) throws Exception {
29
		super(clientIdentifier, hostConfigKey, portConfigKey);
30
		client = new Client(protocol);
31
 
32
	}
33
 
34
	public TransactionServiceClient()throws Exception{
411 rajveer 35
		this(TransactionServiceClient.class.getSimpleName(), ConfigClientKeys.transaction_service_server_host.toString(), ConfigClientKeys.transaction_service_server_port.toString());
193 ashish 36
		if(transport.isOpen()){
37
			Logger.log("Transport was already open", this);
38
		}
39
		try {
40
			transport.open();
41
		} catch (TTransportException e) {
42
			Logger.log("Encountered exception while open transport "+ e, this);
43
		}
68 ashish 44
	}
45
 
46
	@PostConstruct
47
	private void openTransport(){
48
		if(transport.isOpen()){
49
			Logger.log("Transport was already open", this);
50
		}
51
		try {
52
			transport.open();
53
		} catch (TTransportException e) {
54
			Logger.log("Encountered exception while open transport "+ e, this);
55
		}
56
	}
57
 
58
	//Api methods
59
	//TODO: Add logging to this class.
60
 
193 ashish 61
	public Client getClient(){
62
		return client;
68 ashish 63
	}
64
 
65
	@PreDestroy
66
	private void closeTransport(){
67
		if(transport != null && transport.isOpen()){
68
			Logger.log("Closing transport :", this);
69
			transport.close();
70
		}
71
	}
72
 
767 rajveer 73
	@Override
74
	public void closeSession() {
75
		try {
76
			client.closeSession();
77
		} catch (TException e) {
78
			e.printStackTrace();
79
		}
80
	}
68 ashish 81
}