Search in sources :

Example 1 with HAEventWrapper

use of org.apache.geode.internal.cache.tier.sockets.HAEventWrapper in project geode by apache.

the class HARegionQueue method maintainCqStats.

private void maintainCqStats(Object event, long incrementAmount) {
    CqService cqService = region.getGemFireCache().getCqService();
    if (cqService != null) {
        try {
            if (event instanceof HAEventWrapper) {
                HAEventWrapper hw = (HAEventWrapper) event;
                if (hw.getClientUpdateMessage() != null) {
                    event = hw.getClientUpdateMessage();
                } else {
                    event = (Conflatable) this.haContainer.get(event);
                }
                if (event instanceof ClientUpdateMessage) {
                    if (((ClientUpdateMessage) event).hasCqs() && ((ClientUpdateMessage) event).hasCqs(clientProxyID)) {
                        CqNameToOp cqNames = ((ClientUpdateMessage) event).getClientCq(clientProxyID);
                        if (cqNames != null) {
                            for (String cqName : cqNames.getNames()) {
                                InternalCqQuery cq = ((InternalCqQuery) cqService.getClientCqFromServer(clientProxyID, cqName));
                                CqQueryVsdStats cqStats = cq.getVsdStats();
                                if (cq != null && cqStats != null) {
                                    cqStats.incNumHAQueuedEvents(incrementAmount);
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            // as maintaining cq stats should not affect the system.
            if (logger.isTraceEnabled()) {
                logger.trace("Exception while maintaining cq events stats.", e);
            }
        }
    }
}
Also used : ClientUpdateMessage(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessage) CqNameToOp(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) CqService(org.apache.geode.cache.query.internal.cq.CqService) TimeoutException(org.apache.geode.cache.TimeoutException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CancelException(org.apache.geode.CancelException) InternalGemFireException(org.apache.geode.InternalGemFireException) CacheWriterException(org.apache.geode.cache.CacheWriterException) ConcurrentModificationException(java.util.ConcurrentModificationException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) HAEventWrapper(org.apache.geode.internal.cache.tier.sockets.HAEventWrapper) CqQueryVsdStats(org.apache.geode.cache.query.internal.CqQueryVsdStats)

Example 2 with HAEventWrapper

use of org.apache.geode.internal.cache.tier.sockets.HAEventWrapper in project geode by apache.

the class HARegionQueue method getAndRemoveFromHAContainer.

/**
   * If the conflatable is an instance of HAEventWrapper, and if the corresponding entry is present
   * in the haContainer, then decrements its reference count. If the decremented ref count is zero
   * and put is not in progress, removes the entry from the haContainer, before returning the
   * {@code ClientUpdateMessage} instance.
   * 
   * @return An instance of {@code ClientUpdateMessage}
   * @since GemFire 5.7
   */
public Conflatable getAndRemoveFromHAContainer(Conflatable conflatable) {
    Conflatable msg = null;
    if (conflatable instanceof HAEventWrapper) {
        HAEventWrapper wrapper = (HAEventWrapper) conflatable;
        msg = (Conflatable) HARegionQueue.this.haContainer.get(wrapper);
        if (msg != null) {
            decAndRemoveFromHAContainer(wrapper);
        }
    } else {
        msg = conflatable;
    }
    return msg;
}
Also used : Conflatable(org.apache.geode.internal.cache.Conflatable) HAEventWrapper(org.apache.geode.internal.cache.tier.sockets.HAEventWrapper)

Example 3 with HAEventWrapper

use of org.apache.geode.internal.cache.tier.sockets.HAEventWrapper in project geode by apache.

the class HARegionQueue method peek.

public Object peek() throws InterruptedException {
    if (Thread.interrupted())
        throw new InterruptedException();
    Conflatable object = null;
    Long next = null;
    while (true) {
        try {
            next = (Long) this.getNextAvailableIDFromList();
            if (next == null) {
                break;
            }
        } catch (TimeoutException ignore) {
            throw new InterruptedException();
        }
        object = (Conflatable) this.region.get(next);
        if (object != null) {
            // peeked a object, so add the correponding counter to thread-context
            object = (object instanceof HAEventWrapper) ? (Conflatable) this.haContainer.get(object) : object;
            if (object != null) {
                // Is it possible for object to be null...when?
                List peekedEvents;
                if ((peekedEvents = (List) HARegionQueue.peekedEventsContext.get()) != null) {
                    peekedEvents.add(next);
                } else {
                    peekedEvents = new LinkedList();
                    peekedEvents.add(next);
                    HARegionQueue.peekedEventsContext.set(peekedEvents);
                }
                this.storePeekedID(next);
                break;
            }
        }
    }
    // since size is zero, return null
    if (logger.isTraceEnabled()) {
        logger.trace("HARegionQueue::peek: Returning object from head = {}", object);
    }
    return object;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Conflatable(org.apache.geode.internal.cache.Conflatable) LinkedList(java.util.LinkedList) TimeoutException(org.apache.geode.cache.TimeoutException) HAEventWrapper(org.apache.geode.internal.cache.tier.sockets.HAEventWrapper)

Example 4 with HAEventWrapper

use of org.apache.geode.internal.cache.tier.sockets.HAEventWrapper in project geode by apache.

the class HARegionQueue method updateHAContainer.

/**
   * Called from destroy(), this method decrements the referenceCount of all the HAEventWrapper
   * instances held by this queue. Also, removes those instances whose referenceCount becomes zero.
   * 
   * @since GemFire 5.7
   */
private void updateHAContainer() {
    try {
        Object[] wrapperArray = null;
        acquireReadLock();
        try {
            if (this.availableIDsSize() != 0) {
                wrapperArray = this.availableIDsArray();
            }
        } finally {
            releaseReadLock();
        }
        if (wrapperArray != null) {
            final Set wrapperSet = new HashSet();
            for (int i = 0; i < wrapperArray.length; i++) {
                wrapperSet.add(this.region.get(wrapperArray[i]));
            }
            // Start a new thread which will update the clientMessagesRegion for
            // each of the HAEventWrapper instances present in the wrapperSet
            Thread regionCleanupTask = new Thread(new Runnable() {

                public void run() {
                    try {
                        Iterator iter = wrapperSet.iterator();
                        while (iter.hasNext()) {
                            Conflatable conflatable = (Conflatable) iter.next();
                            if (conflatable instanceof HAEventWrapper) {
                                HARegionQueue.this.decAndRemoveFromHAContainer((HAEventWrapper) conflatable);
                            }
                        }
                    } catch (CancelException ignore) {
                        // we're done
                        return;
                    } catch (Exception e) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Exception in regionCleanupTask thread of HARegionQueue.updateHAContainer$run()", e);
                        }
                    }
                }
            });
            regionCleanupTask.start();
        }
    } catch (CancelException e) {
        throw e;
    } catch (RegionDestroyedException e) {
        // TODO does this really generate a CancelException, or do we still
        // get a warning in the logs?
        // Odds are we're shutting down...
        this.getRegion().getCache().getCancelCriterion().checkCancelInProgress(e);
        // If we get back, this is Really Weird. Treat it like the
        // Exception case below.
        logger.warn("HARegionQueue.updateHAContainer: underlying region has been destroyed", e);
    } catch (Exception e) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.HARegionQueue_TASK_TO_DECREMENT_THE_REF_COUNT_MAY_NOT_HAVE_BEEN_STARTED), e);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) TimeoutException(org.apache.geode.cache.TimeoutException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CancelException(org.apache.geode.CancelException) InternalGemFireException(org.apache.geode.InternalGemFireException) CacheWriterException(org.apache.geode.cache.CacheWriterException) ConcurrentModificationException(java.util.ConcurrentModificationException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) Iterator(java.util.Iterator) CancelException(org.apache.geode.CancelException) Conflatable(org.apache.geode.internal.cache.Conflatable) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HAEventWrapper(org.apache.geode.internal.cache.tier.sockets.HAEventWrapper)

Example 5 with HAEventWrapper

use of org.apache.geode.internal.cache.tier.sockets.HAEventWrapper in project geode by apache.

the class HARQueueNewImplDUnitTest method verifyQueueData.

public static void verifyQueueData(Integer regionsize, Integer msgsRegionsize, Integer port) {
    try {
        // Get the clientMessagesRegion and check the size.
        Region msgsRegion = cache.getRegion(CacheServerImpl.generateNameForClientMsgsRegion(port.intValue()));
        Region region = cache.getRegion("/" + regionName);
        logger.fine("size<serverRegion, clientMsgsRegion>: " + region.size() + ", " + msgsRegion.size());
        assertEquals(regionsize.intValue(), region.size());
        assertEquals(msgsRegionsize.intValue(), msgsRegion.size());
        Iterator iter = msgsRegion.entrySet().iterator();
        while (iter.hasNext()) {
            Region.Entry entry = (Region.Entry) iter.next();
            HAEventWrapper wrapper = (HAEventWrapper) entry.getKey();
            ClientUpdateMessage cum = (ClientUpdateMessage) entry.getValue();
            Object key = cum.getKeyOfInterest();
            logger.fine("key<feedCount, regionCount>: " + key + "<" + ((Long) map.get(key)).longValue() + ", " + wrapper.getReferenceCount() + ">");
            assertEquals(((Long) map.get(key)).longValue(), wrapper.getReferenceCount());
        }
    } catch (Exception e) {
        fail("failed in verifyQueueData()" + e);
    }
}
Also used : ClientUpdateMessage(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessage) Iterator(java.util.Iterator) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) HAEventWrapper(org.apache.geode.internal.cache.tier.sockets.HAEventWrapper)

Aggregations

HAEventWrapper (org.apache.geode.internal.cache.tier.sockets.HAEventWrapper)10 ClientUpdateMessageImpl (org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl)4 IOException (java.io.IOException)3 Iterator (java.util.Iterator)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 TimeoutException (org.apache.geode.cache.TimeoutException)3 Conflatable (org.apache.geode.internal.cache.Conflatable)3 ArrayList (java.util.ArrayList)2 ConcurrentModificationException (java.util.ConcurrentModificationException)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 NoSuchElementException (java.util.NoSuchElementException)2 CancelException (org.apache.geode.CancelException)2 InternalGemFireException (org.apache.geode.InternalGemFireException)2 CacheException (org.apache.geode.cache.CacheException)2 CacheWriterException (org.apache.geode.cache.CacheWriterException)2 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)2 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)2 HAContainerWrapper (org.apache.geode.internal.cache.ha.HAContainerWrapper)2 ClientUpdateMessage (org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessage)2