Subversion Repositories SmartDukaan

Rev

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

'''
Created on 17-Aug-2010

@author: ashish
'''
from shop2020.thriftpy.model.v1.order import TransactionService
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
from thrift.transport.TTransport import TFramedTransport
from thrift.transport.TSocket import TSocket
from shop2020.utils.Utils import log_entry
from shop2020.config.client.ConfigClient import ConfigClient

class TransactionClient:
    
    host = "localhost"
    port = "9003"
    
    def __init__(self):
        try:
            self.config_client = ConfigClient()
            self.host = self.config_client.get_property("transaction_service_hostname")
            self.host = self.config_client.get_property("transaction_service_port")
            self.__start__()
        except:
            log_entry("error getting data from config")
        
    def __start__(self):
        self.transport = TSocket(self.host, self.port)
        self.transport = TFramedTransport(self.transport)
        self.protocol = TBinaryProtocol(self.transport)    
        self.client = TransactionService.Client(self.protocol)
        self.transport.open()
        
    def get_client(self):
        if self.transport.isOpen():
            return self.client
        self.transport.open()
        return self.client