def doWork(self, shouldStop): self._logger.info("Configuring ActiveWebService") with self.db.view() as view: config = Configuration.lookupAny(service=self.serviceObject) assert config, "No configuration available." self._logger.setLevel(config.log_level) host, port = config.hostname, config.port login_config = config.login_plugin codebase = login_config.codebase if codebase is None: ser_ctx = TypedPythonCodebase.coreSerializationContext() else: ser_ctx = codebase.instantiate().serializationContext view.setSerializationContext(ser_ctx) self.login_plugin = login_config.login_plugin_factory( self.db, login_config.auth_plugins, login_config.config) # register `load_user` method with login_manager self.login_plugin.load_user = self.login_manager.user_loader( self.login_plugin.load_user) self.authorized_groups_text = self.login_plugin.authorized_groups_text self.login_plugin.init_app(self.app) self._logger.info("ActiveWebService listening on %s:%s", host, port) server = pywsgi.WSGIServer((host, port), self.app, handler_class=WebSocketHandler) server.serve_forever()
def __init__(self, channel, connectionMetadata=None): self._channel = channel self._transaction_callbacks = {} self._connectionMetadata = connectionMetadata or {} self._lock = threading.RLock() # transaction of what's in the KV store self._cur_transaction_num = 0 self.serializationContext = TypedPythonCodebase.coreSerializationContext().withoutCompression() # a datastructure that keeps track of all the different versions of the objects # we have mapped in. self._connection_state = DatabaseConnectionState() self._connection_state.setSerializationContext(self.serializationContext) self._connection_state.setTriggerLazyLoad(self.loadLazyObject) self._lazy_object_read_blocks = {} self.initialized = threading.Event() self.disconnected = threading.Event() # for each schema name we've sent, an event that's triggered # when the server has acknowledged the schema and given us a definition self._schema_response_events = {} self._fields_to_field_ids = Dict(FieldDefinition, int)() self._field_id_to_schema_and_typename = {} self._field_id_to_field_def = Dict(int, FieldDefinition)() self.connectionObject = None # transaction handlers. These must be nonblocking since we call them under lock self._onTransactionHandlers = set() self._flushEvents = {} # set(schema) self._schemas = set() self._messages_received = 0 self._pendingSubscriptions = {} # from (schema, typename, fieldname_and_val) -> {'values', 'index_values', 'identities'} # where (fieldname_and_val) is OneOf(None, (str, IndexValue)) self._subscription_buildup = {} self._channel.setServerToClientHandler(self._onMessage) self._flushIx = 0 self._largeSubscriptionHeartbeatDelay = 0 self._logger = logging.getLogger(__name__) self._auth_token = None self._max_tid_by_schema = {} self._max_tid_by_schema_and_type = {}
def __init__(self, channel): self._channel = channel self._transaction_callbacks = {} self._lock = threading.Lock() # transaction of what's in the KV store self._cur_transaction_num = 0 # a datastructure that keeps track of all the different versions of the objects # we have mapped in. self._versioned_data = ManyVersionedObjects() # a map from lazy object id to (schema, typename) self._lazy_objects = {} self._lazy_object_read_blocks = {} self.initialized = threading.Event() self.disconnected = threading.Event() self.connectionObject = None # transaction handlers. These must be nonblocking since we call them under lock self._onTransactionHandlers = [] self._flushEvents = {} # Map: schema.name -> schema self._schemas = {} self._messages_received = 0 self._pendingSubscriptions = {} #if we have object-level subscriptions to a particular type (e.g. not everything) #then, this is from (schema, typename) -> {object_id -> transaction_id} so that #we can tell when the subscription should become valid. Subscriptions are permanent #otherwise, if we're subscribed, it's 'Everything' self._schema_and_typename_to_subscription_set = {} #from (schema,typename,field_val) -> {'values', 'index_values', 'identities'} self._subscription_buildup = {} self._channel.setServerToClientHandler(self._onMessage) self._flushIx = 0 self._largeSubscriptionHeartbeatDelay = 0 self.serializationContext = TypedPythonCodebase.coreSerializationContext( ) self._logger = logging.getLogger(__name__)
def __init__(self, kvstore, auth_token): self._kvstore = kvstore self._auth_token = auth_token self.serializationContext = TypedPythonCodebase.coreSerializationContext( ).withoutCompression() self._lock = threading.RLock() self.verbose = False self._gc_interval = DEFAULT_GC_INTERVAL self._typeMap = None # InMemoryChannel or ServerToClientProtocol -> ConnectedChannel self._clientChannels = {} # id of the next transaction self._cur_transaction_num = 0 # for each key, the last version number we committed self._version_numbers = {} self._version_numbers_timestamps = {} # _field_id to set(subscribed channel) self._field_id_to_channel = {} # index-stringname to set(subscribed channel) self._index_to_channel = Dict(IndexId, object)() # for each individually subscribed ID, a set of channels self._id_to_channel = {} self.longTransactionThreshold = 1.0 self.logFrequency = 10.0 self.MAX_NORMAL_TO_SEND_SYNCHRONOUSLY = 1000 self.MAX_LAZY_TO_SEND_SYNCHRONOUSLY = 10000 self._transactions = 0 self._keys_set = 0 self._index_values_updated = 0 self._subscriptions_written = 0 self._subscriptionResponseThread = None self._shouldStop = threading.Event() # a queue of queue-subscription messages. we have to handle # these on another thread because they can be quite large, and we don't want # to prevent message processing on the main thread. self._subscriptionQueue = queue.Queue() # if we're building a subscription up, all the objects that have changed while our # lock was released. self._pendingSubscriptionRecheck = None # fault injector to test this thing self._subscriptionBackgroundThreadCallback = None self._lazyLoadCallback = None self._last_garbage_collect_timestamp = None self.identityProducer = IdentityProducer( self.allocateNewIdentityRoot()) self._logger = logging.getLogger(__name__) self._removeOldDeadConnections()