def get_channel(self, channel_name): # TODO: Change to reader-writer lock. with self.channel_map_lock: try: return self.channel_map[channel_name] except KeyError: raise ObjectNotFound(channel_name)
def unregister_plugin(self, url): with self.apps_lock: try: app = self.apps_by_url.pop(url) self.apps_by_token.pop(app.app_token) except KeyError: raise ObjectNotFound(url)
def remove_channel(self, channel_name): with self.channel_map_lock: try: channel = self.channel_map.pop(channel_name) except KeyError: raise ObjectNotFound(channel_name) channel.disconnect() return True
def get_app_info(self, app_token): with self.apps_lock: try: app = self.apps_by_token[app_token] except KeyError: raise ObjectNotFound(app_token) return { "app_name": app.name, "app_type": "plugin" if isinstance(app, Plugin) else "system", "app_url": app.url, }
def update_channel_schema(self, channel_name, request_schema, response_schema): with self.channel_map_lock: try: channel_info = self.channel_map[channel_name].channel_info except KeyError: raise ObjectNotFound(channel_name) # TODO: This might need to be protected by a lock. channel_info.request_schema = request_schema channel_info.response_schema = response_schema logger.info(channel_info.request_schema) return True
def get_plugin_by_id(plugin_id): try: return PluginData.get(PluginData.app_id == plugin_id) except DoesNotExist: raise ObjectNotFound(plugin_id)
def get_plugin_by_url(self, plugin_url): plugin_id = url_to_plugin_id(plugin_url) try: return self.plugin_states[plugin_id] except KeyError: raise ObjectNotFound(plugin_id)
def get_app_by_url(self, url): with self.apps_lock: try: return self.apps_by_url[url] except KeyError: raise ObjectNotFound(url)
def find_rpc(self, url, name): try: return self.rpc_registry[(url, name)] except KeyError: raise ObjectNotFound("RPC not found: " + rpc_name)
def exception(self): raise ObjectNotFound("blah")