Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
130 ashish 1
'''
2
Created on 04-May-2010
3
 
4
@author: ashish
5
'''
6
from shop2020.config.client.ConfigClient import ConfigClient
7
from shop2020.thriftpy.model.v1.user import UserContextService
8
from thrift.transport import TSocket, TTransport
9
from thrift.protocol.TBinaryProtocol import TBinaryProtocolFactory
10
from thrift.server import TServer
11
from shop2020.model.v1.user.impl.UserContextSerivceHandler import UserContextServiceHandler
12
 
13
 
14
host_name = 'localhost'
1249 chandransh 15
port = 9000
16
dbname = 'user'
130 ashish 17
 
18
def main():
19
    #get the config client
20
    try:
21
        config_client = ConfigClient()
22
        host_name = config_client.get_property('user_service_server_host')
23
        port = config_client.get_property('user_service_server_port')
1267 chandransh 24
        dbname = config_client.get_property('user_service_dbname')
130 ashish 25
    except:
26
        #error while spawning the config server
27
        host_name = 'localhost'
1249 chandransh 28
        port = 9000
1415 chandransh 29
        dbname = 'user'
130 ashish 30
 
1249 chandransh 31
    handler = UserContextServiceHandler(dbname)
130 ashish 32
    processor = UserContextService.Processor(handler)
33
    transport = TSocket.TServerSocket(port)
34
    tfactory = TTransport.TFramedTransportFactory()
35
    pfactory = TBinaryProtocolFactory()
36
    server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
37
    print "Starting UserService at, port "+ str(port)+" host "+host_name
38
    server.serve()
39
    print "Server functioning"
40
 
41
 
42
if __name__ == '__main__':
1415 chandransh 43
    main()