Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
116 ashish 1
package in.shop2020.thrift.clients;
2
 
3
import java.util.List;
4
import java.util.Map;
5
 
6
import javax.annotation.PostConstruct;
7
import javax.annotation.PreDestroy;
8
 
9
import org.apache.thrift.transport.TTransportException;
10
 
11
import in.shop2020.utils.ConfigClientKeys;
12
import in.shop2020.utils.ItemLogistics;
13
import in.shop2020.utils.Logger;
14
import in.shop2020.utils.EstimationService.Client;
15
 
16
public class EstimationServiceClient extends GenericServiceClient {
17
 
18
	private Client client = null;
19
 
20
	public EstimationServiceClient(String clientIdentifier,
21
			String hostConfigKey, String portConfigKey) throws Exception {
22
		super(clientIdentifier, hostConfigKey, portConfigKey);
23
		client = new Client(protocol);
24
 
25
	}
26
 
27
	public EstimationServiceClient() throws Exception{
28
		this(EstimationServiceClient.class.getSimpleName(), ConfigClientKeys.estimation_service_hostname.toString(), ConfigClientKeys.estimation_service_port.toString());
29
	}
30
 
31
	@PostConstruct
32
	public void openTransport(){
33
		if(transport.isOpen()){
34
			Logger.log("Transport was already open", this);
35
		}
36
		try {
37
			transport.open();
38
		} catch (TTransportException e) {
39
			Logger.log("Encountered exception while open transport "+ e, this);
40
		}
41
	}
42
 
43
	List<ItemLogistics> getLogisticsEstimation(long itemId, Map<String, String> location) throws Exception{
44
		return client.getLogisticsEstimation(itemId, location);
45
	}
46
 
47
	@PreDestroy
48
	private void closeTransport(){
49
		if(transport != null && transport.isOpen()){
50
			Logger.log("Closing transport :", this);
51
			transport.close();
52
		}
53
	}
54
 
55
}