Search in sources :

Example 1 with RegionEventImpl

use of org.apache.geode.internal.cache.RegionEventImpl in project geode by apache.

the class DynamicRegionFactory method doAfterRegionDestroyed.

private void doAfterRegionDestroyed(Region region, boolean distributed, boolean isOriginRemote, boolean expiration, DistributedMember mbr) {
    final Operation op;
    if (!distributed && !isOriginRemote) {
        op = expiration ? Operation.REGION_EXPIRE_LOCAL_DESTROY : Operation.REGION_LOCAL_DESTROY;
    } else {
        op = expiration ? Operation.REGION_EXPIRE_DESTROY : Operation.REGION_DESTROY;
    }
    RegionEvent event = new RegionEventImpl(region, op, null, isOriginRemote, getMember(mbr));
    for (Object regionListener : regionListeners) {
        DynamicRegionListener listener = (DynamicRegionListener) regionListener;
        try {
            listener.afterRegionDestroy(event);
        } catch (VirtualMachineError err) {
            SystemFailure.initiateFailure(err);
            // now, so don't let this thread continue.
            throw err;
        } catch (Throwable t) {
            // Whenever you catch Error or Throwable, you must also
            // catch VirtualMachineError (see above). However, there is
            // _still_ a possibility that you are dealing with a cascading
            // error condition, so you also need to check to see if the JVM
            // is still usable:
            SystemFailure.checkFailure();
            this.cache.getLoggerI18n().warning(LocalizedStrings.DynamicRegionFactory_DYNAMICREGIONLISTENER__0__THREW_EXCEPTION_ON_AFTERREGIONDESTROYED, listener, t);
        }
    }
}
Also used : RegionEventImpl(org.apache.geode.internal.cache.RegionEventImpl) InitialImageOperation(org.apache.geode.internal.cache.InitialImageOperation)

Example 2 with RegionEventImpl

use of org.apache.geode.internal.cache.RegionEventImpl in project geode by apache.

the class PRTombstoneMessage method operateOnPartitionedRegion.

@Override
protected boolean operateOnPartitionedRegion(final DistributionManager dm, PartitionedRegion r, long startTime) throws ForceReattemptException {
    if (logger.isTraceEnabled(LogMarker.DM)) {
        logger.debug("PRTombstoneMessage operateOnRegion: {}", r.getFullPath());
    }
    FilterProfile fp = r.getFilterProfile();
    if (this.keys != null && this.keys.size() > 0) {
        // sanity check
        if (fp != null && CacheClientNotifier.getInstance() != null && this.eventID != null) {
            RegionEventImpl regionEvent = new RegionEventImpl(r, Operation.REGION_DESTROY, null, true, r.getGemFireCache().getMyId());
            regionEvent.setLocalFilterInfo(fp.getLocalFilterRouting(regionEvent));
            ClientUpdateMessage clientMessage = ClientTombstoneMessage.gc(r, this.keys, this.eventID);
            CacheClientNotifier.notifyClients(regionEvent, clientMessage);
        }
    }
    return true;
}
Also used : FilterProfile(org.apache.geode.internal.cache.FilterProfile) ClientUpdateMessage(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessage) RegionEventImpl(org.apache.geode.internal.cache.RegionEventImpl)

Example 3 with RegionEventImpl

use of org.apache.geode.internal.cache.RegionEventImpl in project geode by apache.

the class HAGIIDUnitTest method tombstonegc.

/** queue a tombstone GC message for the client. See bug #46832 */
public static void tombstonegc() throws Exception {
    LocalRegion r = (LocalRegion) cache.getRegion("/" + REGION_NAME);
    assertNotNull(r);
    DistributedMember id = r.getCache().getDistributedSystem().getDistributedMember();
    RegionEventImpl regionEvent = new RegionEventImpl(r, Operation.REGION_DESTROY, null, true, id);
    FilterInfo clientRouting = r.getFilterProfile().getLocalFilterRouting(regionEvent);
    assertTrue(clientRouting.getInterestedClients().size() > 0);
    regionEvent.setLocalFilterInfo(clientRouting);
    Map<VersionSource, Long> map = Collections.emptyMap();
    ClientTombstoneMessage message = ClientTombstoneMessage.gc(r, map, new EventID(r.getCache().getDistributedSystem()));
    CacheClientNotifier.notifyClients(regionEvent, message);
}
Also used : VersionSource(org.apache.geode.internal.cache.versions.VersionSource) ClientTombstoneMessage(org.apache.geode.internal.cache.tier.sockets.ClientTombstoneMessage) RegionEventImpl(org.apache.geode.internal.cache.RegionEventImpl) DistributedMember(org.apache.geode.distributed.DistributedMember) EventID(org.apache.geode.internal.cache.EventID) LocalRegion(org.apache.geode.internal.cache.LocalRegion) FilterInfo(org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo)

