예제 #1
0
    def testReceiver(self, count=1):
        self.server.max_connections = 1
        self.source.limit = count

        oself = self

        class Counter:
            def __init__(self):
                self.received = 0
                self.receiver = None
                self.open_event = False

            def on_link_remote_open(self, event):
                self.open_event = True

            def on_message(self, event):
                assert event.message.body == oself.source.template % self.received
                self.received += 1
                if self.received == count:
                    self.receiver.stop(event.reactor)

        counter = Counter()
        rcv = Receiver("//localhost:%s" % PORT, Processor(counter))
        counter.receiver = rcv
        self.reactor.handler.add(rcv)
        rcv.start(self.reactor)
        self.reactor.run()
        assert counter.received == count
        assert counter.open_event
예제 #2
0
    def testReceiver(self, count=1):
        self.server.max_connections = 1
        self.source.limit = count

        oself = self

        class Counter:
            def __init__(self):
                self.received = 0
                self.receiver = None
                self.open_event = False

            def on_link_remote_open(self, event):
                self.open_event = True

            def on_message(self, event):
                assert event.message.body == oself.source.template % self.received
                self.received += 1
                if self.received == count:
                    self.receiver.stop(event.reactor)

        counter = Counter()
        rcv = Receiver("//localhost:%s" % PORT, Processor(counter))
        counter.receiver = rcv
        self.reactor.handler.add(rcv)
        rcv.start(self.reactor)
        self.reactor.run()
        assert counter.received == count
        assert counter.open_event
예제 #3
0
    def testAgent(self, count=1, frequency=10):
        self.server.max_connections = 1
        self.agent.sampler.frequency = frequency

        class Counter(Timeout):
            def __init__(self):
                self.received = 0

            def on_message(self, event):
                m = event.message
                assert event.message.body["samples"] == self.received, (
                    event.message.body, self.received)
                self.received += 1
                if self.received == count:
                    rcv.stop(event.reactor)
                    self.cancel()

            def on_timer_task(self, event):
                rcv.stop(event.reactor)

        counter = Counter()
        rcv = Receiver("//localhost:%s" % PORT, Processor(counter))
        rcv.start(self.reactor)
        counter.set_timeout(self.reactor, 20)
        self.reactor.run()
        assert counter.cancelled, "Sampling timed out"
예제 #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 = []
예제 #5
0
 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
예제 #6
0
 def testAgent(self, count=1, frequency=10):
     self.server.max_connections = 1
     self.agent.sampler.frequency = frequency
     class Counter:
         def __init__(self):
             self.received = 0
         def on_message(self, event):
             assert event.message.body["samples"] == self.received, (event.message.body, self.received)
             self.received += 1
             if self.received == count:
                 rcv.stop(event.reactor)
     rcv = Receiver("//localhost:%s" % PORT, Processor(Counter()))
     rcv.start(self.reactor)
     self.reactor.run()
예제 #7
0
class GetBarks(object):
    def __init__(self, user, hostname):
        self.user = user
        self.receiver = Receiver("//%s/inbox/%s" % (hostname, user),
                                 Processor(self))
        self.width = 10

    def on_reactor_init(self, event):
        self.receiver.start(event.reactor)

    def on_message(self, event):
        bark = common.Bark(*event.message.body)
        self.width = max(self.width, len(bark.user))
        print datetime.datetime.now().strftime("%H:%M:%S"), \
              self.user, "<--", "%%%ds:" % self.width % bark.user, \
              bark.content
예제 #8
0
class GetBarks(object):

    def __init__(self, user, hostname):
        self.user = user
        self.receiver = Receiver("//%s/inbox/%s" % (hostname, user), Processor(self))
        self.width = 10

    def on_reactor_init(self, event):
        self.receiver.start(event.reactor)

    def on_message(self, event):
        bark = common.Bark(*event.message.body)
        self.width = max(self.width, len(bark.user))
        print datetime.datetime.now().strftime("%H:%M:%S"), \
              self.user, "<--", "%%%ds:" % self.width % bark.user, \
              bark.content
예제 #9
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 = []
예제 #10
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)
예제 #11
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)
예제 #12
0
 def testAgent(self, count=1, frequency=10):
     self.server.max_connections = 1
     self.agent.sampler.frequency = frequency
     class Counter(Timeout):
         def __init__(self):
             self.received = 0
         def on_message(self, event):
             m = event.message
             assert event.message.body["samples"] == self.received, (event.message.body, self.received)
             self.received += 1
             if self.received == count:
                 rcv.stop(event.reactor)
                 self.cancel()
         def on_timer_task(self, event):
           rcv.stop(event.reactor)
     
     counter = Counter()
     rcv = Receiver("//localhost:%s" % PORT, Processor(counter))
     rcv.start(self.reactor)
     counter.set_timeout(self.reactor, 20)
     self.reactor.run()
     assert counter.cancelled, "Sampling timed out"
예제 #13
0
 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
예제 #14
0
 def __init__(self, user, hostname):
     self.user = user
     self.receiver = Receiver("//%s/inbox/%s" % (hostname, user),
                              Processor(self))
     self.width = 10
예제 #15
0
 def __init__(self, user, hostname):
     self.user = user
     self.receiver = Receiver("//%s/inbox/%s" % (hostname, user), Processor(self))
     self.width = 10