Exemplo n.º 1
0
class BizLogic(object):

    def __init__(self, args):
        self.host = args.host
        self.port = args.port
        self.tether = Tether(None, "//%s/bizlogic" % self.host, None,
                             host=self.host, port=self.port,
                             agent_type="bizlogic", policy="ordered")

        self.users = {}
        self.user_reread_period = 30  # seconds
        self.linker = Linker()
        self.container = Container(Processor(self))
        self.container[self.tether.agent] = Agent(self.tether)

    def on_reactor_init(self, event):
        event.reactor.acceptor(self.host, self.port, self.container)
        self.tether.start(event.reactor)
        event.reactor.schedule(0, self)
        self.linker.start(event.reactor)

    def on_timer_task(self, event):
        self.users = common.load_data("users.pickle")
        event.reactor.schedule(self.user_reread_period, self)

    def on_message(self, event):
        bark = common.Bark(*event.message.body)
        words = bark.content.split()
        mentions = [word[1:] for word in words if word.startswith("@")]
        user = self.users[bark.user]
        followers = user.getFollowers(self.users)
        targets = set(mentions + followers + [bark.user])
        for target in targets:
            sender = self.linker.sender("//%s/inbox/%s" % (self.host, target))
            sender.send(event.message.body)
Exemplo n.º 2
0
 def __init__(self, args):
     self.host = args.host
     self.port = args.port
     self.tether = Tether(None, "//%s/monitor" % self.host, "//%s:%s" % (self.host, self.port))
     self.stream = Stream(HistoryStore(100))
     self.directory = Receiver("//%s/directory" % self.host, Processor(self))
     self.receivers = []
     self.handlers = [self.stream]
     self.statMessages = []
Exemplo n.º 3
0
    def __init__(self, args):
        self.host = args.host
        self.port = args.port
        self.tether = Tether(None, "//%s/bizlogic" % self.host, None,
                             host=self.host, port=self.port,
                             agent_type="bizlogic", policy="ordered")

        self.users = {}
        self.user_reread_period = 30  # seconds
        self.linker = Linker()
        self.container = Container(Processor(self))
        self.container[self.tether.agent] = Agent(self.tether)
Exemplo n.º 4
0
 def __init__(self, args):
     self.host = args.host
     self.port = args.port
     self.tether = Tether(None, "//%s/monitor" % self.host, "//%s:%s" % (self.host, self.port))
     self.stream = Stream(HistoryStore(100))
     self.directory = Receiver("//%s/directory" % self.host, Processor(self))
     self.receivers = []
     self.handlers = [self.stream]
     self.statMessages = []
Exemplo n.º 5
0
class Monitor(object):

    def __init__(self, args):
        self.host = args.host
        self.port = args.port
        self.tether = Tether(None, "//%s/monitor" % self.host, "//%s:%s" % (self.host, self.port))
        self.stream = Stream(HistoryStore(100))
        self.directory = Receiver("//%s/directory" % self.host, Processor(self))
        self.receivers = []
        self.handlers = [self.stream]
        self.statMessages = []

    def on_reactor_init(self, event):
        event.reactor.acceptor(self.host, self.port, self.stream)
        self.tether.start(event.reactor)
        self.directory.start(event.reactor)
        event.reactor.schedule(0, self)

    def add_routes(self, event):
        address, routes = event.message.body
        if "/agents/" in address:
            if routes:
                rcv = Receiver(address, Processor(self))
                self.receivers.append(rcv)
                rcv.start(event.reactor)
            else:
                for rcv in self.receivers:
                    if rcv.source == address:
                        self.receivers.remove(rcv)
                        rcv.stop(event.reactor)
                        break

    def on_message(self, event):
        if event.message.subject == "routes":
            self.add_routes(event)
        else:
            self.statMessages.append(event.message.body)

    def on_timer_task(self, event):
        if self.statMessages:
            self.stream.put(self.statMessages)
            self.statMessages = []
        event.reactor.schedule(1, self)
Exemplo n.º 6
0
class Monitor(object):
    def __init__(self, args):
        self.host = args.host
        self.port = args.port
        self.tether = Tether(None, "//%s/monitor" % self.host, "//%s:%s" % (self.host, self.port))
        self.stream = Stream(HistoryStore(100))
        self.directory = Receiver("//%s/directory" % self.host, Processor(self))
        self.receivers = []
        self.handlers = [self.stream]
        self.statMessages = []

    def on_reactor_init(self, event):
        event.reactor.acceptor(self.host, self.port, self.stream)
        self.tether.start(event.reactor)
        self.directory.start(event.reactor)
        event.reactor.schedule(0, self)

    def add_routes(self, event):
        address, routes = event.message.body
        if "/agents/" in address:
            if routes:
                rcv = Receiver(address, Processor(self))
                self.receivers.append(rcv)
                rcv.start(event.reactor)
            else:
                for rcv in self.receivers:
                    if rcv.source == address:
                        self.receivers.remove(rcv)
                        rcv.stop(event.reactor)
                        break

    def on_message(self, event):
        if event.message.subject == "routes":
            self.add_routes(event)
        else:
            self.statMessages.append(event.message.body)

    def on_timer_task(self, event):
        if self.statMessages:
            self.stream.put(self.statMessages)
            self.statMessages = []
        event.reactor.schedule(1, self)
Exemplo n.º 7
0
    def __init__(self, args):
        self.host = args.host
        self.port = args.port
        self.tether = Tether(None, "//%s/bizlogic" % self.host, None,
                             host=self.host, port=self.port,
                             agent_type="bizlogic", policy="ordered")

        self.users = {}
        self.user_reread_period = 30  # seconds
        self.linker = Linker()
        self.container = Container(Processor(self))
        self.container[self.tether.agent] = Agent(self.tether)
Exemplo n.º 8
0
 def setUp(self):
     fake_tether = Tether(None, "", None)
     self.agent = Agent(fake_tether, self)
     self.server = Server(self.agent)
     self.reactor = Reactor(self.server)
     self.samples = 0