def setUp(self): super(InlineCallbacks, self).setUp() self.callerdict = dict() for i in range(100): print "Creating Thread {0}".format(i) self.callerdict[i] = rpc.RpcLayer() print "All good"
def setUp(self): super(InlineCallbacks, self).setUp() topicSet = "abcdefg*" self.callerdict = dict() for i in range(100): print "Creating Thread {0}".format(i) self.callerdict[i] = rpc.RpcLayer() self.callerdict[i].subscribe( "%s.%s.%s" % (random.choice(topicSet), random.choice(topicSet), random.choice(topicSet)), ) print "All good"
def setUp(self): def unnamed(x): return x def mixed(x, foo='bar'): return x, foo def named(foo='bar'): return foo def add(x, y): return x + y def multiply(x, y): return x * y @defer.inlineCallbacks def callbackCascade(x): plus5 = yield self.callee.call("add", x, 5) print "First result is: {0}".format(plus5) self.assertEqual(plus5, x + 5) times10 = yield self.callee.call("multiply", plus5, 10) print "Second result is: {0}".format(times10) self.assertEqual(times10, (x + 5) * 10) defer.returnValue(times10) self.caller = rpc.RpcLayer() self.callee = rpc.RpcLayer() self.callee.register("unnamed", unnamed) self.callee.register("named", named) self.callee.register("mixed", mixed) self.callee.register("add", add) self.callee.register("multiply", multiply) self.callee.register("plus5times10", callbackCascade) time.sleep(1)
#print "Thread {1} on Server: {0}".format(result1, threading.currentThread()) twisted.internet.defer.returnValue(d1) @decaf_utils_rpc.sync_result.sync(timeout=10.0) def callSync(rpc_name, *args, **kwargs): return r1.call(rpc_name, *args, **kwargs) def printer(x): print x # --------------r1 calls r2----------------------------- r1 = rpc.RpcLayer() r2 = rpc.RpcLayer() r2.register("print", echo) r2.register("print1", echo1) r2.register("print2", echo2) time.sleep(2) d = r1.call("print", 2) d1 = r1.call("print1", 2, foo='lol') d2 = r1.call("print2", foo='lol') d.addBoth(printer) d1.addBoth(printer) d2.addBoth(printer)
__author__ = 'thgoette' def echo(x): return x + " from PYTHON" import decaf_utils_rpc.rpc_layer as rpc r = rpc.RpcLayer() for i in range(10): print "Register {0}".format(i) r.register(str(i), echo)
__author__ = 'Kristian Hinnenthal' import time import twisted.internet.defer as defer def printer(x): print x import decaf_utils_rpc.rpc_layer as rpc r = rpc.RpcLayer(u'amqp://fg-cn-sandman1.cs.upb.de:5672') @defer.inlineCallbacks def doWork(): result = (yield r.call("deployment.scenario_start", "7df6fbc9754944088d50e52f1cc7209a", "TestInstance", "TestDescription", 1, True)) print(result) r.dispose() if __name__ == '__main__': doWork()
import threading __author__ = 'thgoette' i = list() def printer(x): lock.acquire() i.append(0) print len(i) lock.release() import decaf_utils_rpc.rpc_layer as rpc lock = threading.Lock() r = rpc.RpcLayer(host_url=u'amqp://131.234.41.2:5672') for j in range(1): r.call("componentmanager.version").addBoth(printer) print "Im waiting for JAVA, this may takes a while"
def setUp(self): def unnamed(x): return x def mixed(x, foo='bar'): return x, foo def named(foo='bar'): return foo def add(x, y): return x + y def multiply(x, y): return x * y def timeout(*args): time.sleep(300) return "I've been waiting a long time for this moment" @defer.inlineCallbacks def callbackCascade(x): print "Starting Cascade" plus5 = yield self.callee.call("add", x, 5) print "First result is: {0}".format(plus5) self.assertEqual(plus5, x + 5) times10 = yield self.callee.call("multiply", plus5, 10) print "Second result is: {0}".format(times10) self.assertEqual(times10, (x + 5) * 10) defer.returnValue(times10) self.caller = rpc.RpcLayer() self.callee = rpc.RpcLayer() open = list() open.extend([ "unnamed", "named", "mixed", "add", "multiply", "plus5times10", "timeout" ]) lock = threading.Lock() def waiter(name): print "Thread tries to get lock" lock.acquire() print name + " ready" open.remove(name) lock.release() self.callee.register("unnamed", unnamed).addCallback(waiter) self.callee.register("named", named).addCallback(waiter) self.callee.register("mixed", mixed).addCallback(waiter) self.callee.register("add", add).addCallback(waiter) self.callee.register("multiply", multiply).addCallback(waiter) self.callee.register("plus5times10", callbackCascade).addCallback(waiter) self.callee.register("timeout", timeout).addCallback(waiter) OK = False while not OK: lock.acquire() OK = (len(open) == 0) lock.release() print "Set Up done"
# 1: Download and install RabbitMQ for Linux # # 2: Open a terminal and type "sudo rabbitmqctl start_app" # -------------------------------------------------- # ------------------------------------------------- # ----- Step 3: Import the RPCLayer --------------- # ------------------------------------------------- import decaf_utils_rpc.rpc_layer as rpc # ------------------------------------------------- # ----- Step 4: Create an Instance ---------------- # ------------------------------------------------- rpc_layer = rpc.RpcLayer() # ------------------------------------------------- # -------------- Step 5A: Register ---------------- # # If you want to provide method, # # you have to register them with a unique name # # ------------------------------------------------- def example_method(): ''' This is the method we want to provide '''