| 420 |
ashish |
1 |
package in.shop2020.thrift.clients;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.payments.PaymentService.Client;
|
|
|
4 |
import in.shop2020.utils.ConfigClientKeys;
|
|
|
5 |
import in.shop2020.utils.Logger;
|
|
|
6 |
|
|
|
7 |
import javax.annotation.PostConstruct;
|
|
|
8 |
import javax.annotation.PreDestroy;
|
|
|
9 |
|
|
|
10 |
import org.apache.thrift.transport.TTransportException;
|
|
|
11 |
|
|
|
12 |
public class PaymentServiceClient extends GenericServiceClient{
|
|
|
13 |
|
|
|
14 |
private Client client = null;
|
|
|
15 |
|
|
|
16 |
public PaymentServiceClient(String clientIdentifier,
|
|
|
17 |
String hostConfigKey, String portConfigKey) throws Exception {
|
|
|
18 |
super(clientIdentifier, hostConfigKey, portConfigKey);
|
|
|
19 |
client = new Client(protocol);
|
|
|
20 |
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
public PaymentServiceClient() throws Exception{
|
| 747 |
rajveer |
24 |
this(PaymentServiceClient.class.getSimpleName(), ConfigClientKeys.payments_service_server_host.toString() , ConfigClientKeys.payments_service_server_port.toString());
|
| 420 |
ashish |
25 |
if(transport.isOpen()){
|
|
|
26 |
Logger.log("Transport was already open", this);
|
|
|
27 |
}
|
|
|
28 |
try {
|
|
|
29 |
transport.open();
|
|
|
30 |
Logger.log("Transport opened", this);
|
|
|
31 |
} catch (TTransportException e) {
|
|
|
32 |
Logger.log("Encountered exception while open transport "+ e, this);
|
|
|
33 |
}
|
|
|
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 |
@PreDestroy
|
|
|
49 |
private void closeTransport(){
|
|
|
50 |
if(transport != null && transport.isOpen()){
|
|
|
51 |
Logger.log("Closing transport :", this);
|
|
|
52 |
transport.close();
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
public Client getClient(){
|
|
|
57 |
return client;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
}
|