Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
350 ashish 1
package in.shop2020.thrift.clients;
2
 
3
import in.shop2020.utils.ConfigClientKeys;
4
import in.shop2020.utils.ItemLogistics;
5
import in.shop2020.utils.Logger;
6
import in.shop2020.utils.HelperService.Client;
7
 
8
import java.util.List;
9
import java.util.Map;
10
 
11
import javax.annotation.PostConstruct;
12
import javax.annotation.PreDestroy;
13
 
767 rajveer 14
import org.apache.thrift.TException;
350 ashish 15
import org.apache.thrift.transport.TTransportException;
16
 
17
public class HelperServiceClient extends GenericServiceClient{
18
	private Client client = null;
19
 
20
	public HelperServiceClient(String clientIdentifier,
21
			String hostConfigKey, String portConfigKey) throws Exception {
22
		super(clientIdentifier, hostConfigKey, portConfigKey);
23
		client = new Client(protocol);
24
 
25
	}
26
 
27
	public HelperServiceClient() throws Exception{
747 rajveer 28
		this(HelperServiceClient.class.getSimpleName(), ConfigClientKeys.helper_service_server_host.toString(), ConfigClientKeys.helper_service_server_port.toString());
495 rajveer 29
		if(transport.isOpen()){
30
			Logger.log("Transport was already open", this);
31
		}
32
		try {
33
			transport.open();
34
			Logger.log("Transport opened", this);
35
		} catch (TTransportException e) {
36
			Logger.log("Encountered exception while open transport "+ e, this);
37
		}
350 ashish 38
	}
39
 
40
	@PostConstruct
41
	public void openTransport(){
42
		if(transport.isOpen()){
43
			Logger.log("Transport was already open", this);
44
		}
45
		try {
46
			transport.open();
47
		} catch (TTransportException e) {
48
			Logger.log("Encountered exception while open transport "+ e, this);
49
		}
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
	public Client getClient(){
61
		return client;
62
	}
767 rajveer 63
 
64
	@Override
65
	public void closeSession() {
66
		try {
67
			client.closeSession();
68
		} catch (TException e) {
69
			e.printStackTrace();
70
		}
71
	}
350 ashish 72
 
73
}