Search in sources :

Example 11 with ServerCQ

use of org.apache.geode.cache.query.internal.cq.ServerCQ in project geode by apache.

the class CacheClientNotifier method singletonNotifyClients.

private void singletonNotifyClients(InternalCacheEvent event, ClientUpdateMessage cmsg) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    final boolean isTraceEnabled = logger.isTraceEnabled();
    FilterInfo filterInfo = event.getLocalFilterInfo();
    FilterProfile regionProfile = ((LocalRegion) event.getRegion()).getFilterProfile();
    if (filterInfo != null) {
        // if the routing was made using an old profile we need to recompute it
        if (isTraceEnabled) {
            logger.trace("Event isOriginRemote={}", event.isOriginRemote());
        }
    }
    if ((filterInfo == null || (filterInfo.getCQs() == null && filterInfo.getInterestedClients() == null && filterInfo.getInterestedClientsInv() == null))) {
        return;
    }
    long startTime = this.statistics.startTime();
    ClientUpdateMessageImpl clientMessage;
    if (cmsg == null) {
        clientMessage = constructClientMessage(event);
    } else {
        clientMessage = (ClientUpdateMessageImpl) cmsg;
    }
    if (clientMessage == null) {
        return;
    }
    // Holds the clientIds to which filter message needs to be sent.
    Set<ClientProxyMembershipID> filterClients = new HashSet();
    // Add CQ info.
    if (filterInfo.getCQs() != null) {
        for (Map.Entry<Long, Integer> e : filterInfo.getCQs().entrySet()) {
            Long cqID = e.getKey();
            String cqName = regionProfile.getRealCqID(cqID);
            if (cqName == null) {
                continue;
            }
            ServerCQ cq = regionProfile.getCq(cqName);
            if (cq != null) {
                ClientProxyMembershipID id = cq.getClientProxyId();
                filterClients.add(id);
                if (isDebugEnabled) {
                    logger.debug("Adding cq routing info to message for id: {} and cq: {}", id, cqName);
                }
                clientMessage.addClientCq(id, cq.getName(), e.getValue());
            }
        }
    }
    // Add interestList info.
    if (filterInfo.getInterestedClientsInv() != null) {
        Set<Object> rawIDs = regionProfile.getRealClientIDs(filterInfo.getInterestedClientsInv());
        Set<ClientProxyMembershipID> ids = getProxyIDs(rawIDs, true);
        if (ids.remove(event.getContext())) {
            // don't send to member of origin
            CacheClientProxy ccp = getClientProxy(event.getContext());
            if (ccp != null) {
                ccp.getStatistics().incMessagesNotQueuedOriginator();
            }
        }
        if (!ids.isEmpty()) {
            if (isTraceEnabled) {
                logger.trace("adding invalidation routing to message for {}", ids);
            }
            clientMessage.addClientInterestList(ids, false);
            filterClients.addAll(ids);
        }
    }
    if (filterInfo.getInterestedClients() != null) {
        Set<Object> rawIDs = regionProfile.getRealClientIDs(filterInfo.getInterestedClients());
        Set<ClientProxyMembershipID> ids = getProxyIDs(rawIDs, true);
        if (ids.remove(event.getContext())) {
            // don't send to member of origin
            CacheClientProxy ccp = getClientProxy(event.getContext());
            if (ccp != null) {
                ccp.getStatistics().incMessagesNotQueuedOriginator();
            }
        }
        if (!ids.isEmpty()) {
            if (isTraceEnabled) {
                logger.trace("adding routing to message for {}", ids);
            }
            clientMessage.addClientInterestList(ids, true);
            filterClients.addAll(ids);
        }
    }
    Conflatable conflatable = null;
    if (clientMessage instanceof ClientTombstoneMessage) {
        // bug #46832 - HAEventWrapper deserialization can't handle subclasses
        // of ClientUpdateMessageImpl, so don't wrap them
        conflatable = clientMessage;
        // Remove clients older than 70 from the filterClients if the message is
        // ClientTombstoneMessage. Fix for #46591.
        Object[] objects = filterClients.toArray();
        for (Object id : objects) {
            CacheClientProxy ccp = getClientProxy((ClientProxyMembershipID) id, true);
            if (ccp != null && ccp.getVersion().compareTo(Version.GFE_70) < 0) {
                filterClients.remove(id);
            }
        }
    } else {
        HAEventWrapper wrapper = new HAEventWrapper(clientMessage);
        // Set the putInProgress flag to true before starting the put on proxy's
        // HA queues. Nowhere else, this flag is being set to true.
        wrapper.setPutInProgress(true);
        conflatable = wrapper;
    }
    singletonRouteClientMessage(conflatable, filterClients);
    this.statistics.endEvent(startTime);
    // destroyed are removed after the event is placed in clients HAQueue.
    if (filterInfo.filterProcessedLocally) {
        removeDestroyTokensFromCqResultKeys(event, filterInfo);
    }
}
Also used : LocalRegion(org.apache.geode.internal.cache.LocalRegion) FilterProfile(org.apache.geode.internal.cache.FilterProfile) ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ) Conflatable(org.apache.geode.internal.cache.Conflatable) FilterInfo(org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HAContainerMap(org.apache.geode.internal.cache.ha.HAContainerMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet)

Aggregations

ServerCQ (org.apache.geode.cache.query.internal.cq.ServerCQ)11 Map (java.util.Map)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 CancelException (org.apache.geode.CancelException)3 CqService (org.apache.geode.cache.query.internal.cq.CqService)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)3 Iterator (java.util.Iterator)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 CqStateImpl (org.apache.geode.cache.query.internal.CqStateImpl)2 FilterProfile (org.apache.geode.internal.cache.FilterProfile)2 FilterInfo (org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 HAContainerMap (org.apache.geode.internal.cache.ha.HAContainerMap)2 CopyOnWriteHashMap (org.apache.geode.internal.util.concurrent.CopyOnWriteHashMap)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Region (org.apache.geode.cache.Region)1