| 303 |
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;
|
| 303 |
ashish |
7 |
import org.apache.thrift.transport.TTransportException;
|
|
|
8 |
|
|
|
9 |
import in.shop2020.datalogger.DataLogger.Client;
|
|
|
10 |
import in.shop2020.utils.ConfigClientKeys;
|
|
|
11 |
import in.shop2020.utils.Logger;
|
|
|
12 |
|
|
|
13 |
public class DataLoggingClient extends GenericServiceClient{
|
|
|
14 |
|
|
|
15 |
private Client client = null;
|
|
|
16 |
|
|
|
17 |
public DataLoggingClient(String clientIdentifier, String hostConfigKey,
|
|
|
18 |
String portConfigKey) throws Exception {
|
|
|
19 |
super(clientIdentifier, hostConfigKey, portConfigKey);
|
|
|
20 |
client = new Client(protocol);
|
|
|
21 |
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
public DataLoggingClient()throws Exception{
|
|
|
25 |
this(DataLoggingClient.class.getSimpleName(), ConfigClientKeys.datalogging_service_local_hostname.toString(), ConfigClientKeys.datalogging_service_local_wrapper_port.toString());
|
|
|
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 |
}
|
|
|
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 |
public Client getClient(){
|
|
|
49 |
return client;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
@PreDestroy
|
|
|
53 |
private void closeTransport(){
|
|
|
54 |
if(transport != null && transport.isOpen()){
|
|
|
55 |
Logger.log("Closing transport :", this);
|
|
|
56 |
transport.close();
|
|
|
57 |
}
|
|
|
58 |
}
|
| 767 |
rajveer |
59 |
|
|
|
60 |
@Override
|
|
|
61 |
public void closeSession() {
|
|
|
62 |
try {
|
|
|
63 |
client.closeSession();
|
|
|
64 |
} catch (TException e) {
|
|
|
65 |
e.printStackTrace();
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
|
| 303 |
ashish |
69 |
}
|