Search in sources :

Example 6 with Unretained

use of org.apache.geode.internal.offheap.annotations.Unretained in project geode by apache.

the class GatewaySenderEventImpl method getDeserializedValue.

/**
   * Return this event's deserialized value
   * 
   * @return this event's deserialized value
   */
public Object getDeserializedValue() {
    if (this.valueIsObject == 0x00) {
        Object result = this.value;
        if (result == null) {
            @Unretained(OffHeapIdentifier.GATEWAY_SENDER_EVENT_IMPL_VALUE) Object so = this.valueObj;
            if (this.valueObjReleased) {
                throw new IllegalStateException("Value is no longer available. getDeserializedValue must be called before processEvents returns.");
            }
            if (so instanceof StoredObject) {
                return ((StoredObject) so).getValueAsDeserializedHeapObject();
            } else {
                throw new IllegalStateException("expected valueObj field to be an instance of StoredObject but it was " + so);
            }
        }
        return result;
    } else {
        Object vo = this.valueObj;
        if (vo != null) {
            if (vo instanceof StoredObject) {
                @Unretained(OffHeapIdentifier.GATEWAY_SENDER_EVENT_IMPL_VALUE) StoredObject so = (StoredObject) vo;
                return so.getValueAsDeserializedHeapObject();
            } else {
                // it is already deserialized
                return vo;
            }
        } else {
            if (this.value != null) {
                Object result = EntryEventImpl.deserialize(this.value);
                this.valueObj = result;
                return result;
            } else if (this.substituteValue != null) {
                // If the substitute value is set, return it.
                return this.substituteValue;
            } else {
                if (this.valueObjReleased) {
                    throw new IllegalStateException("Value is no longer available. getDeserializedValue must be called before processEvents returns.");
                }
                // both value and valueObj are null but we did not free it.
                return null;
            }
        }
    }
}
Also used : StoredObject(org.apache.geode.internal.offheap.StoredObject) StoredObject(org.apache.geode.internal.offheap.StoredObject) Unretained(org.apache.geode.internal.offheap.annotations.Unretained)

Example 7 with Unretained

use of org.apache.geode.internal.offheap.annotations.Unretained in project geode by apache.

the class GatewaySenderEventImpl method getSerializedValueSize.

public int getSerializedValueSize() {
    int localSerializedValueSize = this.serializedValueSize;
    if (localSerializedValueSize != DEFAULT_SERIALIZED_VALUE_SIZE) {
        return localSerializedValueSize;
    }
    @Unretained(OffHeapIdentifier.GATEWAY_SENDER_EVENT_IMPL_VALUE) Object vo = this.valueObj;
    if (vo instanceof StoredObject) {
        localSerializedValueSize = ((StoredObject) vo).getSizeInBytes();
    } else {
        if (this.substituteValue != null) {
            localSerializedValueSize = sizeOf(this.substituteValue);
        } else {
            localSerializedValueSize = CachedDeserializableFactory.calcMemSize(getSerializedValue());
        }
    }
    this.serializedValueSize = localSerializedValueSize;
    return localSerializedValueSize;
}
Also used : StoredObject(org.apache.geode.internal.offheap.StoredObject) StoredObject(org.apache.geode.internal.offheap.StoredObject) Unretained(org.apache.geode.internal.offheap.annotations.Unretained)

Example 8 with Unretained

use of org.apache.geode.internal.offheap.annotations.Unretained in project geode by apache.

the class FilterProfile method getLocalFilterRoutingForPutAllOp.

/**
   * computes FilterRoutingInfo objects for each of the given events
   */
