當前位置: 首頁>>代碼示例>>Python>>正文


Python runnable.RoutineContainer類代碼示例

本文整理匯總了Python中vlcp.event.runnable.RoutineContainer的典型用法代碼示例。如果您正苦於以下問題:Python RoutineContainer類的具體用法?Python RoutineContainer怎麽用?Python RoutineContainer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了RoutineContainer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testSemaphore

 def testSemaphore(self):
     rc = RoutineContainer(self.server.scheduler)
     obj = [0]
     def routineLock(key):
         l = Lock(key, rc.scheduler)
         for m in l.lock(rc):
             yield m
         t = obj[0]
         for m in rc.waitWithTimeout(0.5):
             yield m
         obj[0] = t + 1
         l.unlock()
     def main_routine():
         smp = Semaphore('testobj', 2, rc.scheduler)
         smp.create()
         for m in rc.executeAll([routineLock('testobj'),
                                 routineLock('testobj'),
                                 routineLock('testobj'),
                                 routineLock('testobj')], retnames = ()):
             yield m
         for m in smp.destroy(rc):
             yield m
     rc.subroutine(main_routine())
     self.server.serve()
     self.assertEqual(obj[0], 2)
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:25,代碼來源:testLock.py

示例2: testLoopConsumer

 def testLoopConsumer(self):
     scheduler = Scheduler()
     scheduler.queue.addSubQueue(10, RoutineControlEvent.createMatcher())
     scheduler.queue.addSubQueue(1, TestConsumerEvent.createMatcher(), 'consumer', 5, 5)
     rA = RoutineContainer(scheduler)
     output = bytearray()
     def mainA():
         rA.subroutine(mainB(), True, 'mainB', True)
         matcher = TestConsumerEvent.createMatcher(rA.mainB)
         for i in range(0,10):
             for ms in rA.waitForSend(TestConsumerEvent(rA.mainroutine)):
                 yield ms
             output.extend(b'A')
             yield (matcher,)
     def mainB():
         matcher = TestConsumerEvent.createMatcher(producer=rA.mainroutine)
         while True:
             yield (matcher,)
             rA.event.canignore = True
             output.extend(b'B')
             for ms in rA.waitForSend(TestConsumerEvent(rA.mainB, canignore = True)):
                 yield ms                
     rA.main = mainA
     rA.start()
     scheduler.main()
     self.assertEqual(output, b'ABABABABABABABABABAB')
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:26,代碼來源:testScheduler.py

示例3: ICMPResponder

class ICMPResponder(FlowBase):
    _tablerequest = (
        ("l3input",("l2input",),""),
        ("l2output",("l3input",),"")
    )
    # True :  use flow auto reply icmp ping
    # False: use controller reply icmp ping

    #
    # when ovs 2.5 , icmp_type is not readonly , we can use flow auto reply icmp echo
    #
    _default_prepush = False

    # router use this mac as inner mac
    _default_inroutermac = '1a:23:67:59:63:33'

    def __init__(self,server):
        super(ICMPResponder,self).__init__(server)
        self.app_routine = RoutineContainer(self.scheduler)
        self.app_routine.main = self._main
        self.routines.append(self.app_routine)
        self._flowupdater = dict()

    def _main(self):

        flowinit = FlowInitialize.createMatcher(_ismatch=lambda x: self.vhostbind is None or
                                                x.vhost in self.vhostbind)
        conndown = OpenflowConnectionStateEvent.createMatcher(state = OpenflowConnectionStateEvent.CONNECTION_DOWN,
                                                _ismatch=lambda x:self.vhostbind is None or
                                                x.createby.vhost in self.vhostbind)
        while True:
            yield (flowinit,conndown)
            if self.app_routine.matcher is flowinit:
                c = self.app_routine.event.connection
                self.app_routine.subroutine(self._init_conn(c))
            if self.app_routine.matcher is conndown:
                c = self.app_routine.event.connection
                self.app_routine.subroutine(self._remove_conn(c))

    def _init_conn(self,conn):

        if conn in self._flowupdater:
            updater = self._flowupdater.pop(conn)
            updater.close()

        updater = ICMPResponderUpdater(conn,self)
        self._flowupdater[conn] = updater
        updater.start()

        if False:
            yield

    def _remove_conn(self,conn):

        if conn in self._flowupdater:
            updater = self._flowupdater.pop(conn)
            updater.close()

        if False:
            yield
