static Object readSerializedValue(byte[] valueBytes, Version version, ByteArrayDataInput in, boolean forceDeserialize) { if (forceDeserialize) { // deserialize checking for product version change return EntryEventImpl.deserialize(valueBytes, version, in); } else { // TODO: upgrades: is there a case where GemFire values are internal // ones that need to be upgraded transparently; probably messages // being persisted (gateway events?) return CachedDeserializableFactory.create(valueBytes); } }
static Object readSerializedValue(byte[] valueBytes, Version version, ByteArrayDataInput in, boolean forceDeserialize) { if (forceDeserialize || CachedDeserializableFactory.preferObject()) { // deserialize checking for product version change return EntryEventImpl.deserialize(valueBytes, version, in); } else { // TODO: upgrades: is there a case where GemFire values are internal // ones that need to be upgraded transparently; probably messages // being persisted (gateway events?) return CachedDeserializableFactory.create(valueBytes); } }
/** * Create one of these in the local case so that we have a snapshot of the state * and can allow the bucket to move out from under us. */ protected NonLocalRegionEntry(Object key, Object value, LocalRegion br, VersionTag<?> versionTag) { this.key = key; this.value = value; if (this.value instanceof CachedDeserializable) { // We make a copy of the CachedDeserializable. // That way the NonLocalRegionEntry will be disconnected // from the CachedDeserializable that is in our cache and // will not modify its state. this.value = CachedDeserializableFactory.create((CachedDeserializable)this.value); } Assert.assertTrue(this.value != Token.NOT_AVAILABLE, "getEntry did not fault value in from disk"); this.lastModified = 0l;//re.getStatistics().getLastModifiedTime(); this.isRemoved = Token.isRemoved(value); // TODO need to get version information from transaction entries this.versionTag = versionTag; }
static Object readSerializedValue(BytesAndBits value, boolean forceDeserialize) { if (forceDeserialize || CachedDeserializableFactory.preferObject()) { // deserialize checking for product version change return value.deserialize(); } else { // TODO: upgrades: is there a case where GemFire values are internal // ones that need to be upgraded transparently; probably messages // being persisted (gateway events?) return CachedDeserializableFactory.create(value.toBytes()); } }
public static Object encodedAddressToObject(long addr, boolean decompress, boolean deserialize) { boolean isSerialized = (addr & SERIALIZED_BIT) != 0; byte[] bytes = encodedAddressToBytes(addr, decompress); if (isSerialized) { if (deserialize || CachedDeserializableFactory.preferObject()) { return EntryEventImpl.deserialize(bytes); } else { return CachedDeserializableFactory.create(bytes); } } else { return bytes; } }
public void setSerializedOldValue(byte[] serializedOldValue){ this.oldValueBytes = serializedOldValue; final Object ov; if (CachedDeserializableFactory.preferObject()) { ov = deserialize(serializedOldValue); } else if (serializedOldValue != null) { ov = CachedDeserializableFactory.create(serializedOldValue); } else { ov = null; } retainAndSetOldValue(ov); }
public final void setSerializedOldValue(byte[] serializedOldValue) { this.oldValueBytes = serializedOldValue; final Object ov; if (CachedDeserializableFactory.preferObject()) { ov = deserialize(serializedOldValue); } else if (serializedOldValue != null) { ov = CachedDeserializableFactory.create(serializedOldValue); } else { ov = null; } retainAndSetOldValue(ov); }
@Override public void run() { Region<String,Object> region = getCache().getRegion(REGION_NAME); String oldValue = (String) region.put(KEY_1, CachedDeserializableFactory.create(EntryEventImpl.serialize(VALUE_1))); assertNull(oldValue); assertEquals(VALUE_1,oldValue); oldValue = (String) region.put(KEY_1, CachedDeserializableFactory.create(EntryEventImpl.serialize(VALUE_2))); if(null != oldValue) { assertEquals(VALUE_1,oldValue); assertEquals(VALUE_2,oldValue); oldValue = (String) region.putIfAbsent(KEY_1, CachedDeserializableFactory.create(EntryEventImpl.serialize(VALUE_3))); assertEquals(VALUE_2,oldValue);
private static Object getCachedDeserializable(Object obj, EntryEventImpl ev) { if (CachedDeserializableFactory.preferObject() || obj instanceof byte[] || obj == null || obj instanceof CachedDeserializable || obj == Token.NOT_AVAILABLE || Token.isInvalidOrRemoved(obj) // don't serialize delta object already serialized || obj instanceof com.gemstone.gemfire.Delta || obj instanceof Delta) { // internal delta return obj; } final byte[] b = serialize(obj); final CachedDeserializable cd = CachedDeserializableFactory.create(b); if (ev != null) { ev.newValueBytes = b; } return cd; }
public final void setSerializedNewValue(byte[] serializedValue) { Object newVal = null; if (serializedValue != null) { if (CachedDeserializableFactory.preferObject()) { newVal = deserialize(serializedValue); } else { newVal = CachedDeserializableFactory.create(serializedValue); } if (newVal instanceof Delta) { this.delta = (Delta)newVal; newVal = null; // We need the newValueBytes field and the newValue field to be in sync. // In the case of non-null delta set both fields to null. serializedValue = null; } } this.newValueBytes = serializedValue; basicSetNewValue(newVal); this.cachedSerializedNewValue = serializedValue; }
public final void setSerializedNewValue(byte[] serializedValue) { Object newVal = null; this.delta = null; if (serializedValue != null) { if (CachedDeserializableFactory.preferObject()) { newVal = deserialize(serializedValue); } else { newVal = CachedDeserializableFactory.create(serializedValue); } if (newVal instanceof Delta) { this.delta = (Delta)newVal; newVal = null; // We need the newValueBytes field and the newValue field to be in sync. // In the case of non-null delta set both fields to null. serializedValue = null; } } this.newValueBytes = serializedValue; basicSetNewValue(newVal); }
byte[] compressedData = compressBytes(r, data); if (data == compressedData) { nv = CachedDeserializableFactory.create(data); } else { nv = compressedData;
public void fromData(DataInput in) throws IOException, ClassNotFoundException { this.op = Operation.fromOrdinal(in.readByte()); this.flags = in.readByte(); if (getFlag(VALUE_IS_BYTE_ARRAY)) { this.valueObject = DataSerializer.readByteArray(in); } else if (getFlag(VALUE_IS_OBJECT)) { byte[] newValueBytes = DataSerializer.readByteArray(in); if(newValueBytes == null) { this.valueObject = null; } else { if(CachedDeserializableFactory.preferObject()) { this.valueObject = EntryEventImpl.deserialize(newValueBytes); } else { this.valueObject = CachedDeserializableFactory.create(newValueBytes); } } } else { this.valueObject = DataSerializer.readObject(in); } }
public void fromData(DataInput in) throws IOException, ClassNotFoundException { this.op = Operation.fromOrdinal(in.readByte()); this.flags = in.readByte(); if (getFlag(VALUE_IS_BYTE_ARRAY)) { this.valueObject = DataSerializer.readByteArray(in); } else if (getFlag(VALUE_IS_OBJECT)) { byte[] newValueBytes = DataSerializer.readByteArray(in); if(newValueBytes == null) { this.valueObject = null; } else { if(CachedDeserializableFactory.preferObject()) { this.valueObject = EntryEventImpl.deserialize(newValueBytes); } else { this.valueObject = CachedDeserializableFactory.create(newValueBytes); } } } else { this.valueObject = DataSerializer.readObject(in); } }
@Override public void sendTo(DataOutput out) throws IOException { Object objToSend; if (CachedDeserializableFactory.preferObject()) { objToSend = getValueAsDeserializedHeapObject(); } else if (isSerialized()) { objToSend = CachedDeserializableFactory.create(getSerializedValue()); // deserialized as a cd } else { objToSend = (byte[]) getDeserializedForReading(); // deserialized as a byte[] } DataSerializer.writeObject(objToSend, out); } public boolean checkDataEquals(@Unretained OffHeapCachedDeserializable other) {
@Override public void sendTo(DataOutput out) throws IOException { Object objToSend; if (CachedDeserializableFactory.preferObject()) { objToSend = getValueAsDeserializedHeapObject(); } else if (isSerialized()) { // Another option is to directly write the bytes to out which would cause it // to be deserialized as the domain object instead of a cd. objToSend = CachedDeserializableFactory.create(getSerializedValue()); // deserialized as a cd } else { objToSend = getDeserializedForReading(); // deserialized as a byte[] } DataSerializer.writeObject(objToSend, out); }
/** * If v is on heap then just return v; no copy needed. * Else v is off-heap so copy it to heap and return a reference to the heap copy. * Note that unlike {@link #getHeapForm(Object)} if v is a serialized off-heap object it will be copied to the heap as a CachedDeserializable. * If you prefer to have the serialized object also deserialized and copied to the heap use {@link #getHeapForm(Object)}. * * @param v possible OFF_HEAP_REFERENCE * @return v or a heap copy of v */ public static Object copyIfNeeded(@Unretained Object v) { if (v instanceof StoredObject) { @Unretained StoredObject ohv = (StoredObject) v; if (ohv.isSerialized()) { v = CachedDeserializableFactory.create(ohv.getSerializedValue()); } else { // it is a byte[] v = ohv.getDeserializedForReading(); } } return v; }
/** * Create one of these in the local case so that we have a snapshot of the state * and can allow the bucket to move out from under us. */ public NonLocalRegionEntry(Region.Entry re, LocalRegion br) { this.key = re.getKey(); this.value = re.getValue(); if (this.value instanceof CachedDeserializable) { // We make a copy of the CachedDeserializable. // That way the NonLocalRegionEntry will be disconnected // from the CachedDeserializable that is in our cache and // will not modify its state. this.value = CachedDeserializableFactory.create((CachedDeserializable)this.value); } Assert.assertTrue(this.value != Token.NOT_AVAILABLE, "getEntry did not fault value in from disk"); this.lastModified = 0l;//re.getStatistics().getLastModifiedTime(); this.isRemoved = Token.isRemoved(value); if (re instanceof EntrySnapshot) { this.versionTag = ((EntrySnapshot)re).getVersionTag(); } else { // TODO need to get version information from transaction entries } }
/** * Just like {@link #copyIfNeeded(Object)} except that if off-heap is copied it is also released. * @param v If this value is off-heap then the caller must have already retained it. * @return the heap copy to use in place of v */ public static Object copyAndReleaseIfNeeded(@Released Object v) { if (v instanceof StoredObject) { @Unretained StoredObject ohv = (StoredObject) v; try { if (ohv.isSerialized()) { return CachedDeserializableFactory.create(ohv.getSerializedValue()); } else { // it is a byte[] return ohv.getDeserializedForReading(); } } finally { ohv.release(); } } else { return v; } }
/** * If v is on heap then just return v; no copy needed. * Else if v is an off-heap gfxd byte[] or byte[][] then just return v; no copy needed. * Else v is off-heap so copy it to heap and return a reference to the heap copy. * Note that unlike {@link #getHeapForm(Object)} if v is a serialized off-heap object it will be copied to the heap as a CachedDeserializable. * If you prefer to have the serialized object also deserialized and copied to the heap use {@link #getHeapForm(Object)} but it will also copy gfxd byte[] and byte[][] to the heap. * * @param v possible OFF_HEAP_REFERENCE * @return possible OFF_HEAP_REFERENCE if gfxd. */ @Unretained public static Object copyIfNeeded(@Unretained Object v) { if (v instanceof StoredObject) { @Unretained StoredObject ohv = (StoredObject) v; if (CachedDeserializableFactory.preferObject()) { // in some cases getDeserializeValue just returns ohv v = ohv.getDeserializedValue(null, null); } else if (ohv.isSerialized()) { v = CachedDeserializableFactory.create(ohv.getSerializedValue()); } else { // it is a byte[] v = ohv.getDeserializedForReading(); } } return v; }