def watch_path(self, path, watch_type, container): ''' Watch the specified path as specified type ''' if watch_type == zk.CHANGED_EVENT_DEF: watch_matchers = (ZooKeeperWatcherEvent.createMatcher(None, None, self.protocol, zk.CHANGED_EVENT_DEF, None, path), ZooKeeperWatcherEvent.createMatcher(None, None, self.protocol, zk.DELETED_EVENT_DEF, None, path)) else: watch_matchers = (ZooKeeperWatcherEvent.createMatcher(None, None, self.protocol, watch_type, None, path),) # If the session expires, raise exception and exit session_state = ZooKeeperSessionStateChanged.createMatcher(ZooKeeperSessionStateChanged.EXPIRED, self, self.session_id) auth_failed = ZooKeeperSessionStateChanged.createMatcher(ZooKeeperSessionStateChanged.AUTHFAILED, self, self.session_id) # If the watchers are restored, restore the matchers restore_matcher = ZooKeeperRestoreWatches.createMatcher(self, self.session_id, True) while True: yield (session_state, auth_failed, restore_matcher) + watch_matchers if container.matcher is session_state or container.matcher is auth_failed: raise ZooKeeperSessionUnavailable(container.event.state) elif container.matcher is restore_matcher: ev = container.event ev.restore_watches[{zk.CHANGED_EVENT_DEF : 0, zk.CREATED_EVENT_DEF : 1, zk.CHILD_EVENT_DEF : 2}[watch_type]].add(path) else: watcher_event = container.event.message if watcher_event.path: watcher_event.path = self.unchroot_path(watcher_event.path) container.retvalue = watcher_event break
def watcher(self): watcher = ZooKeeperWatcherEvent.createMatcher(connection = self.client) while True: yield (watcher,) print('WatcherEvent: %r' % (dump(self.apiroutine.event.message),))
async def watcher(self): watcher = ZooKeeperWatcherEvent.createMatcher(connection=self.client) while True: ev = await watcher print('WatcherEvent: %r' % (dump(ev.message), ))
def watcher(self): watcher = ZooKeeperWatcherEvent.createMatcher() while True: yield (watcher,) print('WatcherEvent: %r' % (dump(self.apiroutine.event.message),))