開發者ID:hubo1016,項目名稱:vlcp,代碼行數:60,代碼來源:icmpresponder.py

示例4: testBeginlock

 def testBeginlock(self):
     rc = RoutineContainer(self.server.scheduler)
     obj = [0]
     def routineLock(key):
         l = Lock(key, rc.scheduler)
         locked = l.beginlock(rc)
         if not locked:
             for m in rc.waitWithTimeout(1.0):
                 yield m
             locked = l.trylock()
             if not locked:
                 raise ValueError('Not locked')
         t = obj[0]
         for m in rc.waitWithTimeout(0.5):
             yield m
         obj[0] = t + 1
         l.unlock()
         for m in rc.doEvents():
             yield m
         for m in l.lock(rc):
             yield m
         t = obj[0]
         for m in rc.waitWithTimeout(1.0):
             yield m
         obj[0] = t + 1
         l.unlock()
     rc.subroutine(routineLock('testobj'))
     rc.subroutine(routineLock('testobj'))
     self.server.serve()
     self.assertEqual(obj[0], 4)
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:30,代碼來源:testLock.py

示例5: TestModule

class TestModule(Module):
    _default_serverlist = ['tcp://localhost:3181/','tcp://localhost:3182/','tcp://localhost:3183/']
    def __init__(self, server):
        Module.__init__(self, server)
        self.apiroutine = RoutineContainer(self.scheduler)
        self.client = ZooKeeperClient(self.apiroutine, self.serverlist)
        self.connections.append(self.client)
        self.apiroutine.main = self.main
        self.routines.append(self.apiroutine)
    def watcher(self):
        watcher = ZooKeeperWatcherEvent.createMatcher()
        while True:
            yield (watcher,)
            print('WatcherEvent: %r' % (dump(self.apiroutine.event.message),))
    def main(self):
        def _watch(w):
            for m in w.wait(self.apiroutine):
                yield m
            print('Watcher returns:', dump(self.apiroutine.retvalue))
        def _watchall(watchers):
            for w in watchers:
                if w is not None:
                    self.apiroutine.subroutine(_watch(w))
        self.apiroutine.subroutine(self.watcher(), False, daemon = True)
        up = ZooKeeperSessionStateChanged.createMatcher(ZooKeeperSessionStateChanged.CREATED, self.client)
        yield (up,)
        print('Connection is up: %r' % (self.client.currentserver,))
        for m in self.client.requests([zk.create(b'/vlcptest', b'test'),
                                       zk.getdata(b'/vlcptest', True)], self.apiroutine):
            yield m
        print(self.apiroutine.retvalue)
        pprint(dump(self.apiroutine.retvalue[0]))
        _watchall(self.apiroutine.retvalue[3])
        for m in self.apiroutine.waitWithTimeout(0.2):
            yield m
        for m in self.client.requests([zk.delete(b'/vlcptest'),
                                        zk.getdata(b'/vlcptest', watch = True)], self.apiroutine):
            yield m
        print(self.apiroutine.retvalue)
        pprint(dump(self.apiroutine.retvalue[0]))
        _watchall(self.apiroutine.retvalue[3])
        for m in self.client.requests([zk.multi(
                                        zk.multi_create(b'/vlcptest2', b'test'),
                                        zk.multi_create(b'/vlcptest2/subtest', 'test2')
                                    ),
                                  zk.getchildren2(b'/vlcptest2', True)], self.apiroutine):
            yield m
        print(self.apiroutine.retvalue)
        pprint(dump(self.apiroutine.retvalue[0]))
        _watchall(self.apiroutine.retvalue[3])
        for m in self.client.requests([zk.multi(
                                        zk.multi_delete(b'/vlcptest2/subtest'),
                                        zk.multi_delete(b'/vlcptest2')),
                                  zk.getchildren2(b'/vlcptest2', True)], self.apiroutine):
            yield m
        print(self.apiroutine.retvalue)
        pprint(dump(self.apiroutine.retvalue[0]))
        _watchall(self.apiroutine.retvalue[3])
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:58,代碼來源:testzookeeper2.py

