Subversion Repositories SmartDukaan

Rev

Rev 3187 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1976 varun.gupt 1
'''
2
Created on 24-May-2011
3
@author: Varun Gupta
4
'''
5
from shop2020.config.client.ConfigClient import ConfigClient
6
from shop2020.thriftpy.model.v1.user import PromotionService
7
from thrift.transport import TSocket, TTransport
8
from thrift.protocol.TBinaryProtocol import TBinaryProtocolFactory
9
from thrift.server import TServer
10
from shop2020.model.v1.user.impl.PromotionServiceHandler import PromotionServiceHandler
11
 
12
host_name = 'localhost'
13
port = 9005
14
dbname = 'user'
15
 
16
def main():
17
    #get the config client
18
    try:
19
        config_client = ConfigClient()
20
        host_name = config_client.get_property('promotion_service_server_host')
21
        port = config_client.get_property('promotion_service_server_port')
22
        dbname = config_client.get_property('promotion_service_dbname')
23
    except:
24
        #error while spawning the config server
25
        host_name = 'localhost'
26
        port = 9005
27
        dbname = 'user'
28
 
29
    handler = PromotionServiceHandler(dbname)
30
    processor = PromotionService.Processor(handler)
31
    transport = TSocket.TServerSocket(port)
32
    tfactory = TTransport.TFramedTransportFactory()
33
    pfactory = TBinaryProtocolFactory()
34
    server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
35
    print "Starting Promotion Service at, port " + str(port) + " host " + host_name
36
    server.serve()
37
    print "Server functioning"
38
 
39
if __name__ == '__main__':
40
    main()