Subversion Repositories SmartDukaan

Rev

Rev 1267 | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 26-Aug-2010

@author: ashish
'''
from shop2020.config.client.ConfigClient import ConfigClient
from thrift.transport import TSocket, TTransport
from thrift.protocol.TBinaryProtocol import TBinaryProtocolFactory
from thrift.server import TServer
from shop2020.payments.impl.PaymentsHandler import PaymentsHandler
from shop2020.thriftpy.payments import PaymentService



host_name = 'localhost'
port = 9012
dbname = 'payment'

def main():
    #get the config client
    try:
        config_client = ConfigClient()
        host_name = config_client.get_property('payments_service_server_host')
        port = config_client.get_property('payments_service_server_port')
        dbname = config_client.get_property('payments_service_dbname')
    except:
        #error while spawning the config server
        host_name = 'localhost'
        port = 9012
        dbname = 'payment'
    
    handler = PaymentsHandler(dbname)
    processor = PaymentService.Processor(handler)
    transport = TSocket.TServerSocket(port)
    tfactory = TTransport.TFramedTransportFactory()
    pfactory = TBinaryProtocolFactory()
    server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
    print "Starting PaymentsService at, port "+ str(port)+" host "+host_name
    server.serve()
    print "Server functioning"
    

if __name__ == '__main__':
    main()