示例6: __init__

 def __init__(self, moduleinst, apidefs = None, allowdiscover = True, rejectunknown = True):
     RoutineContainer.__init__(self, scheduler=moduleinst.scheduler, daemon=False)
     self.handler = EventHandler(self.scheduler)
     self.servicename = moduleinst.getServiceName()
     self.apidefs = apidefs
     self.registeredAPIs = {}
     self.discoverinfo = {}
     self.allowdiscover = allowdiscover
     self.rejectunknown = True
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:9,代碼來源:module.py

示例7: TestModule

class TestModule(Module):
    _default_url = 'tcp://localhost/'
    _default_sessiontimeout = 30
    def __init__(self, server):
        Module.__init__(self, server)
        self.protocol = ZooKeeper()
        self.client = Client(self.url, self.protocol, self.scheduler)
        self.connections.append(self.client)
        self.apiroutine = RoutineContainer(self.scheduler)
        self.apiroutine.main = self.main
        self.routines.append(self.apiroutine)
    def watcher(self):
        watcher = ZooKeeperWatcherEvent.createMatcher(connection = self.client)
        while True:
            yield (watcher,)
            print('WatcherEvent: %r' % (dump(self.apiroutine.event.message),))
    def main(self):
        self.apiroutine.subroutine(self.watcher(), False, daemon = True)
        up = ZooKeeperConnectionStateEvent.createMatcher(ZooKeeperConnectionStateEvent.UP, self.client)
        notconn = ZooKeeperConnectionStateEvent.createMatcher(ZooKeeperConnectionStateEvent.NOTCONNECTED, self.client)
        yield (up, notconn)
        if self.apiroutine.matcher is notconn:
            print('Not connected')
            return
        else:
            print('Connection is up: %r' % (self.client,))
        # Handshake
        for m in self.protocol.handshake(self.client, zk.ConnectRequest(
                                                        timeOut = int(self.sessiontimeout * 1000),
                                                        passwd = b'\x00' * 16,      # Why is it necessary...
                                                    ), self.apiroutine, []):
            yield m
        for m in self.protocol.requests(self.client, [zk.create(b'/vlcptest', b'test'),
                                                      zk.getdata(b'/vlcptest', True)], self.apiroutine):
            yield m
        pprint(dump(self.apiroutine.retvalue[0]))
        for m in self.apiroutine.waitWithTimeout(0.2):
            yield m
        for m in self.protocol.requests(self.client, [zk.delete(b'/vlcptest'),
                                                      zk.getdata(b'/vlcptest', watch = True)], self.apiroutine):
            yield m
        pprint(dump(self.apiroutine.retvalue[0]))
        for m in self.protocol.requests(self.client, [zk.multi(
                                                            zk.multi_create(b'/vlcptest2', b'test'),
                                                            zk.multi_create(b'/vlcptest2/subtest', 'test2')
                                                        ),
                                                      zk.getchildren2(b'/vlcptest2', True)], self.apiroutine):
            yield m
        pprint(dump(self.apiroutine.retvalue[0]))
        for m in self.protocol.requests(self.client, [zk.multi(
                                                            zk.multi_delete(b'/vlcptest2/subtest'),
                                                            zk.multi_delete(b'/vlcptest2')),
                                                      zk.getchildren2(b'/vlcptest2', True)], self.apiroutine):
            yield m
        pprint(dump(self.apiroutine.retvalue[0]))
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:55,代碼來源:testzookeeper.py

