Keep allocate_id() in the enhanced router class.

wip-fakessh-exit-status
David Wilson 7 years ago
parent 02a37d2339
commit c67119501b

@ -868,11 +868,6 @@ class Router(object):
return handle return handle
def allocate_id(self):
master = Context(self, 0)
reply = master.send_await(Message(dst_id=0, handle=ALLOCATE_ID))
return reply.unpickle()
def on_shutdown(self, broker): def on_shutdown(self, broker):
"""Called during :py:meth:`Broker.shutdown`, informs callbacks """Called during :py:meth:`Broker.shutdown`, informs callbacks
registered with :py:meth:`add_handle_cb` the connection is dead.""" registered with :py:meth:`add_handle_cb` the connection is dead."""

@ -739,6 +739,7 @@ METHOD_NAMES = {
def upgrade_router(econtext): def upgrade_router(econtext):
if not isinstance(econtext.router, Router): # TODO if not isinstance(econtext.router, Router): # TODO
econtext.router.__class__ = Router # TODO econtext.router.__class__ = Router # TODO
econtext.router.id_allocator = ChildIdAllocator(econtext.router)
LOG.debug('_proxy_connect(): constructing ModuleForwarder') LOG.debug('_proxy_connect(): constructing ModuleForwarder')
ModuleForwarder(econtext.router, econtext.parent, econtext.importer) ModuleForwarder(econtext.router, econtext.parent, econtext.importer)
@ -785,6 +786,18 @@ class IdAllocator(object):
) )
class ChildIdAllocator(object):
def __init__(self, router):
self.router = router
def allocate(self):
master = Context(self.router, 0)
reply = master.send_await(
mitogen.core.Message(dst_id=0, handle=mitogen.core.ALLOCATE_ID)
)
return reply.unpickle()
class Router(mitogen.core.Router): class Router(mitogen.core.Router):
debug = False debug = False

@ -1,8 +1,10 @@
import mitogen.core import mitogen.core
import mitogen.master
@mitogen.core.takes_router @mitogen.core.takes_econtext
def allocate_an_id(router): def allocate_an_id(econtext):
return router.allocate_id() mitogen.master.upgrade_router(econtext)
return econtext.router.allocate_id()

Loading…
Cancel
Save