Search in sources :

Example 1 with GatewaySenderEventCallbackArgument

use of org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument in project geode by apache.

the class GatewayDeltaEventApplicationCacheListener method afterCreate.

public void afterCreate(EntryEvent<String, GatewayDeltaEvent> event) {
    System.out.println("GatewayDeltaApplierCacheListener event: " + event);
    EntryEventImpl eventImpl = (EntryEventImpl) event;
    if (this.cache.getLogger().fineEnabled()) {
        StringBuilder builder = new StringBuilder();
        builder.append("GatewayDeltaApplierCacheListener: Received event for ").append(event.getKey()).append("->").append(event.getNewValue()).append(".");
        this.cache.getLogger().fine(builder.toString());
    }
    // If the event is from a remote site, apply it to the session
    Object callbackArgument = eventImpl.getRawCallbackArgument();
    System.out.println("GatewayDeltaApplierCacheListener callbackArgument: " + callbackArgument);
    if (callbackArgument instanceof GatewaySenderEventCallbackArgument) {
        GatewayDeltaEvent delta = event.getNewValue();
        delta.apply(this.cache);
        System.out.println("Applied " + delta);
        if (this.cache.getLogger().fineEnabled()) {
            StringBuilder builder = new StringBuilder();
            builder.append("GatewayDeltaApplierCacheListener: Applied ").append(delta);
            this.cache.getLogger().fine(builder.toString());
        }
    }
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) GatewaySenderEventCallbackArgument(org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument)

Example 2 with GatewaySenderEventCallbackArgument

use of org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument in project geode by apache.

the class LocalRegion method basicBridgeDestroyRegion.

// TODO: fromClient is always true
public void basicBridgeDestroyRegion(Object callbackArg, final ClientProxyMembershipID client, boolean fromClient, EventID eventId) throws TimeoutException, EntryExistsException, CacheWriterException {
    if (fromClient) {
        // GatewayEventCallbackArgument to store the event id.
        if (isGatewaySenderEnabled()) {
            callbackArg = new GatewaySenderEventCallbackArgument(callbackArg);
        }
    }
    RegionEventImpl event = new ClientRegionEventImpl(this, Operation.REGION_DESTROY, callbackArg, false, client.getDistributedMember(), client, eventId);
    basicDestroyRegion(event, true);
}
Also used : GatewaySenderEventCallbackArgument(org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument)

Example 3 with GatewaySenderEventCallbackArgument

use of org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument in project geode by apache.

the class LocalRegion method basicBridgePutIfAbsent.

