Search in sources :

Example 6 with CachedDeserializable

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;
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) StoredObject(org.apache.geode.internal.offheap.StoredObject) Retained(org.apache.geode.internal.offheap.annotations.Retained) CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) HasCachePerfStats(org.apache.geode.internal.cache.HasCachePerfStats) StoredObject(org.apache.geode.internal.offheap.StoredObject) ResultsBag(org.apache.geode.cache.query.internal.ResultsBag)

Example 7 with CachedDeserializable

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;
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) StoredObject(org.apache.geode.internal.offheap.StoredObject) Retained(org.apache.geode.internal.offheap.annotations.Retained) CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) StoredObject(org.apache.geode.internal.offheap.StoredObject)

Example 8 with CachedDeserializable

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;
}
Also used : CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent)

Example 9 with CachedDeserializable

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());
}
Also used : PreferBytesCachedDeserializable(org.apache.geode.internal.cache.PreferBytesCachedDeserializable) CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) PreferBytesCachedDeserializable(org.apache.geode.internal.cache.PreferBytesCachedDeserializable) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 10 with CachedDeserializable

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());
}
Also used : CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

CachedDeserializable (org.apache.geode.internal.cache.CachedDeserializable)20 LocalRegion (org.apache.geode.internal.cache.LocalRegion)6 Test (org.junit.Test)6 StoredObject (org.apache.geode.internal.offheap.StoredObject)5 Retained (org.apache.geode.internal.offheap.annotations.Retained)5 IOException (java.io.IOException)4 UnitTest (org.apache.geode.test.junit.categories.UnitTest)4 ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)3 DataOutputStream (java.io.DataOutputStream)2 ArrayList (java.util.ArrayList)2 AttributesFactory (org.apache.geode.cache.AttributesFactory)2 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)2 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)2 Version (org.apache.geode.internal.Version)2 EventID (org.apache.geode.internal.cache.EventID)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)2 Part (org.apache.geode.internal.cache.tier.sockets.Part)2 Released (org.apache.geode.internal.offheap.annotations.Released)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1