@Override public void close() { RegionEventImpl event = new RegionEventImpl(this, Operation.REGION_CLOSE, null, false, getMyId(), generateEventID()/* generate EventID */); try { // NOTE: the 422dynamicRegions branch added the callbackEvents argument // to basicDestroyRegion and inhibited events on region.close. This // clashed with the new SystemMemberCacheListener functionality in // 5.0, causing unit tests to fail basicDestroyRegion(event, false, true, true); } catch (CacheWriterException e) { // not possible with local operation, CacheWriter not called throw new Error( "CacheWriterException should not be thrown in localDestroyRegion", e); } catch (TimeoutException e) { // not possible with local operation, no distributed locks possible throw new Error( "TimeoutException should not be thrown in localDestroyRegion", e); } }
@Override public void localDestroyRegion(Object aCallbackArgument) { getDataView().checkSupportsRegionDestroy(); RegionEventImpl event = new RegionEventImpl(this, Operation.REGION_LOCAL_DESTROY, aCallbackArgument, false, getMyId(), generateEventID()/* generate EventID */); try { basicDestroyRegion(event, false); } catch (CacheWriterException e) { // not possible with local operation, CacheWriter not called throw new Error( "CacheWriterException should not be thrown in localDestroyRegion", e); } catch (TimeoutException e) { // not possible with local operation, no distributed locks possible throw new Error( "TimeoutException should not be thrown in localDestroyRegion", e); } }
@Override public void loadSnapshot(InputStream inputStream) throws CacheWriterException, TimeoutException, ClassNotFoundException, IOException { if (isProxy()) { throw new UnsupportedOperationException( String.format("Regions with DataPolicy %s do not support loadSnapshot.", getDataPolicy())); } if (inputStream == null) { throw new NullPointerException( "InputStream must not be null."); } checkReadiness(); checkForLimitedOrNoAccess(); RegionEventImpl event = new RegionEventImpl(this, Operation.REGION_LOAD_SNAPSHOT, null, false, getMyId(), generateEventID()/* generate EventID */); reinitialize(inputStream, event); }
public void handleCacheClose(Operation operation) { RegionEventImpl event = new RegionEventImpl(this, operation, null, false, getMyId(), generateEventID()); if (!this.isDestroyed) { // don't destroy if already destroyed try {
@Override public void invalidateRegion(Object aCallbackArgument) throws TimeoutException { getDataView().checkSupportsRegionInvalidate(); checkReadiness(); checkForLimitedOrNoAccess(); RegionEventImpl event = new RegionEventImpl(this, Operation.REGION_INVALIDATE, aCallbackArgument, false, getMyId(), generateEventID()); basicInvalidateRegion(event); }
@Override public void destroyRegion(Object aCallbackArgument) throws CacheWriterException, TimeoutException { this.cache.invokeBeforeDestroyed(this); getDataView().checkSupportsRegionDestroy(); checkForLimitedOrNoAccess(); RegionEventImpl event = new RegionEventImpl(this, Operation.REGION_DESTROY, aCallbackArgument, false, getMyId(), generateEventID()); basicDestroyRegion(event, true); }
/** * Creates an event for EVICT_DESTROY operations. It is intended that this method be overridden to * allow for special handling of Partitioned Regions. * * @param key - the key that this event is related to * @return an event for EVICT_DESTROY */ @Retained protected EntryEventImpl generateEvictDestroyEvent(final Object key) { @Retained EntryEventImpl event = EntryEventImpl.create(this, Operation.EVICT_DESTROY, key, null/* newValue */, null, false, getMyId()); // Fix for bug#36963 if (generateEventID()) { event.setNewEventId(this.cache.getDistributedSystem()); } return event; }
@Override public void localDestroy(Object key, Object aCallbackArgument) throws EntryNotFoundException { validateKey(key); checkReadiness(); checkForNoAccess(); @Released EntryEventImpl event = EntryEventImpl.create(this, Operation.LOCAL_DESTROY, key, null, aCallbackArgument, false, getMyId()); if (generateEventID()) { event.setNewEventId(this.cache.getDistributedSystem()); } try { basicDestroy(event, false, null); // expectedOldValue } catch (CacheWriterException e) { // cache writer not called throw new Error( "Cache Writer should not have been called for localDestroy", e); } catch (TimeoutException e) { // no distributed lock throw new Error( "No distributed lock should have been attempted for localDestroy", e); } finally { event.release(); } }
/** * Destroys entry without performing validations. Call this after validating key, callback arg, * and runtime state. */ public Object validatedDestroy(Object key, EntryEventImpl event) throws TimeoutException, EntryNotFoundException, CacheWriterException { if (event.getEventId() == null && generateEventID()) { event.setNewEventId(this.cache.getDistributedSystem()); } basicDestroy(event, true, // cacheWrite null); // expectedOldValue if (event.isOldValueOffHeap()) { return null; } else { return handleNotAvailable(event.getOldValue()); } }
/** * Destroys entry without performing validations. Call this after validating key, callback arg, * and runtime state. */ void validatedInvalidate(Object key, Object aCallbackArgument) throws TimeoutException, EntryNotFoundException { @Released EntryEventImpl event = EntryEventImpl.create(this, Operation.INVALIDATE, key, null, aCallbackArgument, false, getMyId()); try { if (generateEventID()) { event.setNewEventId(this.cache.getDistributedSystem()); } basicInvalidate(event); } finally { event.release(); } }
/** * Clear the region from a server request. * * @param callbackArgument The callback argument. This is currently null since * {@link java.util.Map#clear} supports no parameters. * @param processedMarker Whether the marker has been processed (for durable clients) */ public void basicBridgeClientClear(Object callbackArgument, boolean processedMarker) { checkReadiness(); checkForNoAccess(); RegionEventImpl event = new RegionEventImpl(this, Operation.REGION_LOCAL_CLEAR, callbackArgument, true, getMyId(), generateEventID()/* generate EventID */); // If the marker has been processed, process this clear event normally; // otherwise, this event occurred in the past and has been stored for a // durable client. In this case, just invoke the clear callbacks. if (processedMarker) { basicLocalClear(event); } else { if (isInitialized()) { dispatchListenerEvent(EnumListenerEvent.AFTER_REGION_CLEAR, event); } } }
@Override public void localInvalidate(Object key, Object aCallbackArgument) throws EntryNotFoundException { validateKey(key); checkReadiness(); checkForNoAccess(); @Released EntryEventImpl event = EntryEventImpl.create(this, Operation.LOCAL_INVALIDATE, key, null/* newValue */, aCallbackArgument, false, getMyId()); try { if (generateEventID()) { event.setNewEventId(this.cache.getDistributedSystem()); } event.setLocalInvalid(true); basicInvalidate(event); } finally { event.release(); } }
private void validatedCreate(EntryEventImpl event, long startPut) throws TimeoutException, EntryExistsException, CacheWriterException { if (event.getEventId() == null && generateEventID()) { event.setNewEventId(this.cache.getDistributedSystem()); } // Fix for 42448 - Only make create with null a local invalidate for // normal regions. Otherwise, it will become a distributed invalidate. if (getDataPolicy() == DataPolicy.NORMAL) { event.setLocalInvalid(true); } discoverJTA(); if (!basicPut(event, true, // ifNew false, // ifOld null, // expectedOldValue true // requireOldValue TODO txMerge why is oldValue required for // create? I think so that the EntryExistsException will have it. )) { throw new EntryExistsException(event.getKey().toString(), event.getOldValue()); } else { if (!getDataView().isDeferredStats()) { getCachePerfStats().endPut(startPut, false); } } }
Object validatedPut(EntryEventImpl event, long startPut) throws TimeoutException, CacheWriterException { if (event.getEventId() == null && generateEventID()) { event.setNewEventId(this.cache.getDistributedSystem()); } Object oldValue = null; if (basicPut(event, false, // ifNew false, // ifOld null, // expectedOldValue false // requireOldValue )) { if (!event.isOldValueOffHeap()) { // don't copy it to heap just to return from put. // TODO: come up with a better way to do this. oldValue = event.getOldValue(); } if (!getDataView().isDeferredStats()) { getCachePerfStats().endPut(startPut, false); } } return handleNotAvailable(oldValue); }
@Override protected boolean localDestroy() throws CacheException { RegionEntry re = getCheckedRegionEntry(); Object key = re.getKey(); LocalRegion lr = getLocalRegion(); @Released EntryEventImpl event = EntryEventImpl.create(lr, Operation.EXPIRE_LOCAL_DESTROY, key, null, createExpireEntryCallback(lr, key), false, lr.getMyId()); try { if (lr.generateEventID()) { event.setNewEventId(lr.getCache().getDistributedSystem()); } lr.expireDestroy(event, false); // expectedOldValue } finally { event.release(); } return true; }
@Override protected boolean localInvalidate() throws EntryNotFoundException { RegionEntry re = getCheckedRegionEntry(); Object key = re.getKey(); LocalRegion lr = getLocalRegion(); @Released EntryEventImpl event = EntryEventImpl.create(lr, Operation.EXPIRE_LOCAL_INVALIDATE, key, null, createExpireEntryCallback(lr, key), false, lr.getMyId()); try { if (lr.generateEventID()) { event.setNewEventId(lr.getCache().getDistributedSystem()); } lr.expireInvalidate(event); } finally { event.release(); } return true; }
@Override protected boolean invalidate() throws TimeoutException, EntryNotFoundException { RegionEntry re = getCheckedRegionEntry(); Object key = re.getKey(); LocalRegion lr = getLocalRegion(); @Released EntryEventImpl event = EntryEventImpl.create(lr, Operation.EXPIRE_INVALIDATE, key, null, createExpireEntryCallback(lr, key), false, lr.getMyId()); try { if (lr.generateEventID()) { event.setNewEventId(lr.getCache().getDistributedSystem()); } lr.expireInvalidate(event); } finally { event.release(); } return true; }
@Override protected boolean destroy(boolean isPending) throws CacheException { RegionEntry re = getCheckedRegionEntry(); Object key = re.getKey(); LocalRegion lr = getLocalRegion(); @Released EntryEventImpl event = EntryEventImpl.create(lr, Operation.EXPIRE_DESTROY, key, null, createExpireEntryCallback(lr, key), false, lr.getMyId()); try { event.setPendingSecondaryExpireDestroy(isPending); if (lr.generateEventID()) { event.setNewEventId(lr.getCache().getDistributedSystem()); } lr.expireDestroy(event, true); // expectedOldValue return true; } finally { event.release(); } }
@Test public void txApplyDestroySetCorrectPendingCallback_givenNoRegionEntryNotInTokenModeNoConcurrencyChecks() { givenLocalRegion(); givenNoRegionEntry(); givenNotInTokenMode(); givenNoConcurrencyChecks(); when(owner.generateEventID()).thenReturn(true); when(keyInfo.getCallbackArg()).thenReturn(aCallbackArgument); doTxApplyDestroy(); assertThat(pendingCallbacks).hasSize(1); EntryEventImpl callbackEvent = pendingCallbacks.get(0); // noinspection Duplicates assertSoftly(softly -> { softly.assertThat(callbackEvent.getRegion()).isSameAs(owner); softly.assertThat(callbackEvent.getOperation()).isSameAs(operation); softly.assertThat(callbackEvent.getKey()).isSameAs(key); softly.assertThat(callbackEvent.getNewValue()).isNull(); softly.assertThat(callbackEvent.getTransactionId()).isSameAs(txId); softly.assertThat(callbackEvent.getEventId()).isSameAs(eventId); softly.assertThat(callbackEvent.getCallbackArgument()).isSameAs(aCallbackArgument); softly.assertThat(callbackEvent.getLocalFilterInfo()).isSameAs(filterRoutingInfo); softly.assertThat(callbackEvent.getContext()).isSameAs(bridgeContext); softly.assertThat(callbackEvent.isOriginRemote()).isEqualTo(isOriginRemote); softly.assertThat(callbackEvent.getVersionTag()).isEqualTo(versionTag); softly.assertThat(callbackEvent.getTailKey()).isEqualTo(tailKey); }); }
@Test public void addsCallbackEvent_givenOldRegionEntryWithInTokenModeAndInRI() { givenLocalRegion(); givenConcurrencyChecks(); givenOldRegionEntry(); inTokenMode = true; inRI = true; when(owner.generateEventID()).thenReturn(true); when(keyInfo.getCallbackArg()).thenReturn(aCallbackArgument); doTxApplyDestroy(); assertThat(pendingCallbacks).hasSize(1); EntryEventImpl callbackEvent = pendingCallbacks.get(0); // noinspection Duplicates assertSoftly(softly -> { softly.assertThat(callbackEvent.getRegion()).isSameAs(owner); softly.assertThat(callbackEvent.getOperation()).isSameAs(operation); softly.assertThat(callbackEvent.getKey()).isSameAs(key); softly.assertThat(callbackEvent.getNewValue()).isNull(); softly.assertThat(callbackEvent.getTransactionId()).isSameAs(txId); softly.assertThat(callbackEvent.getEventId()).isSameAs(eventId); softly.assertThat(callbackEvent.getCallbackArgument()).isSameAs(aCallbackArgument); softly.assertThat(callbackEvent.getLocalFilterInfo()).isSameAs(filterRoutingInfo); softly.assertThat(callbackEvent.getContext()).isSameAs(bridgeContext); softly.assertThat(callbackEvent.isOriginRemote()).isEqualTo(isOriginRemote); softly.assertThat(callbackEvent.getVersionTag()).isEqualTo(versionTag); softly.assertThat(callbackEvent.getTailKey()).isEqualTo(tailKey); softly.assertThat(callbackEvent.getRegionEntry()).isSameAs(oldRegionEntry); softly.assertThat(callbackEvent.getOldValue()).isNull(); }); }