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);
2283 ankur.sing 22
		if(transport.isOpen()){
23
            Logger.log("Transport was already open", this);
24
        }
25
        try {
26
            transport.open();
27
            Logger.log("Transport opened", this);
28
        } catch (TTransportException e) {
29
            Logger.log("Encountered exception while open transport "+ e, this);
30
        }
100 ashish 31
	}
32
 
33
	public CatalogServiceClient() throws Exception{
389 rajveer 34
		this(CatalogServiceClient.class.getSimpleName(), ConfigClientKeys.catalog_service_server_host.toString(), ConfigClientKeys.catalog_service_server_port.toString());
100 ashish 35
	}
36
 
37
	@PostConstruct
38
	private void openTransport(){
39
		if(transport.isOpen()){
40
			Logger.log("Transport was already open", this);
41
		}
42
		try {
43
			transport.open();
44
		} catch (TTransportException e) {
45
			Logger.log("Encountered exception while open transport "+ e, this);
46
		}
47
	}
48
 
49
	@PreDestroy
50
	private void closeTransport(){
51
		if(transport != null && transport.isOpen()){
52
			Logger.log("Closing transport :", this);
53
			transport.close();
54
		}
55
	}
56
 
350 ashish 57
	public Client getClient(){
58
		return client;
59
	}
100 ashish 60
 
767 rajveer 61
	@Override
62
	public void closeSession() {
63
		try {
64
			client.closeSession();
65
		} catch (TException e) {
66
			e.printStackTrace();
67
		}
68
	}
69
 
100 ashish 70
}