Exemple #1
0
"""

import sys
sys.path.append('gen-py')

from locator.ttypes import Location
from storeserver import remote_call, parser, DEFAULTPORT, SERVICENAME
from location import find_matching_service, str2loc

usage = '''
  python %prog [options] <key> <value>

Looks for a storage node at PEER, either as specified, or 
auto-discovered on the localhost starting from the default 
port. Sends the remote command there, which gets forwarded 
to the actual node that has it.'''

parser.set_usage(usage)
parser.remove_option('--port')

if __name__ == '__main__':
    (options, args) = parser.parse_args()
    if len(args) != 2:
        parser.error("incorrect number of arguments")
    (key, value) = args
    if options.peer:
        loc = str2loc(options.peer)
    else:
        loc = find_matching_service(Location('localhost', DEFAULTPORT), SERVICENAME) or sys.exit()
    remote_call('put', loc, key, value)
Exemple #2
0
                        self.ring.remove(location.loc2str(tx.location))            
        

def main(inputargs):
    handler = StoreHandler(**inputargs)
    processor = Store.Processor(handler)
    transport = TSocket.TServerSocket(handler.port)
    tfactory = TTransport.TBufferedTransportFactory()
    pfactory = TBinaryProtocol.TBinaryProtocolFactory()
    server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
    
    handler.local_join()
    print 'Starting the server at %s...' % (handler.here)
    try:
        server.serve()
    finally:
        handler.cleanup()
    print 'done.'

if __name__ == '__main__':
    (options, args) = parser.parse_args()
    if not options.port:
        loc = location.ping_until_not_found(Location('localhost', DEFAULTPORT), 25)
        options.port = loc.port
    if options.peer:
        options.peer = location.str2loc(options.peer)
    else:
        options.peer = location.find_matching_service(Location('localhost', DEFAULTPORT), SERVICENAME)
    main(options.__dict__)