def _parseSubscriptionMsg(self, channel, msg): schema_name = msg.schema definition = channel.definedSchemas.get(schema_name) assert definition is not None, "can't subscribe to a schema we don't know about!" assert msg.typename is not None typename = msg.typename assert typename in definition, ( "Can't subscribe to a type we didn't define in the schema: %s not in %s" % (typename, list(definition))) typedef = definition[typename] if msg.fieldname_and_value is None: field, val = " exists", indexValueFor(bool, True) else: field, val = msg.fieldname_and_value if field == '_identity': # single value identities are encoded as integers identities = set([deserialize(ObjectBase, val)._identity]) else: fieldId = self._currentTypeMap().lookupOrAdd( schema_name, typename, field) identities = set( self._kvstore.getSetMembers( IndexId(fieldId=fieldId, indexValue=val))) return typedef, identities
def subscribeToObjects(self, objects): for t in objects: self.addSchema(type(t).__schema__) self.subscribeMultiple([ (type(t).__schema__.name, type(t).__qualname__, ("_identity", indexValueFor(type(t), t, self.serializationContext)), False) for t in objects ])
def _dropConnectionEntry(self, entry): identity = entry._identity fieldId = self._currentTypeMap().fieldIdFor("core", "Connection", " exists") exists_key = ObjectFieldId(objId=identity, fieldId=fieldId) exists_index = IndexId(fieldId=fieldId, indexValue=indexValueFor(bool, True)) self._handleNewTransaction(None, {exists_key: None}, {}, {exists_index: set([identity])}, [], [], self._cur_transaction_num)
def _removeOldDeadConnections(self): fieldId = self._currentTypeMap().fieldIdFor("core", "Connection", " exists") exists_index = IndexId(fieldId=fieldId, indexValue=indexValueFor(bool, True)) oldIds = self._kvstore.getSetMembers(exists_index) if oldIds: self._kvstore.setSeveral( { ObjectFieldId(objId=identity, fieldId=fieldId): None for identity in oldIds }, {}, {exists_index: set(oldIds)})
def _createConnectionEntry(self): identity = self.identityProducer.createIdentity() fieldId = self._currentTypeMap().fieldIdFor("core", "Connection", " exists") exists_key = ObjectFieldId(objId=identity, fieldId=fieldId) exists_index = IndexId(fieldId=fieldId, indexValue=indexValueFor(bool, True)) identityRoot = self.allocateNewIdentityRoot() self._handleNewTransaction(None, {exists_key: serialize(bool, True)}, {exists_index: set([identity])}, {}, [], [], self._cur_transaction_num) return core_schema.Connection.fromIdentity(identity), identityRoot
def subscribeToIndex(self, t, block=True, lazySubscription=None, **kwarg): self.addSchema(t.__schema__) toSubscribe = [] for fieldname, fieldvalue in kwarg.items(): indexVal = indexValueFor( t.__schema__.indexType(t.__qualname__, fieldname), fieldvalue, self.serializationContext ) toSubscribe.append(( t.__schema__.name, t.__qualname__, (fieldname, indexVal), self._lazinessForType(t, lazySubscription) )) return self.subscribeMultiple(toSubscribe, block=block)