1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
from Pyro5.api import expose, Proxy
# a Chain member. Passes messages to the next link,
# until the message went full-circle: then it exits.
class Chain(object):
def __init__(self, name, next_node):
self.name = name
self.nextName = next_node
self.next = None
@expose
def process(self, message):
if self.next is None:
self.next = Proxy("PYRONAME:example.chain." + self.nextName)
if self.name in message:
print("Back at %s; we completed the circle!" % self.name)
return ["complete at " + self.name]
else:
print("I'm %s, passing to %s" % (self.name, self.nextName))
message.append(self.name)
result = self.next.process(message)
result.insert(0, "passed on from " + self.name)
return result
|