示例#1
0
    def main(self, mesh):
        """."""
        handlers = {}
        subscriptions = set()

        while True:
            pat, msg = self.receive(CONNECT, FORGET,
                                    NODEUP, NODEDOWN,
                                    EXIT, SUBSCRIBE)
            if pat is CONNECT:
                name, host, port = msg[1:]
                handlers[name] = self.spawn_link(NodeHandler, name, mesh,
                   host, port, actor.curaddr())
            elif pat is FORGET:
                name, = msg[1:]
                handlers[msg[1:]] | ('die',)
            elif pat is NODEUP or pat is NODEDOWN:
                for sub in subscriptions:
                    sub | msg
            elif pat is SUBSCRIBE:
                msg[1].monitor()
                subscriptions.add(msg[1])
            elif pat is EXIT:
                for name, addr in handlers.items():
                    if addr == msg['address']:
                        del handlers[name]
                        break
                else:
                    if pat['address'] in subscriptions:
                        subscriptions.remove(pat['address'])
示例#2
0
文件: remote.py 项目: jrydberg/guild
    def main(self, mesh):
        """."""
        handlers = {}
        subscriptions = set()

        while True:
            pat, msg = self.receive(CONNECT, FORGET,
                                    NODEUP, NODEDOWN,
                                    EXIT, SUBSCRIBE)
            if pat is CONNECT:
                name, host, port = msg[1:]
                handlers[name] = self.spawn_link(NodeHandler, name, mesh,
                   host, port, actor.curaddr())
            elif pat is FORGET:
                name, = msg[1:]
                handlers[msg[1:]] | ('die',)
            elif pat is NODEUP or pat is NODEDOWN:
                for sub in subscriptions:
                    sub | msg
            elif pat is SUBSCRIBE:
                msg[1].monitor()
                subscriptions.add(msg[1])
            elif pat is EXIT:
                for name, addr in handlers.items():
                    if addr == msg['address']:
                        del handlers[name]
                        break
                else:
                    if pat['address'] in subscriptions:
                        subscriptions.remove(pat['address'])
示例#3
0
def build(receive, n):
    ring = []
    for i in range(n):
        if not ring:
            node = actor.spawn(forward, actor.curaddr())
        else:
            node = actor.spawn(forward, ring[-1])
        ring.append(node)
        gevent.sleep()

    ring[-1] | {'text': 'hello around the ring'}
    pat, data = receive()
    return data
示例#4
0
def server(receive):
    actor.register('test', actor.curaddr())
    actor.spawn(caller, actor.curaddr())
    pat, data = receive()
    return data
示例#5
0
def server(receive):
    actor.register('test', actor.curaddr())
    actor.spawn(caller, actor.curaddr())
    pat, data = receive()
    return data