| 303 |
ashish |
1 |
package in.shop2020.thrift.clients;
|
|
|
2 |
|
|
|
3 |
import javax.annotation.PostConstruct;
|
|
|
4 |
import javax.annotation.PreDestroy;
|
|
|
5 |
|
|
|
6 |
import org.apache.thrift.transport.TTransportException;
|
|
|
7 |
|
|
|
8 |
import in.shop2020.datalogger.DataLogger.Client;
|
|
|
9 |
import in.shop2020.utils.ConfigClientKeys;
|
|
|
10 |
import in.shop2020.utils.Logger;
|
|
|
11 |
|
|
|
12 |
public class DataLoggingClient extends GenericServiceClient{
|
|
|
13 |
|
|
|
14 |
private Client client = null;
|
|
|
15 |
|
|
|
16 |
public DataLoggingClient(String clientIdentifier, String hostConfigKey,
|
|
|
17 |
String portConfigKey) throws Exception {
|
|
|
18 |
super(clientIdentifier, hostConfigKey, portConfigKey);
|
|
|
19 |
client = new Client(protocol);
|
|
|
20 |
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
public DataLoggingClient()throws Exception{
|
|
|
24 |
this(DataLoggingClient.class.getSimpleName(), ConfigClientKeys.datalogging_service_local_hostname.toString(), ConfigClientKeys.datalogging_service_local_wrapper_port.toString());
|
|
|
25 |
if(transport.isOpen()){
|
|
|
26 |
Logger.log("Transport was already open", this);
|
|
|
27 |
}
|
|
|
28 |
try {
|
|
|
29 |
transport.open();
|
|
|
30 |
} catch (TTransportException e) {
|
|
|
31 |
Logger.log("Encountered exception while open transport "+ e, this);
|
|
|
32 |
}
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
@PostConstruct
|
|
|
36 |
private void openTransport(){
|
|
|
37 |
if(transport.isOpen()){
|
|
|
38 |
Logger.log("Transport was already open", this);
|
|
|
39 |
}
|
|
|
40 |
try {
|
|
|
41 |
transport.open();
|
|
|
42 |
} catch (TTransportException e) {
|
|
|
43 |
Logger.log("Encountered exception while open transport "+ e, this);
|
|
|
44 |
}
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public Client getClient(){
|
|
|
48 |
return client;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
@PreDestroy
|
|
|
52 |
private void closeTransport(){
|
|
|
53 |
if(transport != null && transport.isOpen()){
|
|
|
54 |
Logger.log("Closing transport :", this);
|
|
|
55 |
transport.close();
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
}
|