use of org.apache.geode.internal.cache.EntryEventImpl 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.EntryEventImpl in project geode by apache.
the class CacheClientNotifier method removeDestroyTokensFromCqResultKeys.
private void removeDestroyTokensFromCqResultKeys(InternalCacheEvent event, FilterInfo filterInfo) {
FilterProfile regionProfile = ((LocalRegion) event.getRegion()).getFilterProfile();
if (event.getOperation().isEntry() && filterInfo.getCQs() != null) {
EntryEventImpl entryEvent = (EntryEventImpl) event;
for (Map.Entry<Long, Integer> e : filterInfo.getCQs().entrySet()) {
Long cqID = e.getKey();
String cqName = regionProfile.getRealCqID(cqID);
if (cqName != null) {
ServerCQ cq = regionProfile.getCq(cqName);
if (cq != null && e.getValue().equals(Integer.valueOf(MessageType.LOCAL_DESTROY))) {
cq.removeFromCqResultKeys(entryEvent.getKey(), true);
}
}
}
}
}
use of org.apache.geode.internal.cache.EntryEventImpl in project geode by apache.
the class BatchDestroyOperation method initMessage.
@Override
protected void initMessage(CacheOperationMessage msg, DirectReplyProcessor processor) {
super.initMessage(msg, processor);
DestroyMessage m = (DestroyMessage) msg;
EntryEventImpl event = getEvent();
m.key = event.getKey();
m.eventId = event.getEventId();
}
use of org.apache.geode.internal.cache.EntryEventImpl in project geode by apache.
the class ConcurrentSerialGatewaySenderEventProcessor method enqueueEvent.
public void enqueueEvent(EnumListenerEvent operation, EntryEvent event, Object substituteValue, int index) throws CacheException, IOException {
// Get the appropriate gateway
SerialGatewaySenderEventProcessor serialProcessor = this.processors.get(index);
if (sender.getOrderPolicy() == OrderPolicy.KEY || sender.getOrderPolicy() == OrderPolicy.PARTITION) {
// Create copy since the event id will be changed, otherwise the same
// event will be changed for multiple gateways. Fix for bug 44471.
@Released EntryEventImpl clonedEvent = new EntryEventImpl((EntryEventImpl) event);
try {
EventID originalEventId = clonedEvent.getEventId();
if (logger.isDebugEnabled()) {
logger.debug("The original EventId is {}", originalEventId);
}
// PARALLEL_THREAD_BUFFER * (index +1) + originalEventId.getThreadID();
// generating threadId by the algorithm explained above used to clash with
// fakeThreadId generated by putAll
// below is new way to generate threadId so that it doesn't clash with
// any.
long newThreadId = ThreadIdentifier.createFakeThreadIDForParallelGateway(index, originalEventId.getThreadID(), 0);
EventID newEventId = new EventID(originalEventId.getMembershipID(), newThreadId, originalEventId.getSequenceID());
if (logger.isDebugEnabled()) {
logger.debug("{}: Generated event id for event with key={}, index={}, original event id={}, threadId={}, new event id={}, newThreadId={}", this, event.getKey(), index, originalEventId, originalEventId.getThreadID(), newEventId, newThreadId);
}
clonedEvent.setEventId(newEventId);
serialProcessor.enqueueEvent(operation, clonedEvent, substituteValue);
} finally {
clonedEvent.release();
}
} else {
serialProcessor.enqueueEvent(operation, event, substituteValue);
}
}
use of org.apache.geode.internal.cache.EntryEventImpl in project geode by apache.
the class ParallelGatewaySenderEventProcessor method enqueueEvent.
@Override
public void enqueueEvent(EnumListenerEvent operation, EntryEvent event, Object substituteValue) throws IOException, CacheException {
GatewaySenderEventImpl gatewayQueueEvent = null;
Region region = event.getRegion();
if (!(region instanceof DistributedRegion) && ((EntryEventImpl) event).getTailKey() == -1) {
// Fix for #49081 and EntryDestroyedException in #49367.
if (logger.isDebugEnabled()) {
logger.debug("ParallelGatewaySenderEventProcessor not enqueing the following event since tailKey is not set. {}", event);
}
return;
}
// TODO: Looks like for PDX region bucket id is set to -1.
boolean queuedEvent = false;
try {
EventID eventID = ((EntryEventImpl) event).getEventId();
// while merging 42004, kept substituteValue as it is(it is barry's
// change 42466). bucketID is merged with eventID.getBucketID
gatewayQueueEvent = new GatewaySenderEventImpl(operation, event, substituteValue, true, eventID.getBucketID());
if (getSender().beforeEnqueue(gatewayQueueEvent)) {
long start = getSender().getStatistics().startTime();
try {
queuedEvent = this.queue.put(gatewayQueueEvent);
} catch (InterruptedException e) {
e.printStackTrace();
}
getSender().getStatistics().endPut(start);
} else {
if (logger.isDebugEnabled()) {
logger.debug("The Event {} is filtered.", gatewayQueueEvent);
}
getSender().getStatistics().incEventsFiltered();
}
} finally {
if (!queuedEvent) {
// it was not queued for some reason
gatewayQueueEvent.release();
}
}
}
Aggregations