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