Example 4 with RegionEventImpl

use of org.apache.geode.internal.cache.RegionEventImpl in project geode by apache.

the class EventIDVerificationDUnitTest method createClientCache.

public static void createClientCache(String host, Integer port1, Integer port2) throws Exception {
    PORT1 = port1.intValue();
    PORT2 = port2.intValue();
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    new EventIDVerificationDUnitTest().createCache(props);
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setMirrorType(MirrorType.NONE);
    ClientServerTestCase.configureConnectionPool(factory, host, new int[] { PORT1, PORT2 }, true, -1, 2, null, -1, -1, false, -2);
    CacheWriter writer = new CacheWriterAdapter() {

        public void beforeCreate(EntryEvent event) {
            EventID eventId = ((EntryEventImpl) event).getEventId();
            vm0.invoke(() -> EventIDVerificationDUnitTest.setEventIDData(eventId));
            vm1.invoke(() -> EventIDVerificationDUnitTest.setEventIDData(eventId));
            try {
                super.beforeCreate(event);
            } catch (CacheWriterException e) {
                e.printStackTrace();
                fail("Test failed bcoz of exception =" + e);
            }
        }

        public void beforeUpdate(EntryEvent event) {
            EventID eventId = ((EntryEventImpl) event).getEventId();
            vm0.invoke(() -> EventIDVerificationDUnitTest.setEventIDData(eventId));
            vm1.invoke(() -> EventIDVerificationDUnitTest.setEventIDData(eventId));
            try {
                super.beforeUpdate(event);
            } catch (CacheWriterException e) {
                e.printStackTrace();
                fail("Test failed bcoz of exception =" + e);
            }
        }

        public void beforeDestroy(EntryEvent event) {
            EventID eventId = ((EntryEventImpl) event).getEventId();
            vm0.invoke(() -> EventIDVerificationDUnitTest.setEventIDData(eventId));
            vm1.invoke(() -> EventIDVerificationDUnitTest.setEventIDData(eventId));
            try {
                super.beforeDestroy(event);
            } catch (CacheWriterException e) {
                e.printStackTrace();
                fail("Test failed bcoz of exception =" + e);
            }
        }

        public void beforeRegionDestroy(RegionEvent event) {
            EventID eventId = ((RegionEventImpl) event).getEventId();
            vm0.invoke(() -> EventIDVerificationDUnitTest.setEventIDData(eventId));
            vm1.invoke(() -> EventIDVerificationDUnitTest.setEventIDData(eventId));
            try {
                super.beforeRegionDestroy(event);
            } catch (CacheWriterException e) {
                e.printStackTrace();
                fail("Test failed bcoz of exception =" + e);
            }
        }

        public void beforeRegionClear(RegionEvent event) {
            EventID eventId = ((RegionEventImpl) event).getEventId();
            vm0.invoke(() -> EventIDVerificationDUnitTest.setEventIDData(eventId));
            vm1.invoke(() -> EventIDVerificationDUnitTest.setEventIDData(eventId));
            try {
                super.beforeRegionClear(event);
            } catch (CacheWriterException e) {
                e.printStackTrace();
                fail("Test failed bcoz of exception =" + e);
            }
        }
    };
    factory.setCacheWriter(writer);
    /*
     * factory.setCacheListener(new CacheListenerAdapter() { public void afterCreate(EntryEvent
     * event) { synchronized (this) { threadId = ((EntryEventImpl)event).getEventId().getThreadID();
     * membershipId = ((EntryEventImpl)event).getEventId().getMembershipID(); } }
     *
     * public void afterUpdate(EntryEvent event) { synchronized (this) { verifyEventIDs(event); } }
     *
     * public void afterDestroy(EntryEvent event) { synchronized (this) { verifyEventIDs(event); } }
     * public void afterRegionDestroy(RegionEvent event) { synchronized (this) { threadId =
     * ((RegionEventImpl)event).getEventId().getThreadID(); membershipId =
     * ((RegionEventImpl)event).getEventId().getMembershipID(); } } });
     */
    RegionAttributes attrs = factory.create();
    Region r = cache.createRegion(REGION_NAME, attrs);
    r.registerInterest("ALL_KEYS");
}
Also used : CacheWriterAdapter(org.apache.geode.cache.util.CacheWriterAdapter) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) RegionAttributes(org.apache.geode.cache.RegionAttributes) RegionEventImpl(org.apache.geode.internal.cache.RegionEventImpl) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) RegionEvent(org.apache.geode.cache.RegionEvent) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheWriter(org.apache.geode.cache.CacheWriter) EntryEvent(org.apache.geode.cache.EntryEvent) EventID(org.apache.geode.internal.cache.EventID) Region(org.apache.geode.cache.Region) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 5 with RegionEventImpl

