Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
100 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;
100 ashish 7
import org.apache.thrift.transport.TTransportException;
8
 
380 ashish 9
import in.shop2020.model.v1.catalog.InventoryService.Client;
100 ashish 10
import in.shop2020.utils.ConfigClientKeys;
11
import in.shop2020.utils.Logger;
12
 
13
 
14
public class CatalogServiceClient extends GenericServiceClient {
15
 
16
	private Client client = null;
17
 
18
	public CatalogServiceClient(String clientIdentifier,
19
			String hostConfigKey, String portConfigKey) throws Exception {
20
		super(clientIdentifier, hostConfigKey, portConfigKey);
21
		client = new Client(protocol);
22
 
23
	}
24
 
25
	public CatalogServiceClient() throws Exception{
389 rajveer 26
		this(CatalogServiceClient.class.getSimpleName(), ConfigClientKeys.catalog_service_server_host.toString(), ConfigClientKeys.catalog_service_server_port.toString());
27
		if(transport.isOpen()){
28
			Logger.log("Transport was already open", this);
29
		}
30
		try {
31
			transport.open();
32
			Logger.log("Transport opened", this);
33
		} catch (TTransportException e) {
34
			Logger.log("Encountered exception while open transport "+ e, this);
35
		}
100 ashish 36
	}
37
 
38
	@PostConstruct
39
	private void openTransport(){
40
		if(transport.isOpen()){
41
			Logger.log("Transport was already open", this);
42
		}
43
		try {
44
			transport.open();
45
		} catch (TTransportException e) {
46
			Logger.log("Encountered exception while open transport "+ e, this);
47
		}
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
 
350 ashish 58
	public Client getClient(){
59
		return client;
60
	}
100 ashish 61
 
767 rajveer 62
	@Override
63
	public void closeSession() {
64
		try {
65
			client.closeSession();
66
		} catch (TException e) {
67
			e.printStackTrace();
68
		}
69
	}
70
 
100 ashish 71
}