Search in sources :

Example 66 with CacheListenerAdapter

use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.

the class EventIDVerificationInP2PDUnitTest method createServerCache.

public static void createServerCache(Integer type) throws Exception {
    new EventIDVerificationInP2PDUnitTest().createCache(new Properties());
    AttributesFactory factory = new AttributesFactory();
    if (type.intValue() == DISTRIBUTED_ACK)
        factory.setScope(Scope.DISTRIBUTED_ACK);
    if (type.intValue() == GLOBAL)
        factory.setScope(Scope.GLOBAL);
    else
        factory.setScope(Scope.DISTRIBUTED_NO_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    factory.addCacheListener(new CacheListenerAdapter() {

        public void afterCreate(EntryEvent event) {
            eventId = ((InternalCacheEvent) event).getEventId();
            if (receiver) {
                synchronized (EventIDVerificationInP2PDUnitTest.class) {
                    gotCallback = true;
                    EventIDVerificationInP2PDUnitTest.class.notify();
                }
            }
        }

        public void afterUpdate(EntryEvent event) {
            eventId = ((InternalCacheEvent) event).getEventId();
            if (receiver) {
                synchronized (EventIDVerificationInP2PDUnitTest.class) {
                    gotCallback = true;
                    EventIDVerificationInP2PDUnitTest.class.notify();
                }
            }
        }

        public void afterDestroy(EntryEvent event) {
            eventId = ((InternalCacheEvent) event).getEventId();
            if (receiver) {
                synchronized (EventIDVerificationInP2PDUnitTest.class) {
                    gotCallback = true;
                    EventIDVerificationInP2PDUnitTest.class.notify();
                }
            }
        }

        public void afterRegionDestroy(RegionEvent event) {
            eventId = ((InternalCacheEvent) event).getEventId();
            if (receiver) {
                synchronized (EventIDVerificationInP2PDUnitTest.class) {
                    gotCallback = true;
                    EventIDVerificationInP2PDUnitTest.class.notify();
                }
            }
        }

        public void afterRegionInvalidate(RegionEvent event) {
            eventId = ((InternalCacheEvent) event).getEventId();
            if (receiver) {
                synchronized (EventIDVerificationInP2PDUnitTest.class) {
                    gotCallback = true;
                    EventIDVerificationInP2PDUnitTest.class.notify();
                }
            }
        }
    });
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) RegionAttributes(org.apache.geode.cache.RegionAttributes) EntryEvent(org.apache.geode.cache.EntryEvent) InternalCacheEvent(org.apache.geode.internal.cache.InternalCacheEvent) Properties(java.util.Properties) RegionEvent(org.apache.geode.cache.RegionEvent)

Aggregations

CacheListenerAdapter (org.apache.geode.cache.util.CacheListenerAdapter)66 EntryEvent (org.apache.geode.cache.EntryEvent)55 AttributesFactory (org.apache.geode.cache.AttributesFactory)40 Region (org.apache.geode.cache.Region)30 Test (org.junit.Test)25 RegionAttributes (org.apache.geode.cache.RegionAttributes)21 Properties (java.util.Properties)20 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)16 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)15 VM (org.apache.geode.test.dunit.VM)14 CacheException (org.apache.geode.cache.CacheException)11 CacheListener (org.apache.geode.cache.CacheListener)11 LocalRegion (org.apache.geode.internal.cache.LocalRegion)9 Host (org.apache.geode.test.dunit.Host)9 RegionEvent (org.apache.geode.cache.RegionEvent)8 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)8 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)7 CacheServer (org.apache.geode.cache.server.CacheServer)7 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)7 SubscriptionAttributes (org.apache.geode.cache.SubscriptionAttributes)6