Subversion Repositories SmartDukaan

Rev

Rev 3537 | Rev 3915 | Go to most recent revision | Details | Compare with Previous | 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'
3187 rajveer 15
db_hostname='localhost'
1976 varun.gupt 16
 
17
def main():
18
    #get the config client
19
    try:
20
        config_client = ConfigClient()
21
        host_name = config_client.get_property('promotion_service_server_host')
22
        port = config_client.get_property('promotion_service_server_port')
23
        dbname = config_client.get_property('promotion_service_dbname')
3187 rajveer 24
        db_hostname = config_client.get_property('promotion_service_db_hostname')
1976 varun.gupt 25
    except:
26
        #error while spawning the config server
27
        host_name = 'localhost'
28
        port = 9005
29
        dbname = 'user'
3187 rajveer 30
        db_hostname='localhost'
1976 varun.gupt 31
 
3187 rajveer 32
    handler = PromotionServiceHandler(dbname, db_hostname)
1976 varun.gupt 33
    processor = PromotionService.Processor(handler)
3539 chandransh 34
    transport = TSocket.TServerSocket(port=port)
1976 varun.gupt 35
    tfactory = TTransport.TFramedTransportFactory()
36
    pfactory = TBinaryProtocolFactory()
37
    server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
38
    print "Starting Promotion Service at, port " + str(port) + " host " + host_name
39
    server.serve()
40
    print "Server functioning"
41
 
42
if __name__ == '__main__':
43
    main()