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());
}
}
}
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);
}
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();
}
}
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);
}
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();
}
}
Aggregations