Search in sources :

Example 1 with Releasable

use of org.apache.geode.internal.offheap.Releasable in project geode by apache.

the class SearchLoadAndWriteProcessor method doNetWrite.

/** return true if a CacheWriter was actually invoked */
boolean doNetWrite(CacheEvent event, Set netWriteRecipients, CacheWriter localWriter, int paction) throws CacheWriterException, TimeoutException {
    int action = paction;
    this.requestInProgress = true;
    Scope scope = this.region.getScope();
    if (localWriter != null) {
        doLocalWrite(localWriter, event, action);
        this.requestInProgress = false;
        return true;
    }
    if (scope == Scope.LOCAL && (region.getPartitionAttributes() == null)) {
        return false;
    }
    @Released CacheEvent listenerEvent = getEventForListener(event);
    try {
        if (action == BEFOREUPDATE && listenerEvent.getOperation().isCreate()) {
            action = BEFORECREATE;
        }
        boolean cacheWrote = netWrite(listenerEvent, action, netWriteRecipients);
        this.requestInProgress = false;
        return cacheWrote;
    } finally {
        if (event != listenerEvent) {
            if (listenerEvent instanceof EntryEventImpl) {
                ((Releasable) listenerEvent).release();
            }
        }
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) Scope(org.apache.geode.cache.Scope) CacheEvent(org.apache.geode.cache.CacheEvent) Releasable(org.apache.geode.internal.offheap.Releasable)

Example 2 with Releasable

use of org.apache.geode.internal.offheap.Releasable in project geode by apache.

the class EntryEventImpl method release.

@Override
@Released({ ENTRY_EVENT_NEW_VALUE, ENTRY_EVENT_OLD_VALUE })
public void release() {
    // noop if already freed or values can not be off-heap
    if (!this.offHeapOk)
        return;
    if (!mayHaveOffHeapReferences()) {
        return;
    }
    synchronized (this.offHeapLock) {
        // Note that this method does not set the old/new values to null but
        // leaves them set to the off-heap value so that future calls to getOld/NewValue
        // will fail with an exception.
        testHookReleaseInProgress();
        Object ov = basicGetOldValue();
        Object nv = basicGetNewValue();
        this.offHeapOk = false;
        if (ov instanceof StoredObject) {
            // System.identityHashCode(ov));
            if (ReferenceCountHelper.trackReferenceCounts()) {
                ReferenceCountHelper.setReferenceCountOwner(new OldValueOwner());
                ((Releasable) ov).release();
                ReferenceCountHelper.setReferenceCountOwner(null);
            } else {
                ((Releasable) ov).release();
            }
        }
        OffHeapHelper.releaseAndTrackOwner(nv, this);
    }
}
Also used : StoredObject(org.apache.geode.internal.offheap.StoredObject) StoredObject(org.apache.geode.internal.offheap.StoredObject) Releasable(org.apache.geode.internal.offheap.Releasable) Released(org.apache.geode.internal.offheap.annotations.Released)

Example 3 with Releasable

use of org.apache.geode.internal.offheap.Releasable in project geode by apache.

the class SearchLoadAndWriteProcessor method doLocalWrite.

private boolean doLocalWrite(CacheWriter writer, CacheEvent pevent, int paction) throws CacheWriterException {
    // Return if the inhibit all notifications flag is set
    if (pevent instanceof EntryEventImpl) {
        if (((EntryEventImpl) pevent).inhibitAllNotifications()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Notification inhibited for key {}", pevent);
            }
            return false;
        }
    }
    @Released CacheEvent event = getEventForListener(pevent);
    int action = paction;
    if (event.getOperation().isCreate() && action == BEFOREUPDATE) {
        action = BEFORECREATE;
    }
    try {
        switch(action) {
            case BEFORECREATE:
                writer.beforeCreate((EntryEvent) event);
                break;
            case BEFOREDESTROY:
                writer.beforeDestroy((EntryEvent) event);
                break;
            case BEFOREUPDATE:
                writer.beforeUpdate((EntryEvent) event);
                break;
            case BEFOREREGIONDESTROY:
                writer.beforeRegionDestroy((RegionEvent) event);
                break;
            case BEFOREREGIONCLEAR:
                writer.beforeRegionClear((RegionEvent) event);
                break;
            default:
                break;
        }
    } finally {
        if (event != pevent) {
            if (event instanceof EntryEventImpl) {
                ((Releasable) event).release();
            }
        }
    }
    this.localWrite = true;
    return true;
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) CacheEvent(org.apache.geode.cache.CacheEvent) Releasable(org.apache.geode.internal.offheap.Releasable)

Aggregations

Releasable (org.apache.geode.internal.offheap.Releasable)3 Released (org.apache.geode.internal.offheap.annotations.Released)3 CacheEvent (org.apache.geode.cache.CacheEvent)2 Scope (org.apache.geode.cache.Scope)1 StoredObject (org.apache.geode.internal.offheap.StoredObject)1