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.datalogger.DataLogger.Client;
4
import in.shop2020.datalogger.DataLogger.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
 
13
public class DataLoggingClient extends GenericServiceClient{
10
public class DataLoggingClient extends GenericClient{
14
 
11
 
15
	private Client client = null;
12
	private Client client = null;
16
	
13
 
17
	public DataLoggingClient(String clientIdentifier, String hostConfigKey,
-
 
18
			String portConfigKey) throws Exception {
-
 
19
		super(clientIdentifier, hostConfigKey, portConfigKey);
-
 
20
		client = new Client(protocol);
-
 
21
		
14
	/**
22
	}
15
	 * 
-
 
16
	 * @throws TTransportException
23
	
17
	 */
24
	public DataLoggingClient()throws Exception{
18
	public DataLoggingClient() throws TTransportException{
25
		this(DataLoggingClient.class.getSimpleName(), ConfigClientKeys.datalogging_service_local_hostname.toString(), ConfigClientKeys.datalogging_service_local_wrapper_port.toString());
19
		this(ConfigClientKeys.datalogging_service_local_hostname.toString(), ConfigClientKeys.datalogging_service_local_wrapper_port.toString());
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
	}
20
	}
35
	
21
 
36
	@PostConstruct
22
	/**
37
	private void openTransport(){
23
	 * get the client for given hostkey and portkey
-
 
24
	 * @param hostConfigKey
38
		if(transport.isOpen()){
25
	 * @param portConfigKey
39
			Logger.log("Transport was already open", this);
26
	 * @throws TTransportException
40
		}
27
	 */
41
		try {
-
 
42
			transport.open();
28
	public DataLoggingClient(String hostConfigKey, String portConfigKey) throws TTransportException{
43
		} catch (TTransportException e) {
29
		super(hostConfigKey, portConfigKey);
44
			Logger.log("Encountered exception while open transport "+ e, this);
30
		client = new Client(protocol);
45
		}
-
 
46
	}
31
	}
47
	
32
	
-
 
33
 
-
 
34
	/**
-
 
35
	 * Get the client
-
 
36
	 * @return
-
 
37
	 */
48
	public Client getClient(){
38
	public Client getClient(){
49
		return client;
39
		return client;
50
	}
40
	}
51
	
41
	
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
	@Override
42
	@Override
61
	public void closeSession() {
43
	public void closeSession() {
62
		try {
44
		try {
63
			client.closeSession();
45
			client.closeSession();
64
		} catch (TException e) {
46
		} catch (TException e) {
65
			e.printStackTrace();
47
			e.printStackTrace();
66
		}
48
		}
67
	}
49
	}
68
	
50
 
69
}
51
}
-
 
52