Subversion Repositories SmartDukaan

Rev

Rev 3187 | Rev 3539 | 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'
3187 rajveer 17
db_hostname='localhost'
130 ashish 18
 
19
def main():
20
    #get the config client
21
    try:
22
        config_client = ConfigClient()
23
        host_name = config_client.get_property('user_service_server_host')
24
        port = config_client.get_property('user_service_server_port')
1267 chandransh 25
        dbname = config_client.get_property('user_service_dbname')
3187 rajveer 26
        db_hostname = config_client.get_property('user_service_db_hostname')
130 ashish 27
    except:
28
        #error while spawning the config server
29
        host_name = 'localhost'
1249 chandransh 30
        port = 9000
1415 chandransh 31
        dbname = 'user'
3187 rajveer 32
        db_hostname='localhost'
130 ashish 33
 
3187 rajveer 34
    handler = UserContextServiceHandler(dbname, db_hostname)
130 ashish 35
    processor = UserContextService.Processor(handler)
3537 chandransh 36
    transport = TSocket.TServerSocket(host_name, port)
130 ashish 37
    tfactory = TTransport.TFramedTransportFactory()
38
    pfactory = TBinaryProtocolFactory()
39
    server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
40
    print "Starting UserService at, port "+ str(port)+" host "+host_name
41
    server.serve()
42
    print "Server functioning"
43
 
44
 
45
if __name__ == '__main__':
1415 chandransh 46
    main()