use of org.apache.geode.internal.offheap.annotations.Unretained in project geode by apache.
the class EntryEventImpl method getOldValue.
/**
* Returns the value in the cache prior to this event. When passed to an event handler after an
* event occurs, this value reflects the value that was in the cache in this VM, not necessarily
* the value that was in the cache VM that initiated the operation.
*
* @return the value in the cache prior to this event.
*/
public Object getOldValue() {
try {
if (isOriginRemote() && this.region.isProxy()) {
return null;
}
@Unretained Object ov = basicGetOldValue();
if (ov == null) {
return null;
} else if (ov == Token.NOT_AVAILABLE) {
return AbstractRegion.handleNotAvailable(ov);
}
boolean doCopyOnRead = getRegion().isCopyOnRead();
if (ov != null) {
if (ov instanceof CachedDeserializable) {
return callWithOffHeapLock((CachedDeserializable) ov, oldValueCD -> {
if (doCopyOnRead) {
return oldValueCD.getDeserializedWritableCopy(this.region, this.re);
} else {
return oldValueCD.getDeserializedValue(this.region, this.re);
}
});
} else {
if (doCopyOnRead) {
return CopyHelper.copy(ov);
} else {
return ov;
}
}
}
return null;
} catch (IllegalArgumentException i) {
IllegalArgumentException iae = new IllegalArgumentException(LocalizedStrings.DONT_RELEASE.toLocalizedString("Error while deserializing value for key=" + getKey()));
iae.initCause(i);
throw iae;
}
}
use of org.apache.geode.internal.offheap.annotations.Unretained in project geode by apache.
the class DistributedRemoveAllOperation method getEventForPosition.
@Unretained
public EntryEventImpl getEventForPosition(int position) {
RemoveAllEntryData entry = this.removeAllData[position];
if (entry == null) {
return null;
}
if (entry.event != null) {
return entry.event;
}
LocalRegion region = (LocalRegion) this.event.getRegion();
// owned by this.removeAllData once entry.event = ev is done
@Retained EntryEventImpl ev = EntryEventImpl.create(region, entry.getOp(), entry.getKey(), null, /* value */
this.event.getCallbackArgument(), false, /* originRemote */
this.event.getDistributedMember(), this.event.isGenerateCallbacks(), entry.getEventID());
boolean returnedEv = false;
try {
ev.setPossibleDuplicate(entry.isPossibleDuplicate());
ev.setIsRedestroyedEntry(entry.getRedestroyedEntry());
if (entry.versionTag != null && region.concurrencyChecksEnabled) {
VersionSource id = entry.versionTag.getMemberID();
if (id != null) {
entry.versionTag.setMemberID(ev.getRegion().getVersionVector().getCanonicalId(id));
}
ev.setVersionTag(entry.versionTag);
}
entry.event = ev;
returnedEv = true;
ev.setOldValue(entry.getOldValue());
CqService cqService = region.getCache().getCqService();
if (cqService.isRunning() && !entry.getOp().isCreate() && !ev.hasOldValue()) {
ev.setOldValueForQueryProcessing();
}
ev.setInvokePRCallbacks(!entry.isNotifyOnly());
if (getBaseEvent().getContext() != null) {
ev.setContext(getBaseEvent().getContext());
}
ev.callbacksInvoked(entry.isCallbacksInvoked());
ev.setTailKey(entry.getTailKey());
return ev;
} finally {
if (!returnedEv) {
ev.release();
}
}
}
use of org.apache.geode.internal.offheap.annotations.Unretained in project geode by apache.
the class EntryEventImpl method getSerializedNewValue.
/**
* @return null if new value is not serialized; otherwise returns a SerializedCacheValueImpl
* containing the new value.
*/
public SerializedCacheValue<?> getSerializedNewValue() {
// In the case where there is a delta that has not been applied yet,
// do not apply it here since it would not produce a serialized new
// value (return null instead to indicate the new value is not
// in serialized form).
@Unretained(ENTRY_EVENT_NEW_VALUE) final Object tmp = basicGetNewValue();
if (tmp instanceof CachedDeserializable) {
CachedDeserializable cd = (CachedDeserializable) tmp;
if (!cd.isSerialized()) {
return null;
}
byte[] bytes = this.newValueBytes;
if (bytes == null) {
bytes = this.cachedSerializedNewValue;
}
return new SerializedCacheValueImpl(this, getRegion(), this.re, cd, bytes);
} else {
// that a CacheDeserializable should be created during deserialization.
return null;
}
}
use of org.apache.geode.internal.offheap.annotations.Unretained in project geode by apache.
the class EntryEventImpl method exportOldValue.
/**
* Export the event's old value to the given importer.
*/
public void exportOldValue(OldValueImporter importer) {
final boolean prefersSerialized = importer.prefersOldSerialized();
if (prefersSerialized) {
if (this.oldValueBytes != null && this.oldValue instanceof CachedDeserializable) {
importer.importOldBytes(this.oldValueBytes, true);
return;
}
}
@Unretained(ENTRY_EVENT_OLD_VALUE) final Object ov = getRawOldValue();
if (ov instanceof StoredObject) {
final StoredObject so = (StoredObject) ov;
final boolean isSerialized = so.isSerialized();
if (importer.isUnretainedOldReferenceOk()) {
importer.importOldObject(ov, isSerialized);
} else if (!isSerialized || prefersSerialized) {
importer.importOldBytes(so.getValueAsHeapByteArray(), isSerialized);
} else {
importer.importOldObject(so.getValueAsDeserializedHeapObject(), true);
}
} else if (ov instanceof byte[]) {
importer.importOldBytes((byte[]) ov, false);
} else if (!importer.isCachedDeserializableValueOk() && ov instanceof CachedDeserializable) {
CachedDeserializable cd = (CachedDeserializable) ov;
Object cdV = cd.getValue();
if (cdV instanceof byte[]) {
importer.importOldBytes((byte[]) cdV, true);
} else {
importer.importOldObject(cdV, true);
}
} else {
importer.importOldObject(AbstractRegion.handleNotAvailable(ov), true);
}
}
use of org.apache.geode.internal.offheap.annotations.Unretained in project geode by apache.
the class AbstractRegionMap method setOldValueInEvent.
// PRECONDITION: caller must be synced on re
private void setOldValueInEvent(EntryEventImpl event, RegionEntry re, boolean cacheWrite, boolean requireOldValue) {
boolean needToSetOldValue = cacheWrite || requireOldValue || event.getOperation().guaranteesOldValue();
if (needToSetOldValue) {
if (event.getOperation().guaranteesOldValue()) {
// In these cases we want to even get the old value from disk if it is not in memory
ReferenceCountHelper.skipRefCountTracking();
@Released Object oldValueInVMOrDisk = re.getValueOffHeapOrDiskWithoutFaultIn(event.getLocalRegion());
ReferenceCountHelper.unskipRefCountTracking();
try {
event.setOldValue(oldValueInVMOrDisk, needToSetOldValue);
} finally {
OffHeapHelper.releaseWithNoTracking(oldValueInVMOrDisk);
}
} else {
// In these cases only need the old value if it is in memory
ReferenceCountHelper.skipRefCountTracking();
@Retained @Released Object // OFFHEAP: re
oldValueInVM = re._getValueRetain(event.getLocalRegion(), true);
// synced so can use
// its ref.
ReferenceCountHelper.unskipRefCountTracking();
try {
event.setOldValue(oldValueInVM, needToSetOldValue);
} finally {
OffHeapHelper.releaseWithNoTracking(oldValueInVM);
}
}
} else {
// if the old value is in memory then if it is a GatewaySenderEventImpl then
// we want to set the old value.
@Unretained Object // OFFHEAP _getValue is ok since re is synced and we only use it
ov = re._getValue();
// we don't need to worry about ov being compressed.
if (ov instanceof GatewaySenderEventImpl) {
event.setOldValue(ov, true);
}
}
}
Aggregations