当前位置: 首页>>代码示例>>Python>>正文


Python reactor.Reactor类代码示例

本文整理汇总了Python中proton.reactor.Reactor的典型用法代码示例。如果您正苦于以下问题:Python Reactor类的具体用法?Python Reactor怎么用?Python Reactor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Reactor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: do_customEvent

  def do_customEvent(self, reactor_handler, event_root):

    class CustomHandler:
      did_custom = False
      did_init = False
      def __init__(self, *handlers):
        self.handlers = handlers
      def on_reactor_init(self, event):
        self.did_init = True
      def on_custom(self, event):
        self.did_custom = True

    class CustomInvoker(CustomHandler):
      def on_reactor_init(self, event):
        h = event_root(event)
        event.dispatch(h, CUSTOM)
        self.did_init = True

    child = CustomInvoker()
    root = CustomHandler(child)

    reactor = Reactor()

    reactor_handler(reactor, root)
    reactor.run()
    assert root.did_init
    assert child.did_init
    assert root.did_custom
    assert child.did_custom
开发者ID:engineer-legion,项目名称:qpid-proton,代码行数:29,代码来源:handler.py

示例2: protonj_to_protonc

  def protonj_to_protonc(self, count):
    if (not self.proton_j_available):
      raise Skipped("ProtonJ not found")

    rh = ReceiveHandler(count)
    r = Reactor(rh)
    r.run()

    rh.java_thread.join()
    assert(rh.java_thread.result == 0)

    for i in range(1, count):
      assert(rh.messages[i-1] == ("message-" + str(i)))
开发者ID:850361813,项目名称:qpid-proton,代码行数:13,代码来源:reactor_interop.py

示例3: setUp

    def setUp(self):
        import platform

        if platform.python_implementation() != "Jython":
            # Exception propagation does not work currently for CPython
            raise SkipTest()
        self.reactor = Reactor()
开发者ID:Karm,项目名称:qpid-proton,代码行数:7,代码来源:reactor.py

示例4: SourceTest

class SourceTest(TestCase):
    def setUp(self):
        self.source = Source("test-%s")
        self.server = Server(self.source)
        self.reactor = Reactor(self.server)

    def tearDown(self):
        pass

    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

    def testReceiver150(self):
        self.testReceiver(150)

    # This doesn't seem to work for any value > 150! This is a proton
    # bug that needs to be isolated and pushed upstream. Enable and
    # run under valgrind for more details.
    def XXXtestReceiver151(self):
        self.testReceiver(151)
开发者ID:datawire,项目名称:datawire-common,代码行数:47,代码来源:linker.py

示例5: __init__

 def __init__(self, *args):
     self.reactor = Reactor(*args)
     self.reactor.global_handler = self
     self.io = IOHandler()
     self.loop = tornado.ioloop.IOLoop.instance()
     self.count = 0
     self.reactor.start()
     self.reactor.process()
开发者ID:alisheikh,项目名称:datawire-common,代码行数:8,代码来源:tornado_app.py

示例6: protonc_to_protonj

  def protonc_to_protonj(self, count):
    if (not self.proton_j_available):
      raise Skipped("ProtonJ not found")

    port = free_tcp_port()
    java_thread = JavaThread("recv", port, count)
    java_thread.start()
    # Give the Java thread time to spin up a JVM and start listening
    # XXX: would be better to parse the stdout output for a message
    time.sleep(1)

    sh = SendHandler('127.0.0.1:' + str(port), count)
    r = Reactor(sh)
    r.run()

    java_thread.join()
    assert(java_thread.result == 0)
开发者ID:850361813,项目名称:qpid-proton,代码行数:17,代码来源:reactor_interop.py

示例7: __init__

 def __init__(self):
     class FakeTether:
         def __init__(self):
             self.address = None
             self.agent = None
             self.agent_type = None
     self.agent = Agent(FakeTether(), self)
     self.server = Server(self.agent)
     self.reactor = Reactor(self.server)
     self.samples = 0
开发者ID:alisheikh,项目名称:datawire-common,代码行数:10,代码来源:agent.py

示例8: AgentTest

class AgentTest(TestCase):

    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

    def tearDown(self):
        if self.server.acceptor:
            self.server.acceptor.close()

    def sample(self, stats):
        stats["samples"] = self.samples
        self.samples += 1

    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"

    def testAgent10M100F(self):
        self.testAgent(10, 100)
开发者ID:datawire,项目名称:datawire-common,代码行数:42,代码来源:agent.py

