Search in sources :

Example 26 with CqService

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

the class FilterProfile method getLocalFilterRoutingForPutAllOp.

/**
   * computes FilterRoutingInfo objects for each of the given events
   */
public void getLocalFilterRoutingForPutAllOp(DistributedPutAllOperation dpao, DistributedPutAllOperation.PutAllEntryData[] putAllData) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (this.region != null && this.localProfile.hasCacheServer) {
        Set clientsInv = null;
        Set clients = null;
        int size = putAllData.length;
        CqService cqService = getCqService(dpao.getRegion());
        boolean doCQs = cqService.isRunning() && this.region != null;
        for (int idx = 0; idx < size; idx++) {
            PutAllEntryData pEntry = putAllData[idx];
            if (pEntry != null) {
                @Unretained final EntryEventImpl ev = dpao.getEventForPosition(idx);
                FilterRoutingInfo fri = pEntry.filterRouting;
                FilterInfo fi = null;
                if (fri != null) {
                    fi = fri.getLocalFilterInfo();
                }
                if (isDebugEnabled) {
                    logger.debug("Finding locally interested clients for {}", ev);
                }
                if (doCQs) {
                    if (fri == null) {
                        fri = new FilterRoutingInfo();
                    }
                    fillInCQRoutingInfo(ev, true, NO_PROFILES, fri);
                    fi = fri.getLocalFilterInfo();
                }
                if (this.allKeyClientsInv != null || this.keysOfInterestInv != null || this.patternsOfInterestInv != null || this.filtersOfInterestInv != null) {
                    clientsInv = this.getInterestedClients(ev, this.allKeyClientsInv, this.keysOfInterestInv, this.patternsOfInterestInv, this.filtersOfInterestInv);
                }
                if (this.allKeyClients != null || this.keysOfInterest != null || this.patternsOfInterest != null || this.filtersOfInterest != null) {
                    clients = this.getInterestedClients(ev, this.allKeyClients, this.keysOfInterest, this.patternsOfInterest, this.filtersOfInterest);
                }
                if (clients != null || clientsInv != null) {
                    if (fi == null) {
                        fi = new FilterInfo();
                    // no need to create or update a FilterRoutingInfo at this time
                    }
                    fi.setInterestedClients(clients);
                    fi.setInterestedClientsInv(clientsInv);
                }
                ev.setLocalFilterInfo(fi);
            }
        }
    }
}
Also used : Set(java.util.Set) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) CqService(org.apache.geode.cache.query.internal.cq.CqService) PutAllEntryData(org.apache.geode.internal.cache.DistributedPutAllOperation.PutAllEntryData) Unretained(org.apache.geode.internal.offheap.annotations.Unretained) FilterInfo(org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo)

Example 27 with CqService

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

the class DistributedPutAllOperation method getEventForPosition.

@Unretained
public EntryEventImpl getEventForPosition(int position) {
    PutAllEntryData entry = this.putAllData[position];
    if (entry == null) {
        return null;
    }
    if (entry.event != null) {
        return entry.event;
    }
    LocalRegion region = (LocalRegion) this.event.getRegion();
    @Retained EntryEventImpl ev = EntryEventImpl.create(region, entry.getOp(), entry.getKey(), null, /* value */
    this.event.getCallbackArgument(), false, /* originRemote */
    this.event.getDistributedMember(), this.event.isGenerateCallbacks(), entry.getEventID());
    boolean returnedEv = false;
    try {
        ev.setPossibleDuplicate(entry.isPossibleDuplicate());
        if (entry.versionTag != null && region.concurrencyChecksEnabled) {
            VersionSource id = entry.versionTag.getMemberID();
            if (id != null) {
                entry.versionTag.setMemberID(ev.getRegion().getVersionVector().getCanonicalId(id));
            }
            ev.setVersionTag(entry.versionTag);
        }
        entry.event = ev;
        returnedEv = true;
        if (entry.getValue() == null && ev.getRegion().getAttributes().getDataPolicy() == DataPolicy.NORMAL) {
            ev.setLocalInvalid(true);
        }
        ev.setNewValue(entry.getValue());
        ev.setOldValue(entry.getOldValue());
        CqService cqService = region.getCache().getCqService();
        if (cqService.isRunning() && !entry.getOp().isCreate() && !ev.hasOldValue()) {
            ev.setOldValueForQueryProcessing();
        }
        ev.setInvokePRCallbacks(!entry.isNotifyOnly());
        if (getBaseEvent().getContext() != null) {
            ev.setContext(getBaseEvent().getContext());
        }
        ev.callbacksInvoked(entry.isCallbacksInvoked());
        ev.setTailKey(entry.getTailKey());
        return ev;
    } finally {
        if (!returnedEv) {
            ev.release();
        }
    }
}
Also used : Retained(org.apache.geode.internal.offheap.annotations.Retained) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) CqService(org.apache.geode.cache.query.internal.cq.CqService) Unretained(org.apache.geode.internal.offheap.annotations.Unretained)

Example 28 with CqService

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

the class DistributedRemoveAllOperation method getEventForPosition.

