Subversion Repositories SmartDukaan

Rev

Rev 1021 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1021 Rev 3123
Line 1... Line 1...
1
package in.shop2020.thrift.clients;
1
package in.shop2020.thrift.clients;
2
 
2
 
3
import javax.annotation.PostConstruct;
-
 
4
import javax.annotation.PreDestroy;
-
 
5
 
-
 
6
import org.apache.thrift.TException;
-
 
7
import org.apache.thrift.transport.TTransportException;
-
 
8
 
3
 
9
import in.shop2020.logistics.LogisticsService.Client;
4
import in.shop2020.logistics.LogisticsService.Client;
10
import in.shop2020.utils.ConfigClientKeys;
5
import in.shop2020.utils.ConfigClientKeys;
11
import in.shop2020.utils.Logger;
-
 
12
 
6
 
-
 
7
import org.apache.thrift.TException;
-
 
8
import org.apache.thrift.transport.TTransportException;
-
 
9
 
-
 
10
public class LogisticsClient extends GenericClient{
13
 
11
 
14
public class LogisticsServiceClient extends GenericServiceClient {
-
 
15
	
-
 
16
	private Client client = null;
12
	private Client client = null;
17
	
13
 
18
	public LogisticsServiceClient(String clientIdentifier,
-
 
19
			String hostConfigKey, String portConfigKey) throws Exception {
-
 
20
		super(clientIdentifier, hostConfigKey, portConfigKey);
-
 
21
		client = new Client(protocol);
-
 
22
		
-
 
23
	}
14
	/**
24
	
-
 
25
	public LogisticsServiceClient() throws Exception{
-
 
26
		this(LogisticsServiceClient.class.getSimpleName(), ConfigClientKeys.logistics_service_server_host.toString(), ConfigClientKeys.logistics_service_server_port.toString());
-
 
27
		if(transport.isOpen()){
-
 
28
			Logger.log("Transport was already open", this);
-
 
29
		}
15
	 * 
30
		try {
-
 
31
			transport.open();
-
 
32
			Logger.log("Transport opened", this);
-
 
33
		} catch (TTransportException e) {
16
	 * @throws TTransportException
34
			Logger.log("Encountered exception while open transport "+ e, this);
-
 
35
		}
-
 
36
	}
-
 
37
	
-
 
38
	@PostConstruct
-
 
39
	private void openTransport(){
-
 
40
		if(transport.isOpen()){
-
 
41
			Logger.log("Transport was already open", this);
-
 
42
		}
17
	 */
43
		try {
-
 
44
			transport.open();
-
 
45
		} catch (TTransportException e) {
18
	public LogisticsClient() throws TTransportException{
46
			Logger.log("Encountered exception while open transport "+ e, this);
19
		this(ConfigClientKeys.logistics_service_server_host.toString(), ConfigClientKeys.logistics_service_server_port.toString());
47
		}
-
 
48
	}
20
	}
49
	
21
 
50
	@PreDestroy
22
	/**
51
	private void closeTransport(){
23
	 * get the client for given hostkey and portkey
52
		if(transport != null && transport.isOpen()){
24
	 * @param hostConfigKey
53
			Logger.log("Closing transport :", this);
25
	 * @param portConfigKey
54
			transport.close();
26
	 * @throws TTransportException
55
		}
27
	 */
-
 
28
	public LogisticsClient(String hostConfigKey, String portConfigKey) throws TTransportException{
-
 
29
		super(hostConfigKey, portConfigKey);
-
 
30
		client = new Client(protocol);
56
	}
31
	}
57
	
32
	
-
 
33
 
-
 
34
	/**
-
 
35
	 * Get the client
-
 
36
	 * @return
-
 
37
	 */
58
	public Client getClient(){
38
	public Client getClient(){
59
		return client;
39
		return client;
60
	}
40
	}
61
	
41
	
62
	@Override
42
	@Override
Line 65... Line 45...
65
			client.closeSession();
45
			client.closeSession();
66
		} catch (TException e) {
46
		} catch (TException e) {
67
			e.printStackTrace();
47
			e.printStackTrace();
68
		}
48
		}
69
	}
49
	}
-
 
50
 
70
}
51
}