def _processUpdateFromBackend(self, payloadEnvelope: PayloadEnvelope):

        tupleSelector: TupleSelector = payloadEnvelope.filt["tupleSelector"]

        if not self._hasTupleSelector(tupleSelector):
            return

        cache, requiredUpdate = self._updateCache(payloadEnvelope)
        if not requiredUpdate:
            return

        # Get / update the list of observing UUIDs
        observingUuids = cache.vortexUuids & set(VortexFactory.getRemoteVortexUuids())

        if not observingUuids:
            return

        # Create the vortexMsg
        vortexMsg = payloadEnvelope.toVortexMsg()

        # Send the vortex messages
        for vortexUuid in observingUuids:
            d = VortexFactory.sendVortexMsg(vortexMsgs=vortexMsg,
                                            destVortexUuid=vortexUuid)
            d.addErrback(vortexLogFailure, logger, consumeError=True)
    def _notifyOfTupleUpdateInMainOne(self, tupleSelector: TupleSelector):
        tsStr = tupleSelector.toJsonStr()
        if tsStr not in self._observerDataByTupleSelector:
            return

        # Filter out the offline observables
        onlineUuids = set(VortexFactory.getRemoteVortexUuids())
        observers = self._observerDataByTupleSelector[tsStr].observers
        for od in list(observers):
            if od.vortexUuid not in onlineUuids:
                observers.remove(od)

        # Get / update the list of observing UUIDs
        if not observers:
            del self._observerDataByTupleSelector[tsStr]
            return

        # Create the vortexMsg
        filt = dict(tupleSelector=tupleSelector)
        filt.update(self._filt)
        vortexMsg = yield self._createVortexMsg(filt, tupleSelector)

        # We can have multiple Observable clients on the one vortex, so make sure
        # we only send one message for these.
        destVortexUuids = set([od.vortexUuid for od in observers])

        # Send the vortex messages
        for destVortexUuid in destVortexUuids:
            d = VortexFactory.sendVortexMsg(vortexMsgs=vortexMsg,
                                            destVortexUuid=destVortexUuid)
            d.addErrback(vortexLogFailure, logger)
Esempio n. 3
0
    def _filterOutOfflineVortexes(self):
        # TODO, Change this to observe offline vortexes
        # This depends on the VortexFactory offline observable implementation.
        # Which is incomplete at this point :-|

        vortexUuids = set(VortexFactory.getRemoteVortexUuids())
        vortexUuidsToRemove = set(
            self._observedGridKeysByVortexUuid) - vortexUuids

        if not vortexUuidsToRemove:
            return

        for vortexUuid in vortexUuidsToRemove:
            del self._observedGridKeysByVortexUuid[vortexUuid]

        self._rebuildStructs()
Esempio n. 4
0
    def __cacheCheck(self):
        currentVortexUuids = set(VortexFactory.getRemoteVortexUuids())

        for ts, cache in list(self.__cache.items()):
            cache.vortexUuids = cache.vortexUuids & currentVortexUuids

            if cache.vortexUuids or cache.subject.observers:
                cache.resetTearDown()

            elif cache.isReadyForTearDown():
                logger.debug("Cleaning cache for %s", cache.tupleSelector)
                self._sendUnsubscribeToServer(cache.tupleSelector)
                del self.__cache[ts]

            else:
                cache.markForTearDown()