diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2011-01-11 12:21:28 +0100 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2011-01-11 12:21:28 +0100 |
commit | c35e75e477136f6fd81301a07e02630d1f1cb3d6 (patch) | |
tree | 112b501b4136e7965f72ea87dce05c3bd8cdf764 /pyro_ext.py | |
parent | 6f55776a998c776654728a0dd468bd48325da482 (diff) | |
download | logilab-common-c35e75e477136f6fd81301a07e02630d1f1cb3d6.tar.gz |
pyro: new ns_reregister function to ensure a name is still properly registered in the pyro name server
Diffstat (limited to 'pyro_ext.py')
-rw-r--r-- | pyro_ext.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/pyro_ext.py b/pyro_ext.py index e619130..15e6b2d 100644 --- a/pyro_ext.py +++ b/pyro_ext.py @@ -62,6 +62,7 @@ def host_and_port(hoststr): return hoststr, port _DAEMONS = {} +_PYRO_OBJS = {} def _get_daemon(daemonhost, start=True): if not daemonhost in _DAEMONS: if not start: @@ -98,7 +99,9 @@ def register_object(object, nsid, defaultnsgroup=_MARKER, # use Delegation approach impl = core.ObjBase() impl.delegateTo(object) - daemon.connect(impl, '%s.%s' % (nsgroup, nsid)) + qnsid = '%s.%s' % (nsgroup, nsid) + uri = daemon.connect(impl, qnsid) + _PYRO_OBJS[qnsid] = uri _LOGGER.info('registered %s a pyro object using group %s and id %s', object, nsgroup, nsid) return daemon @@ -119,6 +122,26 @@ def ns_unregister(nsid, defaultnsgroup=_MARKER, nshost=None): except errors.NamingError: _LOGGER.warning('%s not registered in pyro name server', nsid) +def ns_reregister(nsid, defaultnsgroup=_MARKER, nshost=None): + """reregister a pyro object into the name server. You only have to specify + the name-server id of the object (though you MUST have gone through + `register_object` for the given object previously). + + This is especially useful for long running server while the name server may + have been restarted, and its records lost. + """ + nsgroup, nsid = ns_group_and_id(nsid, defaultnsgroup) + qnsid = '%s.%s' % (nsgroup, nsid) + nsd = locate_ns(nshost) + try: + nsd.unregister(qnsid) + except errors.NamingError: + # make sure our namespace group exists + try: + nsd.createGroup(nsgroup) + except errors.NamingError: + pass + nsd.register(qnsid, _PYRO_OBJS[qnsid]) def ns_get_proxy(nsid, defaultnsgroup=_MARKER, nshost=None): nsgroup, nsid = ns_group_and_id(nsid, defaultnsgroup) |