// TODO: fromClient is always null
public Object basicBridgePutIfAbsent(final Object key, Object value, boolean isObject, Object callbackArg, final ClientProxyMembershipID client, boolean fromClient, EntryEventImpl clientEvent) throws TimeoutException, EntryExistsException, CacheWriterException {
    EventID eventId = clientEvent.getEventId();
    long startPut = CachePerfStats.getStatTime();
    if (fromClient) {
        // GatewayEventCallbackArgument to store the event id.
        if (isGatewaySenderEnabled()) {
            callbackArg = new GatewaySenderEventCallbackArgument(callbackArg);
        }
    }
    @Released final EntryEventImpl event = EntryEventImpl.create(this, Operation.PUT_IF_ABSENT, key, null, callbackArg, false, client.getDistributedMember(), true, eventId);
    try {
        event.setContext(client);
        // if this is a replayed operation we may already have a version tag
        event.setVersionTag(clientEvent.getVersionTag());
        // Set the new value to the input byte[] if it isn't null
        if (value != null) {
            // in a CachedDeserializable; otherwise store it directly as a byte[]
            if (isObject) {
                // The value represents an object
                event.setSerializedNewValue((byte[]) value);
            } else {
                // The value does not represent an object
                event.setNewValue(value);
            }
        }
        validateArguments(key, event.basicGetNewValue(), callbackArg);
        // cannot overwrite an existing key
        boolean ifNew = true;
        // can create a new key
        boolean ifOld = false;
        // need the old value if the create fails
        boolean requireOldValue = true;
        boolean basicPut = basicPut(event, ifNew, ifOld, null, requireOldValue);
        getCachePerfStats().endPut(startPut, false);
        this.stopper.checkCancelInProgress(null);
        // to fix bug 42968 call getRawOldValue instead of getOldValue
        Object oldValue = event.getRawOldValueAsHeapObject();
        if (oldValue == Token.NOT_AVAILABLE) {
            oldValue = AbstractRegion.handleNotAvailable(oldValue);
        }
        if (basicPut) {
            clientEvent.setVersionTag(event.getVersionTag());
            clientEvent.isConcurrencyConflict(event.isConcurrencyConflict());
        } else if (oldValue == null) {
            // this case from successful operation
            return Token.INVALID;
        }
        return oldValue;
    } finally {
        event.release();
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) StoredObject(org.apache.geode.internal.offheap.StoredObject) GatewaySenderEventCallbackArgument(org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument)

Example 4 with GatewaySenderEventCallbackArgument

use of org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument in project geode by apache.

the class LocalRegion method basicBridgeClear.

public void basicBridgeClear(Object callbackArg, final ClientProxyMembershipID client, boolean fromClient, EventID eventId) throws TimeoutException, EntryExistsException, CacheWriterException {
    if (fromClient) {
        // GatewayEventCallbackArgument to store the event id.
        if (isGatewaySenderEnabled()) {
            callbackArg = new GatewaySenderEventCallbackArgument(callbackArg);
        }
    }
    RegionEventImpl event = new ClientRegionEventImpl(this, Operation.REGION_CLEAR, callbackArg, false, client.getDistributedMember(), client, eventId);
    basicClear(event, true);
}
Also used : GatewaySenderEventCallbackArgument(org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument)

Example 5 with GatewaySenderEventCallbackArgument

use of org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument in project geode by apache.

the class LocalRegion method basicBridgeCreate.

public boolean basicBridgeCreate(final Object key, final byte[] value, boolean isObject, Object callbackArg, final ClientProxyMembershipID client, boolean fromClient, EntryEventImpl clientEvent, boolean throwEntryExists) throws TimeoutException, EntryExistsException, CacheWriterException {
    EventID eventId = clientEvent.getEventId();
    Object theCallbackArg = callbackArg;
    long startPut = CachePerfStats.getStatTime();
    if (fromClient) {
        // GatewayEventCallbackArgument to store the event id.
        if (isGatewaySenderEnabled()) {
            theCallbackArg = new GatewaySenderEventCallbackArgument(theCallbackArg);
        }
    }
    @Released final EntryEventImpl event = EntryEventImpl.create(this, Operation.CREATE, key, value, theCallbackArg, false, /* origin remote */
    client.getDistributedMember(), true, /* generateCallbacks */
    eventId);
    try {
        event.setContext(client);
        // if this is a replayed operation or WAN event we may already have a version tag
        event.setVersionTag(clientEvent.getVersionTag());
        // carry over the possibleDuplicate flag from clientEvent
        event.setPossibleDuplicate(clientEvent.isPossibleDuplicate());
        // normal regions. Otherwise, it will become a distributed invalidate.
        if (getDataPolicy() == DataPolicy.NORMAL) {
            event.setLocalInvalid(true);
        }
        // Set the new value to the input byte[] if it isn't null
        if (value != null) {
            // in a CachedDeserializable; otherwise store it directly as a byte[]
            if (isObject) {
                // The value represents an object
                event.setSerializedNewValue(value);
            } else {
                // The value does not represent an object
                event.setNewValue(value);
            }
        }
        // cannot overwrite an existing key
        boolean ifNew = true;
        // can create a new key
        boolean ifOld = false;
        // use now
        long lastModified = 0L;
        // not okay to overwrite the DESTROYED token
        boolean overwriteDestroyed = false;
        boolean success = basicUpdate(event, ifNew, ifOld, lastModified, overwriteDestroyed);
        clientEvent.isConcurrencyConflict(event.isConcurrencyConflict());
        if (success) {
            clientEvent.setVersionTag(event.getVersionTag());
            getCachePerfStats().endPut(startPut, event.isOriginRemote());
        } else {
            this.stopper.checkCancelInProgress(null);
            if (throwEntryExists) {
                throw new EntryExistsException("" + key, event.getOldValue());
            }
        }
        return success;
    } finally {
        event.release();
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) StoredObject(org.apache.geode.internal.offheap.StoredObject) EntryExistsException(org.apache.geode.cache.EntryExistsException) GatewaySenderEventCallbackArgument(org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument)

Aggregations

GatewaySenderEventCallbackArgument (org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument)13 Released (org.apache.geode.internal.offheap.annotations.Released)9 StoredObject (org.apache.geode.internal.offheap.StoredObject)6 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)2 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)2 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 CacheException (org.apache.geode.cache.CacheException)1 EntryExistsException (org.apache.geode.cache.EntryExistsException)1 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)1 EventID (org.apache.geode.internal.cache.EventID)1 EventWrapper (org.apache.geode.internal.cache.wan.AbstractGatewaySender.EventWrapper)1 GatewaySenderEventImpl (org.apache.geode.internal.cache.wan.GatewaySenderEventImpl)1 GatewaySenderStats (org.apache.geode.internal.cache.wan.GatewaySenderStats)1