コード例 #1
0
ファイル: linker.py プロジェクト: forkkit/datawire-common
    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
ファイル: linker.py プロジェクト: datawire/datawire-common
    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
ファイル: monitor.py プロジェクト: forkkit/datawire-common
 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
ファイル: monitor.py プロジェクト: datawire/datawire-common
 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
ファイル: agent.py プロジェクト: alisheikh/datawire-common
 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
ファイル: listen.py プロジェクト: forkkit/datawire-common
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
ファイル: listen.py プロジェクト: alisheikh/datawire-common
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
ファイル: monitor.py プロジェクト: datawire/datawire-common
 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
ファイル: monitor.py プロジェクト: forkkit/datawire-common
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
ファイル: monitor.py プロジェクト: datawire/datawire-common
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
ファイル: agent.py プロジェクト: datawire/datawire-common
 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
ファイル: monitor.py プロジェクト: forkkit/datawire-common
 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
ファイル: listen.py プロジェクト: forkkit/datawire-common
 def __init__(self, user, hostname):
     self.user = user
     self.receiver = Receiver("//%s/inbox/%s" % (hostname, user),
                              Processor(self))
     self.width = 10
コード例 #15
0
ファイル: listen.py プロジェクト: alisheikh/datawire-common
 def __init__(self, user, hostname):
     self.user = user
     self.receiver = Receiver("//%s/inbox/%s" % (hostname, user), Processor(self))
     self.width = 10