def callRemote(): thread = EventletThread() thread.start() transport = Net('127.0.0.1:6503') vat = RPCHandler('127.0.0.1:6503', '', {}, node=transport, t_model=thread) cb = vat.call('127.0.0.1:6502', 'OBJ', 'fun_b', [5]) print cb.wait()
def handler(transport): # transport is a ws_transport.WebSocketHandler thread = EventletThread() thread.callFromThread = thread.call handler = RPCHandler(transport, {}, t_model=thread, verbose=verbose, jc_opts=jc_opts) handler.client_address = (transport.client_ip, transport.client_address[1]) hproxy = weakref.proxy(handler) factory.initSession(hproxy) try: transport.handle() except: pass factory.closeSession(hproxy)
def testRPC(self): net = MockNet() ta = net.addNode('browser') tb = net.addNode('server') na = RPCHandler(ta, {}) nb = RPCHandler(tb, {}) oa = Model() na.provide('1', oa) rupdate = makeBoundMethod(nb, {'o':'1', 'm':'update'}) rupdate({'x': '1'}) self.assertEqual(oa.get('x'), '1')
def testRPC(self): net = MockNet() ta = net.addNode('browser') tb = net.addNode('server') na = RPCHandler(ta, {}) nb = RPCHandler(tb, {}) oa = Model() na.provide('1', oa) rupdate = makeBoundMethod(nb, {'o': '1', 'm': 'update'}) rupdate({'x': '1'}) self.assertEqual(oa.get('x'), '1')
def testGC(self): h = RPCHandler(MockTransport('browser'), {}) makeBoundMethod(h, {'o': 'shared', 'm': 'notify'}) hr = weakref.ref(h) self.assertEqual(hr(), h) del h self.assertEqual(hr(), None)
def testProxyEquality(self): va0 = RPCHandler(MockTransport('A'), {}) va1 = RPCHandler(MockTransport('A'), {}) vb0 = RPCHandler(MockTransport('B'), {}) p1 = Proxy('B', 'x', va0) p2 = Proxy('B', 'y', va1) p3 = Proxy('B', 'y', va0) p4 = Proxy('A', 'x', vb0) p5 = Proxy('A', 'y', vb0) p6 = Proxy('A', 'y', vb0) self.assertNotEqual(p1, p2) self.assertEqual(p2, p3) # only node and path are compared self.assertNotEqual(p1, p3) self.assertNotEqual(p1, p4) self.assertNotEqual(p3, p4) self.assertEqual(p5, p6)
def handle(transport): thread = EventletThread() thread.callFromThread = thread.call handler = RPCHandler(transport, {}, t_model=thread, jc_opts=JC_OPTS) handler.provide('table', TABLE) transport.handle()
store = FSDict('/var/lib/serf/tables') storage = Storage(store) if 'table' not in storage: storage['table'] = Table() TABLE = storage['table'] JC_OPTS = dict(hooks=JC_HOOKS, safe=['serf.tables'], auto_proxy=True) def handle(transport): thread = EventletThread() thread.callFromThread = thread.call handler = RPCHandler(transport, {}, t_model=thread, jc_opts=JC_OPTS) handler.provide('table', TABLE) transport.handle() if __name__ == '__main__': print 'Table Server', SERF_NODE transport = Transport(SERF_NODE) rpc = RPCHandler(transport, storage, thread) rpc.safe.append('serf.tables') thread.start() eventlet.spawn_n(transport.serve) ws_transport = WSTransport(9900, handler=handle) ws_transport.serve() thread.stop() print '\nBye'
storage['login'] = Login(storage) if 'admin' not in storage: storage['admin'] = Admin(storage) LOGIN = storage['login'] JC_OPTS = dict(hooks={}, auto_proxy=True) def handle(transport): thread = EventletThread() thread.callFromThread = thread.call handler = RPCHandler(transport, {}, t_model=thread, jc_opts=JC_OPTS) handler.provide('login', LOGIN) transport.handle() if __name__ == '__main__': print 'Cap Server', SERF_NODE transport = Transport(SERF_NODE) rpc = RPCHandler(transport, storage, thread, verbose=True) rpc.safe.append('serf.tables') thread.start() eventlet.spawn_n(transport.serve) ws_transport = WSTransport(9902, handler=handle) ws_transport.serve() thread.stop() print '\nBye'
SERVER = '127.0.0.1:6502' CLIENT = '127.0.0.1:6503' SSL = { 'certfile': os.path.join(codeDir(), 'data/host.cert'), 'keyfile': os.path.join(codeDir(), 'data/host.key') } store = FSDict(os.path.join(dataRoot(), 'client')) net = Transport(CLIENT, ssl=SSL) thread = EventletThread() s0 = Storage(store) v0 = RPCHandler(net, s0, t_model=thread) def wrap(x): return REPLProxy(x, thread) class ClientConsole(InteractiveConsole): def raw_input(self, prompt): sys.stdout.write(prompt) sys.stdout.flush() select.select([sys.stdin], [], []) s = sys.stdin.readline() if not s: raise EOFError() return s.strip()
import sys from serf.transport import Transport from serf.fs_dict import FSDict from serf.eventlet_thread import EventletThread from serf.storage import Storage from serf.rpc_handler import RPCHandler from serf.util import codeDir, dataRoot if __name__ == '__main__': NODE = '127.0.0.1:6502' DATA_ROOT = os.path.join(dataRoot(), 'server') store = FSDict(DATA_ROOT) SSL = { 'certfile': os.path.join(codeDir(), 'data/host.cert'), 'keyfile': os.path.join(codeDir(), 'data/host.key') } net = Transport(NODE, ssl=SSL, verbose=('-v' in sys.argv)) thread = EventletThread() storage = Storage(store) vat = RPCHandler(net, storage, t_model=thread) thread.start() print 'Serf Server 0.1', NODE print 'data-root =', DATA_ROOT net.serve() thread.stop() print '\rBye'
The 'fred' value is a proxy to a persistent UserCaps object to which we can add 'capabilities', other persistent objects that are available to the 'fred' user for getting things done. """ from serf.rpc_handler import RPCHandler from serf.transport import Transport from serf.eventlet_thread import EventletThread from serf.proxy import Proxy from serf.repl_proxy import REPLProxy SERVER = '127.0.0.1:6508' net = Transport() thread = EventletThread() rpc = RPCHandler(net, {}, t_model=thread) rpc.safe.append('serf.tables') def remote(x): return REPLProxy(rpc.makeProxy(x, SERVER), thread) thread.start(True) thread.callFromThread(net.start) admin = remote('admin') login = remote('login') users = remote('users')
import sys import time from serf.rpc_handler import RPCHandler from serf.transport import Transport from serf.eventlet_thread import EventletThread from serf.proxy import Proxy from serf.repl_proxy import REPLProxy from serf.po.printer import Printer from serf.tables.table import * from serf.tables.query import * SERVER = '127.0.0.1:6506' transport = Transport() thread = EventletThread() rpc = RPCHandler(transport, {}, t_model=thread) rpc.safe.append('serf.tables') def proxy(name): return REPLProxy(Proxy(SERVER, name, rpc), thread) # thread.start(True) means start a new thread. thread.start(True) thread.callFromThread(transport.start) table = proxy('table')