Subversion Repositories SmartDukaan

Rev

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

'''
Created on 15-Jul-2010

@author: ashish
'''
from shop2020.config.client.ConfigClient import ConfigClient
from shop2020.thriftpy.model.v1.catalog import  InventoryService
from thrift.transport import TSocket, TTransport
from thrift.protocol.TBinaryProtocol import TBinaryProtocolFactory
from thrift.server import TServer
from shop2020.helpers.impl.HelperServiceHandler import HelperServiceHandler
from shop2020.thriftpy.utils import HelperService


host_name = 'localhost'
port = 9008
dbname = 'helper'

def main():
    #get the config client
    try:
        config_client = ConfigClient()
        host_name = config_client.get_property('helper_service_server_host')
        port = int(config_client.get_property('helper_service_server_port'))
        dbname = config_client.get_property('helper_service_dbname')
    except:
        #error while spawning the config server
        host_name = 'localhost'
        port = 9008
        dbname = 'helper'
    
    handler = HelperServiceHandler(dbname)
    processor = HelperService.Processor(handler)
    transport = TSocket.TServerSocket(port)
    tfactory = TTransport.TFramedTransportFactory()
    pfactory = TBinaryProtocolFactory()
    server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
    print "Starting HelperService at, port "+ str(port)+" host "+host_name
    server.serve()
    print "Server functioning"
    

if __name__ == '__main__':
    main()