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);
}
}
Aggregations