本文整理汇总了Python中pyon.ion.event.EventSubscriber.deactivate方法的典型用法代码示例。如果您正苦于以下问题:Python EventSubscriber.deactivate方法的具体用法?Python EventSubscriber.deactivate怎么用?Python EventSubscriber.deactivate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.ion.event.EventSubscriber
的用法示例。
在下文中一共展示了EventSubscriber.deactivate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Directory
# 需要导入模块: from pyon.ion.event import EventSubscriber [as 别名]
# 或者: from pyon.ion.event.EventSubscriber import deactivate [as 别名]
class Directory(object):
"""
Frontent to a directory functionality backed by the resource registry to provide a directory lookup mechanism.
Terms:
directory: instance of a Directory, representing entries within one Org. A tree of entries.
path: parent+key (= qualified name of an entry). All paths start with '/'
entry: node in the directory tree with a name (key) and parent path, holding arbitrary attributes
key: local name of an entry
"""
def __init__(self, orgname=None, datastore_manager=None, events_enabled=False, container=None):
self.container = container or bootstrap.container_instance
# Get an instance of datastore configured as directory.
datastore_manager = datastore_manager or self.container.datastore_manager
self.dir_store = datastore_manager.get_datastore(DataStore.DS_DIRECTORY)
self.orgname = orgname or CFG.system.root_org
self.is_root = (self.orgname == CFG.system.root_org)
self.events_enabled = events_enabled
self.event_pub = None
self.event_sub = None
def start(self):
# Create directory root entry (for current org) if not existing
if CFG.system.auto_bootstrap:
root_de = self.register("/", "DIR", sys_name=bootstrap.get_sys_name())
if root_de is None:
# We created this directory just now
pass
if self.events_enabled:
# init change event publisher
self.event_pub = EventPublisher()
# Register to receive directory changes
self.event_sub = EventSubscriber(event_type="ContainerConfigModifiedEvent",
origin="Directory",
callback=self.receive_directory_change_event)
def stop(self):
self.close()
def close(self):
"""
Close directory and all resources including datastore and event listener.
"""
if self.event_sub:
self.event_sub.deactivate()
self.dir_store.close()
def _get_path(self, parent, key):
"""
Returns the qualified directory path for a directory entry.
"""
if parent == "/":
return parent + key
elif parent.startswith("/"):
return parent + "/" + key
else:
raise BadRequest("Illegal parent: %s" % parent)
def _get_key(self, path):
"""
Returns the key from a qualified directory path
"""
parent, key = path.rsplit("/", 1)
return key
def _create_dir_entry(self, parent, key, orgname=None, ts=None, attributes=None):
"""
Standard way to create a DirEntry object (without persisting it)
"""
orgname = orgname or self.orgname
ts = ts or get_ion_ts()
attributes = attributes if attributes is not None else {}
parent = parent or "/"
de = DirEntry(org=orgname, parent=parent, key=key, attributes=attributes, ts_created=ts, ts_updated=ts)
return de
def _read_by_path(self, path, orgname=None):
"""
Given a qualified path, find entry in directory and return DirEntry
object or None if not found.
A side effect is to clean any but the most recent entries found for this path.
"""
if path is None:
raise BadRequest("Illegal arguments")
orgname = orgname or self.orgname
parent, key = path.rsplit("/", 1)
parent = parent or "/"
find_key = [orgname, key, parent]
view_res = self.dir_store.find_by_view('directory', 'by_key', key=find_key, id_only=True, convert_doc=True)
match = [doc for docid, index, doc in view_res]
if len(match) > 1:
log.warn("More than one directory entry found for key %s" % path)
recent_match = self._cleanup_outdated_entries(match, "path=%s" % path)
return recent_match
#.........这里部分代码省略.........