Search in sources :

Example 1 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 2 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 3 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 4 with CachedDeserializable

use of org.apache.geode.internal.cache.CachedDeserializable in project geode by apache.

the class Get70 method getEntryRetained.

/**
   * Same as getValueAndIsObject but the returned value can be a retained off-heap reference.
   */
@Retained
public Entry getEntryRetained(Region region, Object key, Object callbackArg, ServerConnection servConn) {
    // Region.Entry entry;
    String regionName = region.getFullPath();
    if (servConn != null) {
        servConn.setModificationInfo(true, regionName, key);
    }
    VersionTag versionTag = null;
    // LocalRegion lregion = (LocalRegion)region;
    // entry = lregion.getEntry(key, true);
    boolean isObject = true;
    @Retained Object data = null;
    ClientProxyMembershipID id = servConn == null ? null : servConn.getProxyID();
    VersionTagHolder versionHolder = new VersionTagHolder();
    data = ((LocalRegion) region).getRetained(key, callbackArg, true, true, id, versionHolder, true);
    versionTag = versionHolder.getVersionTag();
    // If it is Token.REMOVED, Token.DESTROYED,
    // Token.INVALID, or Token.LOCAL_INVALID
    // set it to null. If it is NOT_AVAILABLE, get the value from
    // disk. If it is already a byte[], set isObject to false.
    boolean wasInvalid = false;
    if (data == Token.REMOVED_PHASE1 || data == Token.REMOVED_PHASE2 || data == Token.DESTROYED) {
        data = null;
    } else if (data == Token.INVALID || data == Token.LOCAL_INVALID) {
        // fix for bug 35884
        data = null;
        wasInvalid = true;
    } else if (data instanceof byte[]) {
        isObject = false;
    } else if (data instanceof CachedDeserializable) {
        CachedDeserializable cd = (CachedDeserializable) data;
        isObject = cd.isSerialized();
        if (cd.usesHeapForStorage()) {
            data = cd.getValue();
        }
    }
    Entry result = new Entry();
    result.value = data;
    result.isObject = isObject;
    result.keyNotPresent = !wasInvalid && (data == null || data == Token.TOMBSTONE);
    result.versionTag = versionTag;
    return result;
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) Retained(org.apache.geode.internal.offheap.annotations.Retained) VersionTagHolder(org.apache.geode.internal.cache.VersionTagHolder) CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Retained(org.apache.geode.internal.offheap.annotations.Retained)

Example 5 with CachedDeserializable

use of org.apache.geode.internal.cache.CachedDeserializable in project geode by apache.

the class PutAllOperationContextJUnitTest method testCachedDeserializable.

/**
   * Make sure that we do not expose the internal CachedDeserializable to customers
   */
@Test
public void testCachedDeserializable() {
    LinkedHashMap<String, Object> m = new LinkedHashMap<>();
    Object v = Integer.valueOf(99);
    CachedDeserializable cd = CachedDeserializableFactory.create(v, 24);
    m.put("cd", cd);
    PutAllOperationContext paoc = new PutAllOperationContext(m);
    Map<String, Object> opMap = paoc.getMap();
    assertEquals(1, opMap.size());
    assertEquals(true, opMap.containsKey("cd"));
    assertEquals(v, opMap.get("cd"));
    assertEquals(true, opMap.containsValue(v));
    assertEquals(false, opMap.containsValue("junk"));
    Collection<Object> values = opMap.values();
    assertEquals(1, values.size());
    assertEquals(v, values.iterator().next());
    Set<Map.Entry<String, Object>> entries = opMap.entrySet();
    assertEquals(1, entries.size());
    Map.Entry me = entries.iterator().next();
    assertEquals("cd", me.getKey());
    assertEquals(v, me.getValue());
    assertEquals(cd, m.get("cd"));
    String opMapStr = opMap.toString();
    assertEquals("expected " + opMapStr + " to not contain CachedDeserializable", false, opMapStr.contains("CachedDeserializable"));
    HashMap<String, Object> hm = new HashMap<>(opMap);
    assertEquals(hm, opMap);
    assertEquals(opMap, hm);
    assertEquals(hm.hashCode(), opMap.hashCode());
}
Also used : CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) PutAllOperationContext(org.apache.geode.cache.operations.PutAllOperationContext) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

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