use of org.apache.geode.internal.cache.RegionEventImpl in project geode by apache.

the class DynamicRegionFactory method doBeforeRegionDestroyed.

private void doBeforeRegionDestroyed(Region region, boolean distributed, boolean isOriginRemote, boolean expiration, DistributedMember mbr) {
    final Operation op;
    if (!distributed && !isOriginRemote) {
        op = expiration ? Operation.REGION_EXPIRE_LOCAL_DESTROY : Operation.REGION_LOCAL_DESTROY;
    } else {
        op = expiration ? Operation.REGION_EXPIRE_DESTROY : Operation.REGION_DESTROY;
    }
    RegionEvent event = new RegionEventImpl(region, op, null, isOriginRemote, getMember(mbr));
    for (Object regionListener : regionListeners) {
        DynamicRegionListener listener = (DynamicRegionListener) regionListener;
        try {
            listener.beforeRegionDestroy(event);
        } catch (VirtualMachineError err) {
            SystemFailure.initiateFailure(err);
            // now, so don't let this thread continue.
            throw err;
        } catch (Throwable t) {
            // Whenever you catch Error or Throwable, you must also
            // catch VirtualMachineError (see above). However, there is
            // _still_ a possibility that you are dealing with a cascading
            // error condition, so you also need to check to see if the JVM
            // is still usable:
            SystemFailure.checkFailure();
            this.cache.getLoggerI18n().warning(LocalizedStrings.DynamicRegionFactory_DYNAMICREGIONLISTENER__0__THREW_EXCEPTION_ON_BEFOREREGIONDESTROYED, listener, t);
        }
    }
}
Also used : RegionEventImpl(org.apache.geode.internal.cache.RegionEventImpl) InitialImageOperation(org.apache.geode.internal.cache.InitialImageOperation)

Aggregations

RegionEventImpl (org.apache.geode.internal.cache.RegionEventImpl)6 EventID (org.apache.geode.internal.cache.EventID)3 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)2 InitialImageOperation (org.apache.geode.internal.cache.InitialImageOperation)2 IOException (java.io.IOException)1 Properties (java.util.Properties)1 CancelException (org.apache.geode.CancelException)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 CacheException (org.apache.geode.cache.CacheException)1 CacheWriter (org.apache.geode.cache.CacheWriter)1 CacheWriterException (org.apache.geode.cache.CacheWriterException)1 EntryEvent (org.apache.geode.cache.EntryEvent)1 Region (org.apache.geode.cache.Region)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 RegionEvent (org.apache.geode.cache.RegionEvent)1 RegionExistsException (org.apache.geode.cache.RegionExistsException)1 UnsupportedVersionException (org.apache.geode.cache.UnsupportedVersionException)1 CqException (org.apache.geode.cache.query.CqException)1 CacheWriterAdapter (org.apache.geode.cache.util.CacheWriterAdapter)1