use of org.apache.geode.cache.Operation in project geode by apache.
the class DistributedRegion method findObjectInSystem.
/** @return the deserialized value */
@Override
@Retained
protected Object findObjectInSystem(KeyInfo keyInfo, boolean isCreate, TXStateInterface txState, boolean generateCallbacks, Object localValue, boolean disableCopyOnRead, boolean preferCD, ClientProxyMembershipID requestingClient, EntryEventImpl clientEvent, boolean returnTombstones) throws CacheLoaderException, TimeoutException {
@Released EntryEventImpl event = null;
checkForLimitedOrNoAccess();
final Operation op = isCreate ? Operation.CREATE : Operation.UPDATE;
long lastModified = 0L;
try {
event = findOnServer(keyInfo, op, generateCallbacks, clientEvent);
if (event == null) {
event = createEventForLoad(keyInfo, generateCallbacks, requestingClient, op);
lastModified = findUsingSearchLoad(txState, localValue, clientEvent, keyInfo, event);
}
// Update region with new value.
if (event.hasNewValue() && !isMemoryThresholdReachedForLoad()) {
putNewValueInRegion(isCreate, clientEvent, lastModified, event);
} else if (isCreate) {
recordMiss(null, event.getKey());
}
return determineResult(preferCD, event);
} finally {
if (event != null) {
event.release();
}
}
}
use of org.apache.geode.cache.Operation in project geode by apache.
the class SearchLoadAndWriteProcessor method getEventForListener.
/**
* Returns an event for listener notification. The event's operation may be altered to conform to
* the ConcurrentMap implementation specification. If the returned value is not == to the event
* parameter then the caller is responsible for releasing it.
*
* @param event the original event
* @return the original event or a new event having a change in operation
*/
@Retained
private CacheEvent getEventForListener(CacheEvent event) {
Operation op = event.getOperation();
if (!op.isEntry()) {
return event;
} else {
EntryEventImpl r = (EntryEventImpl) event;
@Retained EntryEventImpl result = r;
if (r.isSingleHop()) {
// fix for bug #46130 - origin remote incorrect for one-hop operation in receiver
result = new EntryEventImpl(r);
result.setOriginRemote(true);
// because that's what the sender would use in notifying listeners. bug #46955
if (result.getOperation().isUpdate() && (result.getTransactionId() == null)) {
result.makeCreate();
}
}
if (op == Operation.REPLACE) {
if (result == r)
result = new EntryEventImpl(r);
result.setOperation(Operation.UPDATE);
} else if (op == Operation.PUT_IF_ABSENT) {
if (result == r)
result = new EntryEventImpl(r);
result.setOperation(Operation.CREATE);
} else if (op == Operation.REMOVE) {
if (result == r)
result = new EntryEventImpl(r);
result.setOperation(Operation.DESTROY);
}
return result;
}
}
use of org.apache.geode.cache.Operation in project geode by apache.
the class LocalRegion method serverPut.
/**
* @since GemFire 5.7
*/
void serverPut(EntryEventImpl event, boolean requireOldValue, Object expectedOldValue) {
if (event.getOperation().isDistributed() && !event.isFromServer()) {
ServerRegionProxy mySRP = getServerProxy();
if (mySRP != null) {
if (event.isBulkOpInProgress()) {
// this is a put all, ignore this!
return;
}
Operation op = event.getOperation();
// TODO: is the newEntry flag needed?
Object key = event.getKey();
Object value = event.getRawNewValue();
// serverPut is called by cacheWriteBeforePut so the new value will not yet be off-heap
Object callbackArg = event.getRawCallbackArgument();
boolean isCreate = event.isCreate();
Object result = mySRP.put(key, value, event.getDeltaBytes(), event, op, requireOldValue, expectedOldValue, callbackArg, isCreate);
// bug #42296, serverProxy returns null when cache is closing
getCancelCriterion().checkCancelInProgress(null);
// to apply the operation and need to throw an exception
if (op.guaranteesOldValue()) {
if (op != Operation.REPLACE || requireOldValue) {
event.setConcurrentMapOldValue(result);
}
if (op == Operation.PUT_IF_ABSENT) {
if (result != null) {
// customers don't see this exception
throw new EntryNotFoundException("entry existed for putIfAbsent");
}
} else if (op == Operation.REPLACE) {
if (requireOldValue && result == null) {
throw new EntryNotFoundException("entry not found for replace");
} else if (!requireOldValue) {
if (!(Boolean) result) {
// customers don't see this exception
throw new EntryNotFoundException("entry found with wrong value");
}
}
}
}
}
}
}
use of org.apache.geode.cache.Operation in project geode by apache.
the class LocalRegion method cacheWriteBeforePut.
void cacheWriteBeforePut(EntryEventImpl event, Set netWriteRecipients, CacheWriter localWriter, boolean requireOldValue, Object expectedOldValue) throws CacheWriterException, TimeoutException {
Assert.assertTrue(netWriteRecipients == null);
Operation operation = event.getOperation();
boolean isPutIfAbsentOrReplace = operation == Operation.PUT_IF_ABSENT || operation == Operation.REPLACE;
if (!isPutIfAbsentOrReplace && localWriter != null && !event.inhibitAllNotifications()) {
final long start = getCachePerfStats().startCacheWriterCall();
final boolean newEntry = event.getOperation().isCreate();
try {
if (!newEntry) {
localWriter.beforeUpdate(event);
} else {
localWriter.beforeCreate(event);
}
} finally {
getCachePerfStats().endCacheWriterCall(start);
}
}
serverPut(event, requireOldValue, expectedOldValue);
}
use of org.apache.geode.cache.Operation in project geode by apache.
the class LocalRegion method invokePutCallbacks.
public void invokePutCallbacks(final EnumListenerEvent eventType, final EntryEventImpl event, final boolean callDispatchListenerEvent, boolean notifyGateways) {
// disallow callbacks on import
if (!event.isGenerateCallbacks()) {
return;
}
// Notify bridge clients (if this is a BridgeServer)
Operation op = event.getOperation();
// to non-CM counterparts
if (op == Operation.PUT_IF_ABSENT) {
event.setOperation(Operation.CREATE);
} else if (op == Operation.REPLACE) {
event.setOperation(Operation.UPDATE);
}
event.setEventType(eventType);
notifyBridgeClients(event);
if (notifyGateways) {
notifyGatewaySender(eventType, event);
}
if (callDispatchListenerEvent) {
dispatchListenerEvent(eventType, event);
}
}
Aggregations