示例9: test_reactorHandlerCycling

  def test_reactorHandlerCycling(self, n=0):

    class CustomHandler(Handler):
      UNSET = 999999999
      def __init__(self):
        self.offset = len(traceback.extract_stack())
      def on_reactor_init(self, event):
        self.depth = len(traceback.extract_stack())
      def reset(self):
        self.depth = self.UNSET
      @property
      def init_depth(self):
        d = self.depth - self.offset
        return d
    custom = CustomHandler()

    reactor = Reactor()
    reactor.handler = custom
    for i in range(n):
      h = reactor.handler
      reactor.handler = h
    custom.reset()
    reactor.run()
    assert custom.init_depth < 50, "Unexpectedly long traceback for a simple handler"
开发者ID:engineer-legion,项目名称:qpid-proton,代码行数:24,代码来源:handler.py

示例10: HandlerDerivationTest

class HandlerDerivationTest(Test):
    def setUp(self):
        import platform
        if platform.python_implementation() != "Jython":
          # Exception propagation does not work currently for CPython
          raise SkipTest()
        self.reactor = Reactor()

    def wrong_exception(self):
        import sys
        ex = sys.exc_info()
        assert False, " Unexpected exception " + str(ex[1])
    
    def test_reactor_final_derived(self):
        h = BarfOnFinalDerived()
        self.reactor.global_handler = h
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass
        except:
            self.wrong_exception()

    def test_reactor_final_py_child_py(self):
        class APoorExcuseForAHandler:
            def __init__(self):
                self.handlers = [BarfOnFinal()]
        self.reactor.global_handler = APoorExcuseForAHandler()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass
        except:
            self.wrong_exception()

    def test_reactor_final_py_child_derived(self):
        class APoorExcuseForAHandler:
            def __init__(self):
                self.handlers = [BarfOnFinalDerived()]
        self.reactor.global_handler = APoorExcuseForAHandler()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass
        except:
            self.wrong_exception()

    def test_reactor_final_derived_child_derived(self):
        class APoorExcuseForAHandler(CHandshaker):
            def __init__(self):
                CHandshaker.__init__(self)
                self.handlers = [BarfOnFinalDerived()]
        self.reactor.global_handler = APoorExcuseForAHandler()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass
        except:
            self.wrong_exception()

    def test_reactor_final_derived_child_py(self):
        class APoorExcuseForAHandler(CHandshaker):
            def __init__(self):
                CHandshaker.__init__(self)
                self.handlers = [BarfOnFinal()]
        self.reactor.global_handler = APoorExcuseForAHandler()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass
        except:
            self.wrong_exception()

    def test_reactor_init_derived(self):
        h = BarfOnFinalDerived()
        self.reactor.global_handler = h
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except:
            assert h.init, "excpected the init"

    def test_reactor_init_py_child_py(self):
        h = BarfOnFinal()
        class APoorExcuseForAHandler:
            def __init__(self):
                self.handlers = [h]
        self.reactor.global_handler = APoorExcuseForAHandler()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except:
            assert h.init, "excpected the init"

    def test_reactor_init_py_child_derived(self):
#.........这里部分代码省略.........
开发者ID:andrew-buckley,项目名称:qpid-proton,代码行数:101,代码来源:reactor.py

示例11: setup

 def setup(self):
     self.reactor = Reactor()
开发者ID:RobertoMalatesta,项目名称:qpid-proton,代码行数:2,代码来源:reactor.py

示例12: setUp

 def setUp(self):
     self.sink = Sink()
     self.server = Server(self.sink)
     self.reactor = Reactor(self.server)
开发者ID:datawire,项目名称:datawire-common,代码行数:4,代码来源:linker.py

示例13: SinkTest

