Пример #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
    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