| 350 |
ashish |
1 |
package in.shop2020.thrift.clients;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.utils.ConfigClientKeys;
|
|
|
4 |
import in.shop2020.utils.Logger;
|
|
|
5 |
import in.shop2020.utils.HelperService.Client;
|
|
|
6 |
|
|
|
7 |
import javax.annotation.PostConstruct;
|
|
|
8 |
import javax.annotation.PreDestroy;
|
|
|
9 |
|
| 767 |
rajveer |
10 |
import org.apache.thrift.TException;
|
| 350 |
ashish |
11 |
import org.apache.thrift.transport.TTransportException;
|
|
|
12 |
|
|
|
13 |
public class HelperServiceClient extends GenericServiceClient{
|
|
|
14 |
private Client client = null;
|
|
|
15 |
|
|
|
16 |
public HelperServiceClient(String clientIdentifier,
|
|
|
17 |
String hostConfigKey, String portConfigKey) throws Exception {
|
|
|
18 |
super(clientIdentifier, hostConfigKey, portConfigKey);
|
|
|
19 |
client = new Client(protocol);
|
|
|
20 |
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
public HelperServiceClient() throws Exception{
|
| 747 |
rajveer |
24 |
this(HelperServiceClient.class.getSimpleName(), ConfigClientKeys.helper_service_server_host.toString(), ConfigClientKeys.helper_service_server_port.toString());
|
| 495 |
rajveer |
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 |
}
|
| 350 |
ashish |
34 |
}
|
|
|
35 |
|
|
|
36 |
@PostConstruct
|
|
|
37 |
public 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 |
}
|
| 767 |
rajveer |
59 |
|
|
|
60 |
@Override
|
|
|
61 |
public void closeSession() {
|
|
|
62 |
try {
|
|
|
63 |
client.closeSession();
|
|
|
64 |
} catch (TException e) {
|
|
|
65 |
e.printStackTrace();
|
|
|
66 |
}
|
|
|
67 |
}
|
| 350 |
ashish |
68 |
|
|
|
69 |
}
|