use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.
the class LocalRegion method remove.
/**
* Same as {@link #remove(Object, Object)} except a callback argument is supplied to be passed on
* to <tt>CacheListener</tt>s and/or <tt>CacheWriter</tt>s.
*/
public boolean remove(Object key, Object value, Object callbackArg) {
checkIfConcurrentMapOpsAllowed();
validateKey(key);
validateCallbackArg(callbackArg);
checkReadiness();
checkForLimitedOrNoAccess();
if (value == null) {
value = Token.INVALID;
}
@Released EntryEventImpl event = EntryEventImpl.create(this, Operation.REMOVE, key, null, callbackArg, false, getMyId());
try {
if (generateEventID() && event.getEventId() == null) {
event.setNewEventId(this.cache.getDistributedSystem());
}
discoverJTA();
getDataView().destroyExistingEntry(event, true, value);
} catch (EntryNotFoundException ignore) {
return false;
} catch (RegionDestroyedException rde) {
if (!rde.getRegionFullPath().equals(getFullPath())) {
// Handle when a bucket is destroyed
throw new RegionDestroyedException(toString(), getFullPath(), rde);
} else {
throw rde;
}
} finally {
event.release();
}
return true;
}
use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.
the class LocalRegion method putIfAbsent.
/**
* If the specified key is not already associated with a value, associate it with the given value.
* This is equivalent to
*
* <pre>
* if (!region.containsKey(key))
* return region.put(key, value);
* else
* return region.get(key);
* </pre>
*
* Except that the action is performed atomically.
*
* <i>Note that if this method returns null then there is no way to determine definitely whether
* this operation succeeded and modified the region, or if the entry is in an invalidated state
* and no modification occurred.</i>
*
* If this method does not modify the region then no listeners or other callbacks are executed. If
* a modification does occur, then the behavior with respect to callbacks is the same as
* {@link Region#create(Object, Object)}.
*
* @param key key with which the specified value is to be associated.
* @param value the value for the new entry, which may be null meaning the new entry starts as if
* it had been locally invalidated.
* @return previous value associated with specified key, or <tt>null</tt> if there was no mapping
* for key. A <tt>null</tt> return can also indicate that the entry in the region was
* previously in an invalidated state.
*
* @throws ClassCastException if key does not satisfy the keyConstraint
* @throws IllegalArgumentException if the key or value is not serializable and this is a
* distributed region
* @throws TimeoutException if timed out getting distributed lock for {@code Scope.GLOBAL}
* @throws NullPointerException if key is <tt>null</tt>
* @throws PartitionedRegionStorageException if the operation could not be completed.
*/
public Object putIfAbsent(Object key, Object value, Object callbackArgument) {
long startPut = CachePerfStats.getStatTime();
checkIfConcurrentMapOpsAllowed();
validateArguments(key, value, callbackArgument);
// TODO ConcurrentMap.putIfAbsent() treats null as an invalidation operation
// BUT we need to return the old value, which Invalidate isn't currently doing
checkReadiness();
checkForLimitedOrNoAccess();
discoverJTA();
// This used to call the constructor which took the old value. It
// was modified to call the other EntryEventImpl constructor so that
// an id will be generated by default. Null was passed in anyway.
// generate EventID
@Released EntryEventImpl event = EntryEventImpl.create(this, Operation.PUT_IF_ABSENT, key, value, callbackArgument, false, getMyId());
try {
if (generateEventID()) {
event.setNewEventId(this.cache.getDistributedSystem());
}
final Object oldValue = null;
final boolean ifNew = true;
final boolean ifOld = false;
final boolean requireOldValue = true;
if (!basicPut(event, ifNew, ifOld, oldValue, requireOldValue)) {
return event.getOldValue();
} else {
if (!getDataView().isDeferredStats()) {
getCachePerfStats().endPut(startPut, false);
}
return null;
}
} catch (EntryNotFoundException ignore) {
return event.getOldValue();
} finally {
event.release();
}
}
use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.
the class LocalRegion method localDestroyNoCallbacks.
/**
* WARNING: this method is overridden in subclasses.
*/
protected void localDestroyNoCallbacks(Object key) {
if (logger.isDebugEnabled()) {
logger.debug("localDestroyNoCallbacks key={}", key);
}
checkReadiness();
validateKey(key);
@Released EntryEventImpl event = EntryEventImpl.create(this, Operation.LOCAL_DESTROY, key, false, getMyId(), false, /* generateCallbacks */
true);
try {
// expectedOldValue
basicDestroy(event, false, null);
} catch (CacheWriterException e) {
// cache writer not called
throw new Error(LocalizedStrings.LocalRegion_CACHE_WRITER_SHOULD_NOT_HAVE_BEEN_CALLED_FOR_LOCALDESTROY.toLocalizedString(), e);
} catch (TimeoutException e) {
// no distributed lock
throw new Error(LocalizedStrings.LocalRegion_NO_DISTRIBUTED_LOCK_SHOULD_HAVE_BEEN_ATTEMPTED_FOR_LOCALDESTROY.toLocalizedString(), e);
} catch (EntryNotFoundException ignore) {
// not a problem
} finally {
event.release();
}
}
use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.
the class LocalRegion method basicBridgeCreate.
public boolean basicBridgeCreate(final Object key, final byte[] value, boolean isObject, Object callbackArg, final ClientProxyMembershipID client, boolean fromClient, EntryEventImpl clientEvent, boolean throwEntryExists) throws TimeoutException, EntryExistsException, CacheWriterException {
EventID eventId = clientEvent.getEventId();
Object theCallbackArg = callbackArg;
long startPut = CachePerfStats.getStatTime();
if (fromClient) {
// GatewayEventCallbackArgument to store the event id.
if (isGatewaySenderEnabled()) {
theCallbackArg = new GatewaySenderEventCallbackArgument(theCallbackArg);
}
}
@Released final EntryEventImpl event = EntryEventImpl.create(this, Operation.CREATE, key, value, theCallbackArg, false, /* origin remote */
client.getDistributedMember(), true, /* generateCallbacks */
eventId);
try {
event.setContext(client);
// if this is a replayed operation or WAN event we may already have a version tag
event.setVersionTag(clientEvent.getVersionTag());
// carry over the possibleDuplicate flag from clientEvent
event.setPossibleDuplicate(clientEvent.isPossibleDuplicate());
// normal regions. Otherwise, it will become a distributed invalidate.
if (getDataPolicy() == DataPolicy.NORMAL) {
event.setLocalInvalid(true);
}
// Set the new value to the input byte[] if it isn't null
if (value != null) {
// in a CachedDeserializable; otherwise store it directly as a byte[]
if (isObject) {
// The value represents an object
event.setSerializedNewValue(value);
} else {
// The value does not represent an object
event.setNewValue(value);
}
}
// cannot overwrite an existing key
boolean ifNew = true;
// can create a new key
boolean ifOld = false;
// use now
long lastModified = 0L;
// not okay to overwrite the DESTROYED token
boolean overwriteDestroyed = false;
boolean success = basicUpdate(event, ifNew, ifOld, lastModified, overwriteDestroyed);
clientEvent.isConcurrencyConflict(event.isConcurrencyConflict());
if (success) {
clientEvent.setVersionTag(event.getVersionTag());
getCachePerfStats().endPut(startPut, event.isOriginRemote());
} else {
this.stopper.checkCancelInProgress(null);
if (throwEntryExists) {
throw new EntryExistsException("" + key, event.getOldValue());
}
}
return success;
} finally {
event.release();
}
}
use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.
the class LocalRegion method basicBridgePut.
public boolean basicBridgePut(Object key, Object value, byte[] deltaBytes, boolean isObject, Object callbackArg, ClientProxyMembershipID memberId, boolean fromClient, EntryEventImpl clientEvent) throws TimeoutException, CacheWriterException {
EventID eventID = clientEvent.getEventId();
Object theCallbackArg = callbackArg;
long startPut = CachePerfStats.getStatTime();
if (fromClient) {
// GatewayEventCallbackArgument to store the event id.
if (isGatewaySenderEnabled()) {
theCallbackArg = new GatewaySenderEventCallbackArgument(theCallbackArg);
}
}
@Released final EntryEventImpl event = EntryEventImpl.create(this, Operation.UPDATE, key, null, /* new value */
theCallbackArg, false, /* origin remote */
memberId.getDistributedMember(), true, /* generateCallbacks */
eventID);
try {
event.setContext(memberId);
event.setDeltaBytes(deltaBytes);
// if this is a replayed operation we may already have a version tag
event.setVersionTag(clientEvent.getVersionTag());
// carry over the possibleDuplicate flag from clientEvent
event.setPossibleDuplicate(clientEvent.isPossibleDuplicate());
// serialized in a CachedDeserializable; otherwise store it directly as a byte[].
if (isObject && value instanceof byte[]) {
event.setSerializedNewValue((byte[]) value);
} else {
event.setNewValue(value);
}
boolean success = false;
try {
// can overwrite an existing key
boolean ifNew = false;
// can create a new key
boolean ifOld = false;
// use now
long lastModified = 0L;
// not okay to overwrite the DESTROYED token
boolean overwriteDestroyed = false;
success = basicUpdate(event, ifNew, ifOld, lastModified, overwriteDestroyed);
} catch (ConcurrentCacheModificationException ignore) {
// thrown by WAN conflicts
event.isConcurrencyConflict(true);
}
clientEvent.isConcurrencyConflict(event.isConcurrencyConflict());
if (success) {
clientEvent.setVersionTag(event.getVersionTag());
getCachePerfStats().endPut(startPut, event.isOriginRemote());
} else {
this.stopper.checkCancelInProgress(null);
}
return success;
} finally {
event.release();
}
}
Aggregations