本文整理汇总了Python中vlcp.event.runnable.RoutineContainer类的典型用法代码示例。如果您正苦于以下问题:Python RoutineContainer类的具体用法?Python RoutineContainer怎么用?Python RoutineContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RoutineContainer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: __init__
def __init__(self, server):
FlowBase.__init__(self, server)
self.apiroutine = RoutineContainer(self.scheduler)
self.apiroutine.main = self._main
self.routines.append(self.apiroutine)
self._flowupdaters = {}
self._extra_arps = {}
开发者ID:hubo1016,项目名称:vlcp,代码行数:7,代码来源:dhcpserver.py
示例17: __init__
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)
开发者ID:dq5070410,项目名称:vlcp,代码行数:8,代码来源:testzookeeper.py
示例18: DHCPServer
class DHCPServer(FlowBase):
"Send ARP respond"
_tablerequest = (("l3input", ('l2input',), ''),
("l2output", ("l3input",), ''))
_default_serveraddress = '169.254.169.254'
_default_servermac = '1a:23:67:59:63:33'
_default_leasetime = None
_default_t1 = None
_default_t2 = None
def __init__(self, server):
FlowBase.__init__(self, server)
self.apiroutine = RoutineContainer(self.scheduler)
self.apiroutine.main = self._main
self.routines.append(self.apiroutine)
self._flowupdaters = {}
self._extra_arps = {}
def _main(self):
flow_init = FlowInitialize.createMatcher(_ismatch = lambda x: self.vhostbind is None or x.vhost in self.vhostbind)
conn_down = OpenflowConnectionStateEvent.createMatcher(state = OpenflowConnectionStateEvent.CONNECTION_DOWN,
_ismatch = lambda x: self.vhostbind is None or x.createby.vhost in self.vhostbind)
while True:
yield (flow_init, conn_down)
if self.apiroutine.matcher is flow_init:
c = self.apiroutine.event.connection
self.apiroutine.subroutine(self._init_conn(self.apiroutine.event.connection))
else:
c = self.apiroutine.event.connection
self.apiroutine.subroutine(self._remove_conn(c))
def _init_conn(self, conn):
# Default
if conn in self._flowupdaters:
updater = self._flowupdaters.pop(conn)
updater.close()
updater = DHCPUpdater(conn, self)
#flowupdater = VXLANFlowUpdater(conn, self)
self._flowupdaters[conn] = updater
updater.start()
if False:
yield
def _remove_conn(self, conn):
# Do not need to modify flows
if conn in self._flowupdaters:
self._flowupdaters.pop(conn).close()
if False:
yield
开发者ID:hubo1016,项目名称:vlcp,代码行数:45,代码来源:dhcpserver.py
示例19: __init__
def __init__(self, server):
FlowBase.__init__(self, server)
self.apiroutine = RoutineContainer(self.scheduler)
self.apiroutine.main = self._main
self.routines.append(self.apiroutine)
self._flowupdaters = {}
self._extra_arps = {}
self.createAPI(api(self.createproxyarp),
api(self.removeproxyarp))
开发者ID:hubo1016,项目名称:vlcp,代码行数:9,代码来源:arpresponder.py
示例20: __init__
def __init__(self, connection, initialkeys, requestid = None, logger = None):
RoutineContainer.__init__(self, connection.scheduler)
self._initialkeys = initialkeys
self._connection = connection
self._walkerdict = {}
self._savedkeys = ()
self._savedresult = []
self._updatedset = set()
self._updatedset2 = set()
if not logger:
self._logger = logging.getLogger(__name__ + '.FlowUpdater')
else:
self._logger = logger
if requestid is None:
self._requstid = str(uuid1())
else:
self._requstid = requestid
self._dataupdateroutine = None
self._flowupdateroutine = None
开发者ID:hubo1016,项目名称:vlcp,代码行数:19,代码来源:flowupdater.py
注:本文中的vlcp.event.runnable.RoutineContainer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论