Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
381 ashish 1
package in.shop2020.thrift.clients;
2
 
3
import in.shop2020.model.v1.widgets.WidgetService.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 WidgetServiceClient extends GenericServiceClient{
13
	private Client client = null;
14
 
15
	public WidgetServiceClient(String clientIdentifier, String hostConfigKey,
16
			String portConfigKey) throws Exception {
17
		super(clientIdentifier, hostConfigKey, portConfigKey);
18
		client = new Client(protocol);
19
 
20
	}
21
 
22
	public WidgetServiceClient()throws Exception{
23
		this(WidgetServiceClient.class.getSimpleName(), ConfigClientKeys.widget_service_hostname.toString(), ConfigClientKeys.widget_service_port.toString());
24
		if(transport.isOpen()){
25
			Logger.log("Transport was already open", this);
26
		}
27
		try {
28
			transport.open();
29
		} catch (TTransportException e) {
30
			Logger.log("Encountered exception while open transport "+ e, this);
31
		}
32
	}
33
 
34
	@PostConstruct
35
	private void openTransport(){
36
		if(transport.isOpen()){
37
			Logger.log("Transport was already open", this);
38
		}
39
		try {
40
			transport.open();
41
		} catch (TTransportException e) {
42
			Logger.log("Encountered exception while open transport "+ e, this);
43
		}
44
	}
45
 
46
	public Client getClient(){
47
		return client;
48
	}
49
 
50
	@PreDestroy
51
	private void closeTransport(){
52
		if(transport != null && transport.isOpen()){
53
			Logger.log("Closing transport :", this);
54
			transport.close();
55
		}
56
	}
57
 
58
}