public static ValueWrapper createValueWrapperFromEntry(DiskEntry entry, InternalRegion region, EntryEventImpl event) { if (event != null) { // For off-heap it should be faster to pass a reference to the // StoredObject instead of using the cached byte[] (unless it is also compressed). // Since NIO is used if the chunk of memory is large we can write it // to the file using the off-heap memory with no extra copying. // So we give preference to getRawNewValue over getCachedSerializedNewValue Object rawValue = null; { rawValue = event.getRawNewValue(); if (wrapOffHeapReference(rawValue)) { return new OffHeapValueWrapper((StoredObject) rawValue); } } if (event.getCachedSerializedNewValue() != null) { return new ByteArrayValueWrapper(true, event.getCachedSerializedNewValue()); } if (rawValue != null) { return createValueWrapper(rawValue, event); } } @Retained Object value = entry.getValueRetain(region, true); try { return createValueWrapper(value, event); } finally { OffHeapHelper.release(value); } }
} else { Assert.assertTrue(!Token.isRemovedFromDisk(value)); if (event != null && event.getCachedSerializedNewValue() != null) { bytes = event.getCachedSerializedNewValue(); } else { bytes = EntryEventImpl.serialize(value);
this.valueIsObject = 0x00; } else if (event.getCachedSerializedNewValue() != null) { this.value = event.getCachedSerializedNewValue(); } else { final Object newValue = event.getRawNewValue();
@Test public void whenPrepareValueForCacheCalledWithOffHeapEntryHasNewCachedSerializedValue() throws RegionClearedException, IOException, ClassNotFoundException { LocalRegion lr = mock(LocalRegion.class); RegionEntryContext regionEntryContext = mock(RegionEntryContext.class); OutOfOffHeapMemoryListener ooohml = mock(OutOfOffHeapMemoryListener.class); OffHeapMemoryStats stats = mock(OffHeapMemoryStats.class); SlabImpl slab = new SlabImpl(1024); // 1k MemoryAllocatorImpl ma = MemoryAllocatorImpl.createForUnitTest(ooohml, stats, new SlabImpl[] {slab}); try { when(regionEntryContext.getOffHeap()).thenReturn(true); String value = "value"; AbstractRegionEntry re = new TestableRegionEntry(lr, value); assertEquals(value, re.getValueField()); EntryEventImpl entryEvent = new EntryEventImpl(); StoredObject valueForCache = (StoredObject) re.prepareValueForCache(regionEntryContext, value, entryEvent, true); final byte[] cachedSerializedNewValue = entryEvent.getCachedSerializedNewValue(); assertNotNull(cachedSerializedNewValue); valueForCache.checkDataEquals(cachedSerializedNewValue); DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(cachedSerializedNewValue)); Object o = DataSerializer.readObject(dataInputStream); assertEquals(o, value); } finally { MemoryAllocatorImpl.freeOffHeapMemory(); } }
long time = context.getCachePerfStats().startCompression(); byte[] serializedValue; if (event != null && event.getCachedSerializedNewValue() != null) { serializedValue = event.getCachedSerializedNewValue(); if (value instanceof CachedDeserializable) { CachedDeserializable cd = (CachedDeserializable) value;
boolean isSerialized = !(val instanceof byte[]); if (isSerialized) { if (event != null && event.getCachedSerializedNewValue() != null) { data = event.getCachedSerializedNewValue(); } else { if (val instanceof CachedDeserializable) {
final boolean prefersSerialized = importer.prefersNewSerialized(); if (prefersSerialized) { byte[] serializedNewValue = getCachedSerializedNewValue(); if (serializedNewValue == null) { serializedNewValue = this.newValueBytes;