def reload_snapshot(self): """ Reload snapshot. """ self._rwlock = RWLock() try: self._dispatch_snapshot = self._get_dispatch_snapshot_callback() except Exception as e: raise SnapshotManagerException(e)
def __init__(self, dispatch_schema_manager, get_dispatch_snapshot_callback, update_dispatch_snapshot_callback): """ @dispatch_schema_manager: dispatch schema manager. @get_dispatch_snapshot_callback: callback for geting dispatch snapshot. @update_dispatch_snapshot_callback: callback for updating dispatch snapshot. """ self._dispatch_schema_manager = dispatch_schema_manager self._get_dispatch_snapshot_callback = get_dispatch_snapshot_callback self._update_dispatch_snapshot_callback = \ update_dispatch_snapshot_callback self._rwlock = RWLock() try: self._dispatch_snapshot = self._get_dispatch_snapshot_callback() except Exception as e: raise SnapshotManagerException(e)
def __init__(self, server_uri, session_key, dispatch_schema, get_forwarders_snapshot_callback, update_forwarders_snapshot_callback, get_dispatch_snapshot_callback, update_dispatch_snapshot_callback, ucc_server_id): """ @server_uri: local server uri. @session_key: local session key. @dispatch_schema: dispatch schema. @get_forwarders_snapshot_callback: callback for geting forwarders snapshot. @update_forwarders_snapshot_callback: callback for updating forwarders snapshot. @get_dispatch_snapshot_callback: callback for geting dispatch snapshot. @update_dispatch_snapshot_callback: callback for updating dispatch snapshot. @ucc_server_id: ucc server id. """ assert server_uri, "server_uri is None." assert session_key, "session_key is None." assert dispatch_schema, "dispatch_schema is None." assert get_forwarders_snapshot_callback, \ "get_forwarders_snapshot_callback is None." assert update_forwarders_snapshot_callback, \ "update_forwarders_snapshot_callback is None." assert get_dispatch_snapshot_callback, \ "get_dispatch_snapshot_callback is None." assert update_dispatch_snapshot_callback, \ "update_dispatch_snapshot_callback is None." assert ucc_server_id, "ucc_server_id is None." self._server_uri = server_uri self._session_key = session_key self._dispatch_schema_manager = DispatchSchemaManager(dispatch_schema) self._dispatch_snapshot_manager = DispatchSnapshotManager( self._dispatch_schema_manager, get_dispatch_snapshot_callback, update_dispatch_snapshot_callback) self._get_forwarders_snapshot_callback = \ get_forwarders_snapshot_callback self._update_forwarders_snapshot_callback = \ update_forwarders_snapshot_callback self._forwarders_snapshot = None self._forwarders_snapshot_lock = RWLock() self._threadpool_executor = futures.ThreadPoolExecutor(cpu_count()) self._ucc_server_id = ucc_server_id # Current dispatch settings self._settings = None self._settings_lock = RWLock() # Forwarders available self._available_forwarderloads = None self._unavailable_forwarderloads = None self._forwarders_lock = RWLock()