Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
373 rajveer 1
package in.shop2020.thrift.clients;
2
 
3
import in.shop2020.serving.page.PageLoader.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
 
376 ashish 12
public class PageLoaderClient extends GenericServiceJavaClient{
373 rajveer 13
 
14
	private Client client = null;
15
 
16
	public PageLoaderClient(String clientIdentifier, String hostConfigKey,
17
			String portConfigKey) throws Exception {
18
		super(clientIdentifier, hostConfigKey, portConfigKey);
19
		client = new Client(protocol);
20
 
21
	}
22
 
23
	public PageLoaderClient()throws Exception{
24
		this(PageLoaderClient.class.getSimpleName(), ConfigClientKeys.pageloader_service_hostname.toString(), ConfigClientKeys.pageloader_service_port.toString());
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
	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
	}
59
 
60
}