class SinkTest(TestCase):
    def setUp(self):
        self.sink = Sink()
        self.server = Server(self.sink)
        self.reactor = Reactor(self.server)

    def tearDown(self):
        pass

    def testSender(self, count=1):
        self.server.max_connections = 1
        snd = Sender("//localhost:%s" % PORT)
        self.reactor.handler.add(snd)
        snd.start(self.reactor)
        for i in range(count):
            snd.send("test-%s" % i)
        snd.close()
        self.reactor.run()
        assert len(self.sink.messages) == count
        for i in range(count):
            assert self.sink.messages[i] == "test-%s" % i, self.sink.messages[i]

    def testSender4K(self):
        self.testSender(4 * 1024)

    def testSampler(self, count=1, frequency=10):
        self.server.max_connections = 1
        oself = self

        class Gen(Timeout):
            def __init__(self):
                self.sent = 0

            def on_sample(self, event):
                event.link.send(Message("test-%s" % self.sent))
                self.sent += 1
                if self.sent >= count:
                    event.link.close()
                    self.cancel()

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

        gen = Gen()
        snd = Sender("//localhost:%s" % PORT, Sampler(gen, frequency))
        self.reactor.handler.add(snd)
        gen.set_timeout(self.reactor, 2)
        snd.start(self.reactor)
        self.reactor.run()
        assert gen.cancelled, "Sampling timed out"
        assert len(self.sink.messages) == count, len(self.sink.messages)
        for i in range(count):
            assert self.sink.messages[i] == "test-%s" % i

    def testSampler100M100F(self):
        self.testSampler(100, 100)

    def testLinker(self, address_count=1, message_count=1):
        self.server.max_connections = address_count
        linker = Linker()
        linker.start(self.reactor)
        for i in range(address_count):
            for j in range(message_count):
                snd = linker.sender("//localhost:%s/%s" % (PORT, i))
                assert len(linker.senders) == i + 1
                snd.send(dict(i=i, j=j))
        linker.close()
        self.reactor.run()

        by_addr = dict((i, []) for i in range(address_count))
        for m in self.sink.messages:
            by_addr[m["i"]].append(m)
        for addr, msgs in by_addr.iteritems():
            self.assertSequenceEqual(msgs, list(sorted(msgs, key=lambda x: (x["i"], x["j"]))))
        self.assertEqual(len(self.sink.messages), address_count * message_count)

    def testLinker2A1M(self):
        self.testLinker(2, 1)

    def testLinker4A1M(self):
        self.testLinker(4, 1)

    def testLinker16A1M(self):
        self.testLinker(16, 1)

    def testLinker1A2M(self):
        self.testLinker(1, 2)

    def testLinker1A4M(self):
        self.testLinker(1, 4)

    def testLinker1A16M(self):
        self.testLinker(1, 16)

    def testLinker2A2M(self):
        self.testLinker(2, 2)

    def testLinker4A4M(self):
        self.testLinker(4, 4)

#.........这里部分代码省略.........
开发者ID:datawire,项目名称:datawire-common,代码行数:101,代码来源:linker.py

示例14: ExceptionTest

class ExceptionTest(Test):

    def setup(self):
        self.reactor = Reactor()

    def test_reactor_final(self):
        self.reactor.global_handler = BarfOnFinal()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_global_set(self):
        self.reactor.global_handler = BarfOnInit()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_global_add(self):
        self.reactor.global_handler.add(BarfOnInit())
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_reactor_set(self):
        self.reactor.handler = BarfOnInit()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_reactor_add(self):
        self.reactor.handler.add(BarfOnInit())
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_connection(self):
        self.reactor.connection(BarfOnInit())
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_connection_set(self):
        c = self.reactor.connection()
        c.handler = BarfOnInit()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_connection_add(self):
        c = self.reactor.connection()
        c.handler = object()
        c.handler.add(BarfOnInit())
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_session_set(self):
        c = self.reactor.connection()
        s = c.session()
        s.handler = BarfOnInit()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_session_add(self):
        c = self.reactor.connection()
        s = c.session()
        s.handler = object()
        s.handler.add(BarfOnInit())
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_link_set(self):
        c = self.reactor.connection()
        s = c.session()
        l = s.sender("xxx")
        l.handler = BarfOnInit()
        try:
            self.reactor.run()
#.........这里部分代码省略.........
开发者ID:flaper87,项目名称:qpid-proton,代码行数:101,代码来源:reactor.py

示例15: ExceptionTest

class ExceptionTest(Test):
    def setup(self):
        self.reactor = Reactor()

    def test_reactor_final(self):
        self.reactor.global_handler = BarfOnFinal()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_global_set(self):
        self.reactor.global_handler = BarfOnInit()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_global_add(self):
        self.reactor.global_handler.add(BarfOnInit())
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_reactor_set(self):
        self.reactor.handler = BarfOnInit()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_reactor_add(self):
        self.reactor.handler.add(BarfOnInit())
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_connection(self):
        self.reactor.connection(BarfOnInit())
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_connection_set(self):
        c = self.reactor.connection()
        c.handler = BarfOnInit()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_connection_add(self):
        c = self.reactor.connection()
        c.handler = object()
        c.handler.add(BarfOnInit())
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_session_set(self):
        c = self.reactor.connection()
        s = c.session()
        s.handler = BarfOnInit()
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_session_add(self):
        c = self.reactor.connection()
        s = c.session()
        s.handler = object()
        s.handler.add(BarfOnInit())
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_link_set(self):
        c = self.reactor.connection()
        s = c.session()
        l = s.sender("xxx")
        l.handler = BarfOnInit()
        try:
            self.reactor.run()
            assert False, "expected to barf"
#.........这里部分代码省略.........
开发者ID:RobertoMalatesta,项目名称:qpid-proton,代码行数:101,代码来源:reactor.py


注:本文中的proton.reactor.Reactor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。