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
 
11
import org.apache.thrift.transport.TTransportException;
12
 
13
public class UserContextServiceClient extends GenericServiceClient{
14
 
15
	private Client client = null;
16
 
17
	public UserContextServiceClient(String clientIdentifier,
18
			String hostConfigKey, String portConfigKey) throws Exception {
19
		super(clientIdentifier, hostConfigKey, portConfigKey);
20
		client = new Client(protocol);
21
 
22
	}
23
 
24
	public UserContextServiceClient() throws Exception{
747 rajveer 25
		this(UserContextServiceClient.class.getSimpleName(), ConfigClientKeys.user_service_server_host.toString(), ConfigClientKeys.user_service_server_port.toString());
402 rajveer 26
		if(transport.isOpen()){
27
			Logger.log("Transport was already open", this);
28
		}
29
		try {
30
			transport.open();
31
		} catch (TTransportException e) {
32
			Logger.log("Encountered exception while open transport "+ e, this);
33
		}
34
 
394 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
 
57
	public Client getClient(){
58
		return client;
59
	}
60
 
61
}