示例8: __init__

 def __init__(self, vhostbind, prefix, scheduler=None, singlecastlimit = 256, deflate = False):
     RoutineContainer.__init__(self, scheduler=scheduler, daemon=False)
     self.vhostbind = vhostbind
     self.prefix = _bytes(prefix)
     self._matchers = {}
     self._publishkey = uuid.uuid1().hex
     self._publishno = 1
     self._publish_wait = set()
     self._matchadd_wait = set()
     self._matchremove_wait = set()
     self._singlecastlimit = singlecastlimit
     self._deflate = deflate
開發者ID:hubo1016,項目名稱:vlcp,代碼行數:12,代碼來源:redisnotifier.py

示例9: testTrylock

 def testTrylock(self):
     rc = RoutineContainer(self.server.scheduler)
     result = []
     def routineTrylock(key):
         l = Lock(key, rc.scheduler)
         locked = l.trylock()
         result.append(locked)
         for m in rc.waitWithTimeout(0.5):
             yield m
         l.unlock()
     rc.subroutine(routineTrylock('testobj'))
     rc.subroutine(routineTrylock('testobj'))
     self.server.serve()
     self.assertEqual(result, [True, False])
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:14,代碼來源:testLock.py

示例10: TestModule

class TestModule(Module):
    _default_serverlist = ['tcp://localhost:3181/','tcp://localhost:3182/','tcp://localhost:3183/']
    def __init__(self, server):
        Module.__init__(self, server)
        self.apiroutine = RoutineContainer(self.scheduler)
        self.apiroutine.main = self.main
        self.routines.append(self.apiroutine)
    def main(self):
        clients = [ZooKeeperClient(self.apiroutine, self.serverlist) for _ in range(0,10)]
        for c in clients:
            c.start()
        def test_loop(number):
            maindir = ('vlcptest_' + str(number)).encode('utf-8')
            client = clients[number % len(clients)]
            for _ in range(0, 100):
                for m in client.requests([zk.multi(
                                                zk.multi_create(maindir, b'test'),
                                                zk.multi_create(maindir + b'/subtest', 'test2')
                                            ),
                                          zk.getchildren2(maindir, True)], self.apiroutine):
                    yield m
                for m in client.requests([zk.multi(
                                                zk.multi_delete(maindir + b'/subtest'),
                                                zk.multi_delete(maindir)),
                                          zk.getchildren2(maindir, True)], self.apiroutine):
                    yield m
        from time import time
        starttime = time()
        for m in self.apiroutine.executeAll([test_loop(i) for i in range(0, 100)]):
            yield m
        print('10000 loops in %r seconds, with %d connections' % (time() - starttime, len(clients)))
        for c in clients:
            for m in c.shutdown():
                yield m
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:34,代碼來源:testzookeeper3.py

示例11: __init__

 def __init__(self, server):
     Module.__init__(self, server)
     self._managed_objs = {}
     self._watches = {}
     self._watchedkeys = set()
     self._requests = []
     self._transactno = 0
     self._stale = False
     self._updatekeys = set()
     self._update_version = {}
     self.apiroutine = RoutineContainer(self.scheduler)
     self.apiroutine.main = self._update
     self.routines.append(self.apiroutine)
     self.createAPI(api(self.mget, self.apiroutine),
                    api(self.get, self.apiroutine),
                    api(self.mgetonce, self.apiroutine),
                    api(self.getonce, self.apiroutine),
                    api(self.mwatch, self.apiroutine),
                    api(self.watch, self.apiroutine),
                    api(self.munwatch, self.apiroutine),
                    api(self.unwatch, self.apiroutine),
                    api(self.unwatchall, self.apiroutine),
                    api(self.transact, self.apiroutine),
                    api(self.watchlist),
                    api(self.walk, self.apiroutine)
                    )
開發者ID:,項目名稱:,代碼行數:26,代碼來源:

