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