use of org.apache.geode.internal.cache.EventID in project geode by apache.
the class HARegionQueue method take.
/**
* For non blocking queue , this method either returns null or an Object. For blocking queue it
* will always return with an Object or wait for queue to be populated.
*
* @throws CacheException The exception can be thrown by BlockingQueue if it encounters
* InterruptedException while waiting for data
*/
public Object take() throws CacheException, InterruptedException {
Conflatable object = null;
Long next = null;
if ((next = this.getAndRemoveNextAvailableID()) != null) {
object = (Conflatable) this.region.get(next);
Assert.assertTrue(object != null);
object = this.getAndRemoveFromHAContainer(object);
Assert.assertTrue(object != null);
EventID eventid = object.getEventId();
long sequenceId = eventid.getSequenceID();
ThreadIdentifier threadid = getThreadIdentifier(eventid);
DispatchedAndCurrentEvents dace = (DispatchedAndCurrentEvents) this.eventsMap.get(threadid);
Assert.assertTrue(dace != null);
Object keyToConflate = null;
if (shouldBeConflated(object)) {
keyToConflate = object.getKeyToConflate();
}
dace.removeEventAndSetSequenceID(new RemovedEventInfo(next, object.getRegionToConflate(), keyToConflate), sequenceId);
// Periodic ack from the client will add to the addDispatchMessage Map.
// This method gets called from cacheClientNotifier upon receiving the ack from client.
// addDispatchedMessage(threadid, sequenceId);
// update the stats
// if (logger.isDebugEnabled()) {
this.stats.incEventsTaken();
// }
}
// since size is zero, return null
if (object == null && logger.isDebugEnabled()) {
logger.debug("RegionQueue is EMPTY, returning null for take()");
}
return object;
}
use of org.apache.geode.internal.cache.EventID in project geode by apache.
the class HARegionQueue method expireTheEventOrThreadIdentifier.
/**
* This function is invoked by the createCacheListenerForHARegion for theHARegionQueue & also by
* overridden function createCacheListenerForHARegion of the HARegionQueueJUnitTest class for the
* test testConcurrentEventExpiryAndTake. This function provides the meaningful functionality for
* expiry of the Event object as well as ThreadIdentifier
*
* @param event event object representing the data being expired
*/
void expireTheEventOrThreadIdentifier(EntryEvent event) throws CacheException {
final boolean isDebugEnabled = logger.isDebugEnabled();
if (isDebugEnabled) {
logger.debug("HARegionQueue::afterInvalidate. Entry Event being invalidated:{}, isPrimaryQueue:{}", event, HARegionQueue.this.isPrimary());
}
Object key = event.getKey();
if (key instanceof ThreadIdentifier) {
// Check if the sequenceID present as value against this key is same
// as
// the last dispatched sequence & the size of set containing the
// counters
// is 0. If yes the Dace should be removed
// Get DACE
DispatchedAndCurrentEvents dace = (DispatchedAndCurrentEvents) HARegionQueue.this.eventsMap.get(key);
Assert.assertTrue(dace != null);
Long expirySequenceID = (Long) event.getOldValue();
boolean expired = dace.expireOrUpdate(expirySequenceID, (ThreadIdentifier) key);
if (isDebugEnabled) {
logger.debug("HARegionQueue::afterInvalidate:Size of the region after expiring or updating the ThreadIdentifier={}", HARegionQueue.this.region.keys().size());
logger.debug("HARegionQueue::afterInvalidate:ThreadIdentifier expired={}", expired);
}
} else if (key instanceof Long) {
// if (destroyFromAvailableIDsAndRegion((Long)key)) {
destroyFromQueue(key);
Conflatable cf = (Conflatable) event.getOldValue();
EventID id = cf.getEventId();
byte[] memID = id.getMembershipID();
long threadId = id.getThreadID();
DispatchedAndCurrentEvents dace = (DispatchedAndCurrentEvents) eventsMap.get(new ThreadIdentifier(memID, threadId));
if (shouldBeConflated(cf)) {
dace.destroy((Long) key, cf.getKeyToConflate(), cf.getRegionToConflate());
} else {
dace.destroy((Long) key);
}
// }
} else {
// unexpected condition, throw exception?
}
}
use of org.apache.geode.internal.cache.EventID in project geode by apache.
the class CacheClientUpdater method handleUpdate.
/**
* Create or update an entry
*
* @param clientMessage message containing the data
*/
private void handleUpdate(Message clientMessage) {
String regionName = null;
Object key = null;
Part valuePart = null;
final boolean isDebugEnabled = logger.isDebugEnabled();
try {
this.isOpCompleted = false;
// Retrieve the data from the put message parts
if (isDebugEnabled) {
logger.debug("Received put message of length ({} bytes)", clientMessage.getPayloadLength());
}
int partCnt = 0;
Part regionNamePart = clientMessage.getPart(partCnt++);
Part keyPart = clientMessage.getPart(partCnt++);
boolean isDeltaSent = (Boolean) clientMessage.getPart(partCnt++).getObject();
valuePart = clientMessage.getPart(partCnt++);
Part callbackArgumentPart = clientMessage.getPart(partCnt++);
VersionTag versionTag = (VersionTag) clientMessage.getPart(partCnt++).getObject();
if (versionTag != null) {
versionTag.replaceNullIDs((InternalDistributedMember) this.endpoint.getMemberId());
}
Part isInterestListPassedPart = clientMessage.getPart(partCnt++);
Part hasCqsPart = clientMessage.getPart(partCnt++);
EventID eventId = (EventID) clientMessage.getPart(clientMessage.getNumberOfParts() - 1).getObject();
boolean withInterest = (Boolean) isInterestListPassedPart.getObject();
boolean withCQs = (Boolean) hasCqsPart.getObject();
regionName = regionNamePart.getString();
key = keyPart.getStringOrObject();
Object callbackArgument = callbackArgumentPart.getObject();
// Don't automatically deserialize the value.
// Pass it onto the region as a byte[]. If it is a serialized
// object, it will be stored as a CachedDeserializable and
// deserialized only when requested.
boolean isCreate = clientMessage.getMessageType() == MessageType.LOCAL_CREATE;
if (isDebugEnabled) {
logger.debug("Putting entry for region: {} key: {} create: {}{} callbackArgument: {} withInterest={} withCQs={} eventID={} version={}", regionName, key, isCreate, valuePart.isObject() ? new StringBuilder(" value: ").append(deserialize(valuePart.getSerializedForm())) : "", callbackArgument, withInterest, withCQs, eventId, versionTag);
}
LocalRegion region = (LocalRegion) this.cacheHelper.getRegion(regionName);
Object newValue = null;
byte[] deltaBytes = null;
Object fullValue = null;
boolean isValueObject;
if (!isDeltaSent) {
// bug #42162 - must check for a serialized null here
byte[] serializedForm = valuePart.getSerializedForm();
if (isCreate && InternalDataSerializer.isSerializedNull(serializedForm)) {
// newValue = null; newValue is already null
} else {
newValue = valuePart.getSerializedForm();
}
if (withCQs) {
fullValue = valuePart.getObject();
}
isValueObject = valuePart.isObject();
} else {
deltaBytes = valuePart.getSerializedForm();
isValueObject = true;
}
if (region == null) {
if (isDebugEnabled && !quitting()) {
logger.debug("{}: Region named {} does not exist", this, regionName);
}
} else if (region.hasServerProxy() && ServerResponseMatrix.checkForValidStateAfterNotification(region, key, clientMessage.getMessageType()) && (withInterest || !withCQs)) {
@Released EntryEventImpl newEvent = null;
try {
// Create an event and put the entry
newEvent = EntryEventImpl.create(region, clientMessage.getMessageType() == MessageType.LOCAL_CREATE ? Operation.CREATE : Operation.UPDATE, key, null, /* newValue */
callbackArgument, /* callbackArg */
true, /* originRemote */
eventId.getDistributedMember());
newEvent.setVersionTag(versionTag);
newEvent.setFromServer(true);
region.basicBridgeClientUpdate(eventId.getDistributedMember(), key, newValue, deltaBytes, isValueObject, callbackArgument, clientMessage.getMessageType() == MessageType.LOCAL_CREATE, this.qManager.getState().getProcessedMarker() || !this.isDurableClient, newEvent, eventId);
this.isOpCompleted = true;
// flag
if (withCQs && isDeltaSent) {
fullValue = newEvent.getNewValue();
}
} catch (InvalidDeltaException ignore) {
Part fullValuePart = requestFullValue(eventId, "Caught InvalidDeltaException.");
region.getCachePerfStats().incDeltaFullValuesRequested();
// TODO: fix this line
fullValue = newValue = fullValuePart.getObject();
isValueObject = fullValuePart.isObject();
region.basicBridgeClientUpdate(eventId.getDistributedMember(), key, newValue, null, isValueObject, callbackArgument, clientMessage.getMessageType() == MessageType.LOCAL_CREATE, this.qManager.getState().getProcessedMarker() || !this.isDurableClient, newEvent, eventId);
this.isOpCompleted = true;
} finally {
if (newEvent != null)
newEvent.release();
}
if (isDebugEnabled) {
logger.debug("Put entry for region: {} key: {} callbackArgument: {}", regionName, key, callbackArgument);
}
}
// Update CQs. CQs can exist without client region.
if (withCQs) {
Part numCqsPart = clientMessage.getPart(partCnt++);
if (isDebugEnabled) {
logger.debug("Received message has CQ Event. Number of cqs interested in the event : {}", numCqsPart.getInt() / 2);
}
partCnt = processCqs(clientMessage, partCnt, numCqsPart.getInt(), clientMessage.getMessageType(), key, fullValue, deltaBytes, eventId);
this.isOpCompleted = true;
}
} catch (Exception e) {
String message = LocalizedStrings.CacheClientUpdater_THE_FOLLOWING_EXCEPTION_OCCURRED_WHILE_ATTEMPTING_TO_PUT_ENTRY_REGION_0_KEY_1_VALUE_2.toLocalizedString(regionName, key, deserialize(valuePart.getSerializedForm()));
handleException(message, e);
}
}
use of org.apache.geode.internal.cache.EventID in project geode by apache.
the class CacheClientProxy method enqueueInitialValue.
private void enqueueInitialValue(ClientInterestMessageImpl clientInterestMessage, String regionName, Object keyOfInterest) {
// Get the initial value
Get70 request = (Get70) Get70.getCommand();
LocalRegion lr = (LocalRegion) this._cache.getRegion(regionName);
Get70.Entry entry = request.getValueAndIsObject(lr, keyOfInterest, null, null);
boolean isObject = entry.isObject;
byte[] value = null;
// If the initial value is not null, add it to the client's queue
if (entry.value != null) {
if (entry.value instanceof byte[]) {
value = (byte[]) entry.value;
} else {
try {
value = CacheServerHelper.serialize(entry.value);
} catch (IOException e) {
logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientProxy_THE_FOLLOWING_EXCEPTION_OCCURRED_0, entry.value), e);
}
}
VersionTag tag = entry.versionTag;
// Initialize the event id.
EventID eventId = null;
if (clientInterestMessage == null) {
// If the clientInterestMessage is null, create a new event id
eventId = new EventID(this._cache.getDistributedSystem());
} else {
// If the clientInterestMessage is not null, base the event id off its event id to fix
// GEM-794.
// This will cause the updateMessage created below to have the same event id as the one
// created
// in the primary.
eventId = new EventID(clientInterestMessage.getEventId(), 1);
}
ClientUpdateMessage updateMessage = new ClientUpdateMessageImpl(EnumListenerEvent.AFTER_CREATE, lr, keyOfInterest, value, null, (isObject ? (byte) 0x01 : (byte) 0x00), null, this.proxyID, eventId, tag);
CacheClientNotifier.routeSingleClientMessage(updateMessage, this.proxyID);
}
}
use of org.apache.geode.internal.cache.EventID in project geode by apache.
the class CacheClientUpdater method handleDestroy.
/**
* locally destroy an entry
*
* @param clientMessage message describing the entry
*/
private void handleDestroy(Message clientMessage) {
String regionName = null;
Object key = null;
final boolean isDebugEnabled = logger.isDebugEnabled();
try {
this.isOpCompleted = false;
// Retrieve the data from the local-destroy message parts
if (isDebugEnabled) {
logger.debug("Received destroy message of length ({} bytes)", clientMessage.getPayloadLength());
}
int partCnt = 0;
Part regionNamePart = clientMessage.getPart(partCnt++);
Part keyPart = clientMessage.getPart(partCnt++);
Part callbackArgumentPart = clientMessage.getPart(partCnt++);
VersionTag versionTag = (VersionTag) clientMessage.getPart(partCnt++).getObject();
if (versionTag != null) {
versionTag.replaceNullIDs((InternalDistributedMember) this.endpoint.getMemberId());
}
regionName = regionNamePart.getString();
key = keyPart.getStringOrObject();
Part isInterestListPassedPart = clientMessage.getPart(partCnt++);
Part hasCqsPart = clientMessage.getPart(partCnt++);
boolean withInterest = ((Boolean) isInterestListPassedPart.getObject()).booleanValue();
boolean withCQs = ((Boolean) hasCqsPart.getObject()).booleanValue();
Object callbackArgument = callbackArgumentPart.getObject();
if (isDebugEnabled) {
logger.debug("Destroying entry for region: {} key: {} callbackArgument: {} withInterest={} withCQs={} version={}", regionName, key, callbackArgument, withInterest, withCQs, versionTag);
}
LocalRegion region = (LocalRegion) this.cacheHelper.getRegion(regionName);
if (region == null) {
if (isDebugEnabled && !quitting()) {
logger.debug("Region named {} does not exist", regionName);
}
} else if (region.hasServerProxy() && (withInterest || !withCQs)) {
EventID eventId = null;
try {
Part eid = clientMessage.getPart(clientMessage.getNumberOfParts() - 1);
eventId = (EventID) eid.getObject();
try {
region.basicBridgeClientDestroy(eventId.getDistributedMember(), key, callbackArgument, this.qManager.getState().getProcessedMarker() || !this.isDurableClient, eventId, versionTag);
} catch (ConcurrentCacheModificationException ignore) {
// allow CQs to be processed
}
this.isOpCompleted = true;
if (isDebugEnabled) {
logger.debug("Destroyed entry for region: {} key: {} callbackArgument: {}", regionName, key, callbackArgument);
}
} catch (EntryNotFoundException ignore) {
if (isDebugEnabled && !quitting()) {
logger.debug("Already destroyed entry for region: {} key: {} callbackArgument: {} eventId={}", regionName, key, callbackArgument, eventId.expensiveToString());
}
this.isOpCompleted = true;
}
}
if (withCQs) {
Part numCqsPart = clientMessage.getPart(partCnt++);
if (isDebugEnabled) {
logger.debug("Received message has CQ Event. Number of cqs interested in the event : {}", numCqsPart.getInt() / 2);
}
partCnt = processCqs(clientMessage, partCnt, numCqsPart.getInt(), clientMessage.getMessageType(), key, null);
this.isOpCompleted = true;
}
} catch (Exception e) {
String message = LocalizedStrings.CacheClientUpdater_THE_FOLLOWING_EXCEPTION_OCCURRED_WHILE_ATTEMPTING_TO_DESTROY_ENTRY_REGION_0_KEY_1.toLocalizedString(regionName, key);
handleException(message, e);
}
}
Aggregations