public void getLocalFilterRoutingForPutAllOp(DistributedPutAllOperation dpao, DistributedPutAllOperation.PutAllEntryData[] putAllData) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (this.region != null && this.localProfile.hasCacheServer) {
        Set clientsInv = null;
        Set clients = null;
        int size = putAllData.length;
        CqService cqService = getCqService(dpao.getRegion());
        boolean doCQs = cqService.isRunning() && this.region != null;
        for (int idx = 0; idx < size; idx++) {
            PutAllEntryData pEntry = putAllData[idx];
            if (pEntry != null) {
                @Unretained final EntryEventImpl ev = dpao.getEventForPosition(idx);
                FilterRoutingInfo fri = pEntry.filterRouting;
                FilterInfo fi = null;
                if (fri != null) {
                    fi = fri.getLocalFilterInfo();
                }
                if (isDebugEnabled) {
                    logger.debug("Finding locally interested clients for {}", ev);
                }
                if (doCQs) {
                    if (fri == null) {
                        fri = new FilterRoutingInfo();
                    }
                    fillInCQRoutingInfo(ev, true, NO_PROFILES, fri);
                    fi = fri.getLocalFilterInfo();
                }
                if (this.allKeyClientsInv != null || this.keysOfInterestInv != null || this.patternsOfInterestInv != null || this.filtersOfInterestInv != null) {
                    clientsInv = this.getInterestedClients(ev, this.allKeyClientsInv, this.keysOfInterestInv, this.patternsOfInterestInv, this.filtersOfInterestInv);
                }
                if (this.allKeyClients != null || this.keysOfInterest != null || this.patternsOfInterest != null || this.filtersOfInterest != null) {
                    clients = this.getInterestedClients(ev, this.allKeyClients, this.keysOfInterest, this.patternsOfInterest, this.filtersOfInterest);
                }
                if (clients != null || clientsInv != null) {
                    if (fi == null) {
                        fi = new FilterInfo();
                    // no need to create or update a FilterRoutingInfo at this time
                    }
                    fi.setInterestedClients(clients);
                    fi.setInterestedClientsInv(clientsInv);
                }
                ev.setLocalFilterInfo(fi);
            }
        }
    }
}
Also used : Set(java.util.Set) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) CqService(org.apache.geode.cache.query.internal.cq.CqService) PutAllEntryData(org.apache.geode.internal.cache.DistributedPutAllOperation.PutAllEntryData) Unretained(org.apache.geode.internal.offheap.annotations.Unretained) FilterInfo(org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo)

Example 9 with Unretained

use of org.apache.geode.internal.offheap.annotations.Unretained in project geode by apache.

the class DistributedPutAllOperation method getEventForPosition.

@Unretained
public EntryEventImpl getEventForPosition(int position) {
    PutAllEntryData entry = this.putAllData[position];
    if (entry == null) {
        return null;
    }
    if (entry.event != null) {
        return entry.event;
    }
    LocalRegion region = (LocalRegion) this.event.getRegion();
    @Retained EntryEventImpl ev = EntryEventImpl.create(region, entry.getOp(), entry.getKey(), null, /* value */
    this.event.getCallbackArgument(), false, /* originRemote */
    this.event.getDistributedMember(), this.event.isGenerateCallbacks(), entry.getEventID());
    boolean returnedEv = false;
    try {
        ev.setPossibleDuplicate(entry.isPossibleDuplicate());
        if (entry.versionTag != null && region.concurrencyChecksEnabled) {
            VersionSource id = entry.versionTag.getMemberID();
            if (id != null) {
                entry.versionTag.setMemberID(ev.getRegion().getVersionVector().getCanonicalId(id));
            }
            ev.setVersionTag(entry.versionTag);
        }
        entry.event = ev;
        returnedEv = true;
        if (entry.getValue() == null && ev.getRegion().getAttributes().getDataPolicy() == DataPolicy.NORMAL) {
            ev.setLocalInvalid(true);
        }
        ev.setNewValue(entry.getValue());
        ev.setOldValue(entry.getOldValue());
        CqService cqService = region.getCache().getCqService();
        if (cqService.isRunning() && !entry.getOp().isCreate() && !ev.hasOldValue()) {
            ev.setOldValueForQueryProcessing();
        }
        ev.setInvokePRCallbacks(!entry.isNotifyOnly());
        if (getBaseEvent().getContext() != null) {
            ev.setContext(getBaseEvent().getContext());
        }
        ev.callbacksInvoked(entry.isCallbacksInvoked());
        ev.setTailKey(entry.getTailKey());
        return ev;
    } finally {
        if (!returnedEv) {
            ev.release();
        }
    }
}
Also used : Retained(org.apache.geode.internal.offheap.annotations.Retained) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) CqService(org.apache.geode.cache.query.internal.cq.CqService) Unretained(org.apache.geode.internal.offheap.annotations.Unretained)