示例12: __init__

 def __init__(self, server):
     Module.__init__(self, server)
     self.apiroutine = RoutineContainer(self.scheduler)
     self.client = ZooKeeperClient(self.apiroutine, self.serverlist)
     self.connections.append(self.client)
     self.apiroutine.main = self.main
     self.routines.append(self.apiroutine)
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:7,代碼來源:testzookeeper2.py

示例13: testLock2

 def testLock2(self):
     rc = RoutineContainer(self.server.scheduler)
     obj = [0]
     def routineLock(key):
         l = Lock(key, rc.scheduler)
         for m in l.lock(rc):
             yield m
         t = obj[0]
         for m in rc.waitWithTimeout(0.5):
             yield m
         obj[0] = t + 1
         l.unlock()
     rc.subroutine(routineLock('testobj'))
     rc.subroutine(routineLock('testobj2'))
     self.server.serve()
     self.assertEqual(obj[0], 1)
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:16,代碼來源:testLock.py

示例14: __init__

 def __init__(self, server):
     Module.__init__(self, server)
     self.apiroutine = RoutineContainer(self.scheduler)
     self.apiroutine.main = self._manage_conns
     self.routines.append(self.apiroutine)
     self.managed_conns = {}
     self.managed_systemids = {}
     self.managed_bridges = {}
     self.managed_routines = []
     self.endpoint_conns = {}
     self.createAPI(api(self.getconnection, self.apiroutine),
                    api(self.waitconnection, self.apiroutine),
                    api(self.getdatapathids, self.apiroutine),
                    api(self.getalldatapathids, self.apiroutine),
                    api(self.getallconnections, self.apiroutine),
                    api(self.getbridges, self.apiroutine),
                    api(self.getbridge, self.apiroutine),
                    api(self.getbridgebyuuid, self.apiroutine),
                    api(self.waitbridge, self.apiroutine),
                    api(self.waitbridgebyuuid, self.apiroutine),
                    api(self.getsystemids, self.apiroutine),
                    api(self.getallsystemids, self.apiroutine),
                    api(self.getconnectionbysystemid, self.apiroutine),
                    api(self.waitconnectionbysystemid, self.apiroutine),
                    api(self.getconnectionsbyendpoint, self.apiroutine),
                    api(self.getconnectionsbyendpointname, self.apiroutine),
                    api(self.getendpoints, self.apiroutine),
                    api(self.getallendpoints, self.apiroutine),
                    api(self.getallbridges, self.apiroutine),
                    api(self.getbridgeinfo, self.apiroutine),
                    api(self.waitbridgeinfo, self.apiroutine)
                    )
     self._synchronized = False
開發者ID:hubo1016,項目名稱:vlcp,代碼行數:33,代碼來源:ovsdbmanager.py

示例15: __init__

 def __init__(self, server):
     Module.__init__(self, server)
     self.apiroutine = RoutineContainer(self.scheduler)
     self.apiroutine.main = self._manage_conns
     self.routines.append(self.apiroutine)
     self.managed_conns = {}
     self.endpoint_conns = {}
     self.table_modules = set()
     self._acquiring = False
     self._acquire_updated = False
     self._lastacquire = None
     self._synchronized = False
     self.createAPI(api(self.getconnections, self.apiroutine),
                    api(self.getconnection, self.apiroutine),
                    api(self.waitconnection, self.apiroutine),
                    api(self.getdatapathids, self.apiroutine),
                    api(self.getalldatapathids, self.apiroutine),
                    api(self.getallconnections, self.apiroutine),
                    api(self.getconnectionsbyendpoint, self.apiroutine),
                    api(self.getconnectionsbyendpointname, self.apiroutine),
                    api(self.getendpoints, self.apiroutine),
                    api(self.getallendpoints, self.apiroutine),
                    api(self.acquiretable, self.apiroutine),
                    api(self.unacquiretable, self.apiroutine),
                    api(self.lastacquiredtables)
                    )
開發者ID:hubo1016,項目名稱:vlcp,代碼行數:26,代碼來源:ofpmanager.py


注:本文中的vlcp.event.runnable.RoutineContainer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。