@Unretained
public EntryEventImpl getEventForPosition(int position) {
    RemoveAllEntryData entry = this.removeAllData[position];
    if (entry == null) {
        return null;
    }
    if (entry.event != null) {
        return entry.event;
    }
    LocalRegion region = (LocalRegion) this.event.getRegion();
    // owned by this.removeAllData once entry.event = ev is done
    @Retained EntryEventImpl ev = EntryEventImpl.create(region, entry.getOp(), entry.getKey(), null, /* value */
    this.event.getCallbackArgument(), false, /* originRemote */
    this.event.getDistributedMember(), this.event.isGenerateCallbacks(), entry.getEventID());
    boolean returnedEv = false;
    try {
        ev.setPossibleDuplicate(entry.isPossibleDuplicate());
        ev.setIsRedestroyedEntry(entry.getRedestroyedEntry());
        if (entry.versionTag != null && region.concurrencyChecksEnabled) {
            VersionSource id = entry.versionTag.getMemberID();
            if (id != null) {
                entry.versionTag.setMemberID(ev.getRegion().getVersionVector().getCanonicalId(id));
            }
            ev.setVersionTag(entry.versionTag);
        }
        entry.event = ev;
        returnedEv = true;
        ev.setOldValue(entry.getOldValue());
        CqService cqService = region.getCache().getCqService();
        if (cqService.isRunning() && !entry.getOp().isCreate() && !ev.hasOldValue()) {
            ev.setOldValueForQueryProcessing();
        }
        ev.setInvokePRCallbacks(!entry.isNotifyOnly());
        if (getBaseEvent().getContext() != null) {
            ev.setContext(getBaseEvent().getContext());
        }
        ev.callbacksInvoked(entry.isCallbacksInvoked());
        ev.setTailKey(entry.getTailKey());
        return ev;
    } finally {
        if (!returnedEv) {
            ev.release();
        }
    }
}
Also used : Retained(org.apache.geode.internal.offheap.annotations.Retained) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) CqService(org.apache.geode.cache.query.internal.cq.CqService) Unretained(org.apache.geode.internal.offheap.annotations.Unretained)

Example 29 with CqService

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

the class CacheClientUpdater method processCqs.

private int processCqs(Message clientMessage, int startMessagePart, int numCqParts, int messageType, Object key, Object value, byte[] delta, EventID eventId) {
    HashMap cqs = new HashMap();
    final boolean isDebugEnabled = logger.isDebugEnabled();
    for (int cqCnt = 0; cqCnt < numCqParts; ) {
        StringBuilder sb = null;
        if (isDebugEnabled) {
            sb = new StringBuilder(100);
            sb.append("found these queries: ");
        }
        try {
            // Get CQ Name.
            Part cqNamePart = clientMessage.getPart(startMessagePart + cqCnt++);
            // Get CQ Op.
            Part cqOpPart = clientMessage.getPart(startMessagePart + cqCnt++);
            cqs.put(cqNamePart.getString(), cqOpPart.getInt());
            if (sb != null) {
                sb.append(cqNamePart.getString()).append(" op=").append(cqOpPart.getInt()).append("  ");
            }
        } catch (Exception ignore) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientUpdater_ERROR_WHILE_PROCESSING_THE_CQ_MESSAGE_PROBLEM_WITH_READING_MESSAGE_FOR_CQ_0, cqCnt));
        }
        if (isDebugEnabled) {
            logger.debug(sb);
        }
    }
    CqService cqService = this.cache.getCqService();
    try {
        cqService.dispatchCqListeners(cqs, messageType, key, value, delta, this.qManager, eventId);
    } catch (Exception ex) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientUpdater_FAILED_TO_INVOKE_CQ_DISPATCHER_ERROR___0, ex.getMessage()));
        if (isDebugEnabled) {
            logger.debug("Failed to invoke CQ Dispatcher.", ex);
        }
    }
    return startMessagePart + numCqParts;
}
Also used : HashMap(java.util.HashMap) CqService(org.apache.geode.cache.query.internal.cq.CqService) Endpoint(org.apache.geode.cache.client.internal.Endpoint) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) SSLException(javax.net.ssl.SSLException) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) InterruptedIOException(java.io.InterruptedIOException) SocketException(java.net.SocketException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException)

Example 30 with CqService

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

the class QueueManagerImpl method cqsConnected.

private void cqsConnected() {
    InternalCache cache = GemFireCacheImpl.getInstance();
    if (cache != null) {
        CqService cqService = cache.getCqService();
        // Primary queue was found, alert the affected cqs if necessary
        cqService.cqsConnected(pool);
    }
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) CqService(org.apache.geode.cache.query.internal.cq.CqService)

Aggregations

CqService (org.apache.geode.cache.query.internal.cq.CqService)36 InternalCqQuery (org.apache.geode.cache.query.internal.cq.InternalCqQuery)15 CacheException (org.apache.geode.cache.CacheException)11 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)11 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)10 IOException (java.io.IOException)9 Collection (java.util.Collection)9 Set (java.util.Set)8 CqException (org.apache.geode.cache.query.CqException)8 HashSet (java.util.HashSet)7 Region (org.apache.geode.cache.Region)7 ServerCQImpl (org.apache.geode.cache.query.internal.cq.ServerCQImpl)7 Host (org.apache.geode.test.dunit.Host)7 VM (org.apache.geode.test.dunit.VM)7 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)7 Test (org.junit.Test)7 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)6 Portfolio (org.apache.geode.cache.query.data.Portfolio)5 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)5 CacheServerStats (org.apache.geode.internal.cache.tier.sockets.CacheServerStats)5