Subversion Repositories SmartDukaan

Rev

Rev 1021 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.thrift.clients;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.apache.thrift.TException;
import org.apache.thrift.transport.TTransportException;

import in.shop2020.model.v1.order.TransactionService.Client;
import in.shop2020.utils.ConfigClientKeys;
import in.shop2020.utils.Logger;

public class TransactionServiceClient extends GenericServiceClient{

        private Client client = null;
        
        public TransactionServiceClient(String clientIdentifier,
                        String hostConfigKey, String portConfigKey) throws Exception {
                super(clientIdentifier, hostConfigKey, portConfigKey);
                client = new Client(protocol);
                
        }
        
        public TransactionServiceClient()throws Exception{
                this(TransactionServiceClient.class.getSimpleName(), ConfigClientKeys.transaction_service_server_host.toString(), ConfigClientKeys.transaction_service_server_port.toString());
                if(transport.isOpen()){
                        Logger.log("Transport was already open", this);
                }
                try {
                        transport.open();
                } catch (TTransportException e) {
                        Logger.log("Encountered exception while open transport "+ e, this);
                }
        }
        
        @PostConstruct
        private void openTransport(){
                if(transport.isOpen()){
                        Logger.log("Transport was already open", this);
                }
                try {
                        transport.open();
                } catch (TTransportException e) {
                        Logger.log("Encountered exception while open transport "+ e, this);
                }
        }
        
        //Api methods
        //TODO: Add logging to this class.
        
        public Client getClient(){
                return client;
        }
        
        @PreDestroy
        private void closeTransport(){
                if(transport != null && transport.isOpen()){
                        Logger.log("Closing transport :", this);
                        transport.close();
                }
        }
        
        @Override
        public void closeSession() {
                try {
                        client.closeSession();
                } catch (TException e) {
                        e.printStackTrace();
                }
        }
}