Example 10 with Unretained

use of org.apache.geode.internal.offheap.annotations.Unretained in project geode by apache.

the class EntryEventImpl method exportNewValue.

/**
   * Export the event's new value to the given importer.
   */
public void exportNewValue(NewValueImporter importer) {
    final boolean prefersSerialized = importer.prefersNewSerialized();
    if (prefersSerialized) {
        if (getCachedSerializedNewValue() != null) {
            importer.importNewBytes(getCachedSerializedNewValue(), true);
            return;
        } else if (this.newValueBytes != null && this.newValue instanceof CachedDeserializable) {
            importer.importNewBytes(this.newValueBytes, true);
            return;
        }
    }
    @Unretained(ENTRY_EVENT_NEW_VALUE) final Object nv = getRawNewValue();
    if (nv instanceof StoredObject) {
        @Unretained(ENTRY_EVENT_NEW_VALUE) final StoredObject so = (StoredObject) nv;
        final boolean isSerialized = so.isSerialized();
        if (importer.isUnretainedNewReferenceOk()) {
            importer.importNewObject(nv, isSerialized);
        } else if (!isSerialized || prefersSerialized) {
            byte[] bytes = so.getValueAsHeapByteArray();
            importer.importNewBytes(bytes, isSerialized);
            if (isSerialized) {
                setCachedSerializedNewValue(bytes);
            }
        } else {
            importer.importNewObject(so.getValueAsDeserializedHeapObject(), true);
        }
    } else if (nv instanceof byte[]) {
        importer.importNewBytes((byte[]) nv, false);
    } else if (nv instanceof CachedDeserializable) {
        CachedDeserializable cd = (CachedDeserializable) nv;
        Object cdV = cd.getValue();
        if (cdV instanceof byte[]) {
            importer.importNewBytes((byte[]) cdV, true);
            setCachedSerializedNewValue((byte[]) cdV);
        } else {
            importer.importNewObject(cdV, true);
        }
    } else {
        importer.importNewObject(nv, true);
    }
}
Also used : StoredObject(org.apache.geode.internal.offheap.StoredObject) StoredObject(org.apache.geode.internal.offheap.StoredObject) Unretained(org.apache.geode.internal.offheap.annotations.Unretained)

Aggregations

Unretained (org.apache.geode.internal.offheap.annotations.Unretained)17 StoredObject (org.apache.geode.internal.offheap.StoredObject)12 HashSet (java.util.HashSet)4 Set (java.util.Set)4 CqService (org.apache.geode.cache.query.internal.cq.CqService)4 Retained (org.apache.geode.internal.offheap.annotations.Retained)4 IOException (java.io.IOException)2 AbstractSet (java.util.AbstractSet)2 EnumSet (java.util.EnumSet)2 Iterator (java.util.Iterator)2 TreeSet (java.util.TreeSet)2 CopyOnWriteHashSet (org.apache.geode.internal.CopyOnWriteHashSet)2 FilterInfo (org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo)2 VersionSource (org.apache.geode.internal.cache.versions.VersionSource)2 org.apache.geode (org.apache.geode)1 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)1 PutAllEntryData (org.apache.geode.internal.cache.DistributedPutAllOperation.PutAllEntryData)1 RemoveAllEntryData (org.apache.geode.internal.cache.DistributedRemoveAllOperation.RemoveAllEntryData)1 Token (org.apache.geode.internal.cache.Token)1 LockObject (org.apache.geode.internal.cache.partitioned.LockObject)1