private void givenPutNeedsToDoCacheWrite() { when(event.isGenerateCallbacks()).thenReturn(true); when(internalRegion.getScope()).thenReturn(Scope.DISTRIBUTED_ACK); }
private void givenPutDoesNotNeedToDoCacheWrite() { when(event.isGenerateCallbacks()).thenReturn(false); when(internalRegion.getScope()).thenReturn(Scope.DISTRIBUTED_ACK); }
@Test public void isOriginRemoteCausesCacheWriteToBeFalse() { when(event.isOriginRemote()).thenReturn(true); when(event.isGenerateCallbacks()).thenReturn(true); when(internalRegion.basicGetWriter()).thenReturn(mock(CacheWriter.class)); createInstance(); assertThat(instance.isCacheWrite()).isFalse(); }
@Test public void netSearchCausesCacheWriteToBeFalse() { when(event.isNetSearch()).thenReturn(true); when(event.isGenerateCallbacks()).thenReturn(true); when(internalRegion.basicGetWriter()).thenReturn(mock(CacheWriter.class)); createInstance(); assertThat(instance.isCacheWrite()).isFalse(); }
@Test public void cacheWriteIsFalseIfGenerateCallbacksButNotDistributedEtc() { when(event.isGenerateCallbacks()).thenReturn(true); createInstance(); assertThat(instance.isCacheWrite()).isFalse(); }
@Test public void cacheWriteIsTrueIfGenerateCallbacksAndCacheWriter() { when(event.isGenerateCallbacks()).thenReturn(true); when(internalRegion.basicGetWriter()).thenReturn(mock(CacheWriter.class)); createInstance(); assertThat(instance.isCacheWrite()).isTrue(); }
@Test public void cacheWriteIsTrueIfGenerateCallbacksAndDistributed() { when(event.isGenerateCallbacks()).thenReturn(true); when(internalRegion.getScope()).thenReturn(Scope.DISTRIBUTED_ACK); createInstance(); assertThat(instance.isCacheWrite()).isTrue(); }
@Test public void cacheWriteIsTrueIfGenerateCallbacksAndServerProxy() { when(event.isGenerateCallbacks()).thenReturn(true); when(internalRegion.hasServerProxy()).thenReturn(true); createInstance(); assertThat(instance.isCacheWrite()).isTrue(); }
public static PutAllResponse send(DistributedMember recipient, EntryEventImpl event, PutAllEntryData[] putAllData, int putAllDataCount, boolean useOriginRemote, boolean possibleDuplicate) throws RemoteOperationException { PutAllResponse p = new PutAllResponse(event.getRegion().getSystem(), recipient); RemotePutAllMessage msg = new RemotePutAllMessage(event, recipient, p, putAllData, putAllDataCount, useOriginRemote, possibleDuplicate, !event.isGenerateCallbacks()); Set<?> failures = event.getRegion().getDistributionManager().putOutgoing(msg); if (failures != null && failures.size() > 0) { throw new RemoteOperationException( String.format("Failed sending < %s >", msg)); } return p; }
@Override public void basicPutPart3(EntryEventImpl event, RegionEntry entry, boolean isInitialized, long lastModified, boolean invokeCallbacks, boolean ifNew, boolean ifOld, Object expectedOldValue, boolean requireOldValue) { super.basicPutPart3(event, entry, isInitialized, lastModified, invokeCallbacks, ifNew, ifOld, expectedOldValue, requireOldValue); // this code is copied from LocalRegion.basicPutPart2 invokeCallbacks &= !entry.isTombstone(); // put() is creating a tombstone if (invokeCallbacks) { boolean doCallback = false; if (isInitialized) { if (event.isGenerateCallbacks()) { doCallback = true; } } if (doCallback) { notifyGatewaySender(event.getOperation().isUpdate() ? EnumListenerEvent.AFTER_UPDATE : EnumListenerEvent.AFTER_CREATE, event); // Notify listeners if (!event.isBulkOpInProgress()) { try { entry.dispatchListenerEvents(event); } catch (InterruptedException ignore) { Thread.currentThread().interrupt(); this.stopper.checkCancelInProgress(null); } } } } }
boolean doCallback = false; if (isInitialized) { if (event.isGenerateCallbacks()) { doCallback = true;
@Retained protected static EntryEventImpl createRemoveAllEvent(DistributedRemoveAllOperation op, InternalRegion region, Object entryKey) { @Retained EntryEventImpl e; final Operation entryOp = Operation.REMOVEALL_DESTROY; if (op != null) { EntryEventImpl event = op.getBaseEvent(); if (event.isBridgeEvent()) { e = EntryEventImpl.create(region, entryOp, entryKey, null, event.getRawCallbackArgument(), false, event.distributedMember, event.isGenerateCallbacks()); e.setContext(event.getContext()); } else { e = EntryEventImpl.create(region, entryOp, entryKey, null, event.getCallbackArgument(), false, region.getMyId(), event.isGenerateCallbacks()); } } else { e = EntryEventImpl.create(region, entryOp, entryKey, null, null, false, region.getMyId(), true); } e.removeAllOp = op; return e; }
if (prMsg == null) { prMsg = new RemoveAllPRMessage(bucketId.intValue(), removeAllDataSize, false, event.isPossibleDuplicate(), !event.isGenerateCallbacks(), event.getCallbackArgument()); prMsg .setTransactionDistributed(event.getRegion().getCache().getTxManager().isDistributed());
/** * Create RemoveAllPRMessage for notify only (to adjunct nodes) * * @param bucketId create message to send to this bucket */ public RemoveAllPRMessage createPRMessagesNotifyOnly(int bucketId) { final EntryEventImpl event = getBaseEvent(); RemoveAllPRMessage prMsg = new RemoveAllPRMessage(bucketId, removeAllDataSize, true, event.isPossibleDuplicate(), !event.isGenerateCallbacks(), event.getCallbackArgument()); if (event.getContext() != null) { prMsg.setBridgeContext(event.getContext()); } // will not recover event id here for (int i = 0; i < removeAllDataSize; i++) { prMsg.addEntry(removeAllData[i]); } return prMsg; }
@Override public void invokePutCallbacks(final EnumListenerEvent eventType, final EntryEventImpl event, final boolean callDispatchListenerEvent, boolean notifyGateways) { // disallow callbacks on import if (!event.isGenerateCallbacks()) { return; } // Notify bridge clients (if this is a BridgeServer) Operation op = event.getOperation(); // The spec for ConcurrentMap support requires that operations be mapped // to non-CM counterparts if (op == Operation.PUT_IF_ABSENT) { event.setOperation(Operation.CREATE); } else if (op == Operation.REPLACE) { event.setOperation(Operation.UPDATE); } event.setEventType(eventType); notifyBridgeClients(event); if (notifyGateways) { notifyGatewaySender(eventType, event); } if (callDispatchListenerEvent) { dispatchListenerEvent(eventType, event); } }
/** * Create PutAllPRMessage for notify only (to adjunct nodes) * * @param bucketId create message to send to this bucket */ public PutAllPRMessage createPRMessagesNotifyOnly(int bucketId) { final EntryEventImpl event = getBaseEvent(); PutAllPRMessage prMsg = new PutAllPRMessage(bucketId, putAllDataSize, true, event.isPossibleDuplicate(), !event.isGenerateCallbacks(), event.getCallbackArgument()); if (event.getContext() != null) { prMsg.setBridgeContext(event.getContext()); } // will not recover event id here for (int i = 0; i < putAllDataSize; i++) { prMsg.addEntry(putAllData[i]); } return prMsg; }
/** * Creates a PutAllEvent given the distributed operation, the region, and the entry data. * * @since GemFire 5.0 */ @Retained static EntryEventImpl createPutAllEvent(DistributedPutAllOperation putAllOp, InternalRegion region, Operation entryOp, Object entryKey, @Retained(ENTRY_EVENT_NEW_VALUE) Object entryNewValue) { @Retained EntryEventImpl e; if (putAllOp != null) { EntryEventImpl event = putAllOp.getBaseEvent(); if (event.isBridgeEvent()) { e = EntryEventImpl.create(region, entryOp, entryKey, entryNewValue, event.getRawCallbackArgument(), false, event.distributedMember, event.isGenerateCallbacks()); e.setContext(event.getContext()); } else { e = EntryEventImpl.create(region, entryOp, entryKey, entryNewValue, event.getCallbackArgument(), false, region.getMyId(), event.isGenerateCallbacks()); } } else { e = EntryEventImpl.create(region, entryOp, entryKey, entryNewValue, null, false, region.getMyId(), true); } e.putAllOp = putAllOp; return e; }
@Override public void run() { // final boolean requiresRegionContext = theRegion.keyRequiresRegionContext(); InternalDistributedMember myId = theRegion.getDistributionManager().getDistributionManagerId(); for (int i = 0; i < putallOp.putAllDataSize; ++i) { @Released EntryEventImpl ev = PutAllPRMessage.getEventFromEntry(theRegion, myId, myId, i, putallOp.putAllData, false, putallOp.getBaseEvent().getContext(), false, !putallOp.getBaseEvent().isGenerateCallbacks()); try { ev.setPutAllOperation(putallOp); if (theRegion.basicPut(ev, false, false, null, false)) { successfulPuts.addKeyAndVersion(putallOp.putAllData[i].key, null); } } finally { ev.release(); } } } }, putallOp.getBaseEvent().getEventId());
@Override public void run() { InternalDistributedMember myId = theRegion.getDistributionManager().getDistributionManagerId(); for (int i = 0; i < op.removeAllDataSize; ++i) { @Released EntryEventImpl ev = RemoveAllPRMessage.getEventFromEntry(theRegion, myId, myId, i, op.removeAllData, false, op.getBaseEvent().getContext(), false, !op.getBaseEvent().isGenerateCallbacks()); ev.setRemoveAllOperation(op); try { theRegion.basicDestroy(ev, true/* should we invoke cacheWriter? */, null); } catch (EntryNotFoundException ignore) { } finally { ev.release(); } successfulOps.addKeyAndVersion(op.removeAllData[i].key, null); } } }, op.getBaseEvent().getEventId());
public RegionMapPut(FocusedRegionMap focusedRegionMap, InternalRegion owner, CacheModificationLock cacheModificationLock, EntryEventSerialization entryEventSerialization, EntryEventImpl event, boolean ifNew, boolean ifOld, boolean overwriteDestroyed, boolean requireOldValue, Object expectedOldValue) { super(focusedRegionMap, owner, event); this.cacheModificationLock = cacheModificationLock; this.entryEventSerialization = entryEventSerialization; this.ifNew = ifNew; this.ifOld = ifOld; this.overwriteDestroyed = overwriteDestroyed; this.requireOldValue = requireOldValue; this.retrieveOldValueForDelta = event.getDeltaBytes() != null && event.getRawNewValue() == null; this.replaceOnClient = event.getOperation() == Operation.REPLACE && owner.hasServerProxy(); this.onlyExisting = ifOld && !isReplaceOnClient(); this.cacheWriter = owner.basicGetWriter(); this.cacheWrite = !event.isOriginRemote() && !event.isNetSearch() && event.isGenerateCallbacks() && (getCacheWriter() != null || owner.hasServerProxy() || owner.getScope().isDistributed()); this.expectedOldValue = expectedOldValue; if (isCacheWrite() && getCacheWriter() == null) { this.netWriteRecipients = owner.adviseNetWrite(); } else { this.netWriteRecipients = null; } }