use of org.apache.geode.internal.cache.CachedDeserializable in project geode by apache.
the class DummyQRegion method getValues.
@Override
public SelectResults getValues() {
if (values == null) {
values = new ResultsBag(((HasCachePerfStats) getRegion().getCache()).getCachePerfStats());
values.setElementType(valueType);
}
values.clear();
Object val = this.entry.getValueOffHeapOrDiskWithoutFaultIn((LocalRegion) getRegion());
if (val instanceof StoredObject) {
@Retained @Released StoredObject ohval = (StoredObject) val;
try {
val = ohval.getDeserializedValue(getRegion(), this.entry);
} finally {
ohval.release();
}
} else if (val instanceof CachedDeserializable) {
val = ((CachedDeserializable) val).getDeserializedValue(getRegion(), this.entry);
}
values.add(val);
return values;
}
use of org.apache.geode.internal.cache.CachedDeserializable in project geode by apache.
the class DummyQRegion method toArray.
@Override
public Object[] toArray() {
if (valueInArray == null) {
valueInArray = new Object[1];
}
Object val = this.entry.getValueOffHeapOrDiskWithoutFaultIn((LocalRegion) getRegion());
if (val instanceof StoredObject) {
@Retained @Released StoredObject ohval = (StoredObject) val;
try {
val = ohval.getDeserializedValue(getRegion(), this.entry);
} finally {
ohval.release();
}
} else if (val instanceof CachedDeserializable) {
val = ((CachedDeserializable) val).getDeserializedValue(getRegion(), this.entry);
}
valueInArray[0] = val;
return valueInArray;
}
use of org.apache.geode.internal.cache.CachedDeserializable in project geode by apache.
the class SerialGatewaySenderQueue method optimalGet.
/**
* Does a get that gets the value without fault values in from disk.
*/
private AsyncEvent optimalGet(Long k) {
// Get the object at that key (to remove the index).
LocalRegion lr = (LocalRegion) this.region;
Object o = null;
try {
o = lr.getValueInVMOrDiskWithoutFaultIn(k);
if (o != null && o instanceof CachedDeserializable) {
o = ((CachedDeserializable) o).getDeserializedValue(lr, lr.getRegionEntry(k));
}
} catch (EntryNotFoundException ok) {
// just return null;
}
// bug #46023 do not return a destroyed entry marker
if (o == Token.TOMBSTONE) {
o = null;
}
return (AsyncEvent) o;
}
use of org.apache.geode.internal.cache.CachedDeserializable in project geode by apache.
the class PageEntryJUnitTest method serializationReturnObjectFromCachedDeserializableValue.
@Test
public void serializationReturnObjectFromCachedDeserializableValue() throws IOException, ClassNotFoundException {
CachedDeserializable cachedDeserializable = new PreferBytesCachedDeserializable("value");
PageEntry entry = new PageEntry("key", cachedDeserializable);
assertEquals("value", copy(entry).getValue());
}
use of org.apache.geode.internal.cache.CachedDeserializable in project geode by apache.
the class StringUtilsJUnitTest method testForceToString.
@Test
public void testForceToString() throws IOException {
assertEquals("null", StringUtils.forceToString(null));
assertEquals("Object[][]", StringUtils.forceToString(new Object[0][0]));
assertEquals("byte[1, 2]", StringUtils.forceToString(new byte[] { 1, 2 }));
assertEquals("int[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]", StringUtils.forceToString(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }));
assertEquals("long[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, and 1 more]", StringUtils.forceToString(new long[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }));
assertEquals("short[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, and 2 more]", StringUtils.forceToString(new short[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }));
assertEquals("char[1, 2, 3]", StringUtils.forceToString(new char[] { '1', '2', '3' }));
assertEquals("boolean[true, false]", StringUtils.forceToString(new boolean[] { true, false }));
assertEquals("float[1.0]", StringUtils.forceToString(new float[] { 1.0f }));
assertEquals("double[1.0, 2.0]", StringUtils.forceToString(new double[] { 1.0, 2.0 }));
assertEquals("String[start, middle, end]", StringUtils.forceToString(new String[] { "start", "middle", "end" }));
// make sure CacheDeserializables do not get deserialized when getting their string form
Object v = "value";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
DataSerializer.writeObject(v, dos);
dos.flush();
byte[] valueBytes = baos.toByteArray();
CachedDeserializable cd = CachedDeserializableFactory.create(valueBytes);
assertSame(valueBytes, cd.getValue());
assertEquals("value", StringUtils.forceToString(cd));
assertSame(valueBytes, cd.getValue());
}
Aggregations