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


Python Reactor.run方法代码示例

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


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

示例1: do_customEvent

# 需要导入模块: from proton.reactor import Reactor [as 别名]
# 或者: from proton.reactor.Reactor import run [as 别名]
  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,代码行数:31,代码来源:handler.py

示例2: protonj_to_protonc

# 需要导入模块: from proton.reactor import Reactor [as 别名]
# 或者: from proton.reactor.Reactor import run [as 别名]
  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,代码行数:15,代码来源:reactor_interop.py

示例3: SourceTest

# 需要导入模块: from proton.reactor import Reactor [as 别名]
# 或者: from proton.reactor.Reactor import run [as 别名]
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,代码行数:49,代码来源:linker.py

示例4: protonc_to_protonj

# 需要导入模块: from proton.reactor import Reactor [as 别名]
# 或者: from proton.reactor.Reactor import run [as 别名]
  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,代码行数:19,代码来源:reactor_interop.py

示例5: AgentTest

# 需要导入模块: from proton.reactor import Reactor [as 别名]
# 或者: from proton.reactor.Reactor import run [as 别名]
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,代码行数:44,代码来源:agent.py

示例6: __init__

# 需要导入模块: from proton.reactor import Reactor [as 别名]
# 或者: from proton.reactor.Reactor import run [as 别名]
class AgentTest:

    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

    def teardown(self):
        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:
            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()

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

示例7: test_reactorHandlerCycling

# 需要导入模块: from proton.reactor import Reactor [as 别名]
# 或者: from proton.reactor.Reactor import run [as 别名]
  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,代码行数:26,代码来源:handler.py

示例8: on_reactor_init

# 需要导入模块: from proton.reactor import Reactor [as 别名]
# 或者: from proton.reactor.Reactor import run [as 别名]
from proton.reactor import Reactor

class Program:

    def on_reactor_init(self, event):
        self.start = time.time()
        print "Hello, World!"

        # We can schedule a task event for some point in the future.
        # This will cause the reactor to stick around until it has a
        # chance to process the event.

        # The first argument is the delay. The second argument is the
        # handler for the event. We are just using self for now, but
        # we could pass in another object if we wanted.
        task = event.reactor.schedule(1.0, self)

        # We can ignore the task if we want to, but we can also use it
        # to pass stuff to the handler.
        task.something_to_say = "Yay"

    def on_timer_task(self, event):
        task = event.context # xxx: don't have a task property on event yet
        print task.something_to_say, "my task is complete!"

    def on_reactor_final(self, event):
        print "Goodbye, World! (after %s long seconds)" % (time.time() - self.start)

r = Reactor(Program())
r.run()
开发者ID:MZDN,项目名称:qpid-proton,代码行数:32,代码来源:scheduling.py

示例9: ExceptionTest

# 需要导入模块: from proton.reactor import Reactor [as 别名]
# 或者: from proton.reactor.Reactor import run [as 别名]
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,代码行数:103,代码来源:reactor.py

示例10: HandlerDerivationTest

# 需要导入模块: from proton.reactor import Reactor [as 别名]
# 或者: from proton.reactor.Reactor import run [as 别名]
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,代码行数:103,代码来源:reactor.py

示例11: SinkTest

# 需要导入模块: from proton.reactor import Reactor [as 别名]
# 或者: from proton.reactor.Reactor import run [as 别名]
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,代码行数:103,代码来源:linker.py

示例12: ExceptionTest

# 需要导入模块: from proton.reactor import Reactor [as 别名]
# 或者: from proton.reactor.Reactor import run [as 别名]
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,代码行数:103,代码来源:reactor.py


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