Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
394 ashish 1
package in.shop2020.thrift.clients;
2
 
3
 
4
import in.shop2020.model.v1.user.UserContextService.Client;
5
import in.shop2020.utils.ConfigClientKeys;
6
import in.shop2020.utils.Logger;
7
 
8
import javax.annotation.PostConstruct;
9
import javax.annotation.PreDestroy;
10
 
767 rajveer 11
import org.apache.thrift.TException;
394 ashish 12
import org.apache.thrift.transport.TTransportException;
13
 
14
public class UserContextServiceClient extends GenericServiceClient{
15
 
16
	private Client client = null;
17
 
18
	public UserContextServiceClient(String clientIdentifier,
19
			String hostConfigKey, String portConfigKey) throws Exception {
20
		super(clientIdentifier, hostConfigKey, portConfigKey);
21
		client = new Client(protocol);
22
 
23
	}
24
 
25
	public UserContextServiceClient() throws Exception{
747 rajveer 26
		this(UserContextServiceClient.class.getSimpleName(), ConfigClientKeys.user_service_server_host.toString(), ConfigClientKeys.user_service_server_port.toString());
402 rajveer 27
		if(transport.isOpen()){
28
			Logger.log("Transport was already open", this);
29
		}
30
		try {
31
			transport.open();
32
		} catch (TTransportException e) {
33
			Logger.log("Encountered exception while open transport "+ e, this);
34
		}
35
 
394 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
 
58
	public Client getClient(){
59
		return client;
60
	}
767 rajveer 61
 
62
	@Override
63
	public void closeSession() {
64
		try {
65
			client.closeSession();
66
		} catch (TException e) {
67
			e.printStackTrace();
68
		}
69
	}
394 ashish 70
 
71
}