Search in sources :

Example 21 with CacheListener

use of org.apache.geode.cache.CacheListener in project geode by apache.

the class RegionMBeanCompositeDataFactory method getRegionAttributesData.

public static RegionAttributesData getRegionAttributesData(RegionAttributes regAttrs) {
    String cacheLoaderClassName = null;
    if (regAttrs.getCacheLoader() != null) {
        cacheLoaderClassName = regAttrs.getCacheLoader().getClass().getCanonicalName();
    }
    String cacheWriteClassName = null;
    if (regAttrs.getCacheWriter() != null) {
        cacheWriteClassName = regAttrs.getCacheWriter().getClass().getCanonicalName();
    }
    String keyConstraintClassName = null;
    if (regAttrs.getKeyConstraint() != null) {
        keyConstraintClassName = regAttrs.getKeyConstraint().getName();
    }
    String valueContstraintClassName = null;
    if (regAttrs.getValueConstraint() != null) {
        valueContstraintClassName = regAttrs.getValueConstraint().getName();
    }
    CacheListener[] listeners = regAttrs.getCacheListeners();
    String[] cacheListeners = null;
    if (listeners != null && listeners.length > 0) {
        cacheListeners = new String[listeners.length];
        int j = 0;
        for (CacheListener l : listeners) {
            cacheListeners[j] = l.getClass().getName();
            j++;
        }
    } else {
        cacheListeners = ManagementConstants.NO_DATA_STRING;
    }
    int regionTimeToLive = regAttrs.getRegionTimeToLive().getTimeout();
    int regionIdleTimeout = regAttrs.getRegionIdleTimeout().getTimeout();
    int entryTimeToLive = regAttrs.getEntryTimeToLive().getTimeout();
    int entryIdleTimeout = regAttrs.getEntryIdleTimeout().getTimeout();
    String customEntryTimeToLive = null;
    Object o1 = regAttrs.getCustomEntryTimeToLive();
    if (o1 != null) {
        customEntryTimeToLive = o1.toString();
    }
    String customEntryIdleTimeout = null;
    Object o2 = regAttrs.getCustomEntryIdleTimeout();
    if (o2 != null) {
        customEntryIdleTimeout = o2.toString();
    }
    boolean ignoreJTA = regAttrs.getIgnoreJTA();
    String dataPolicy = regAttrs.getDataPolicy().toString();
    String scope = regAttrs.getScope().toString();
    int initialCapacity = regAttrs.getInitialCapacity();
    float loadFactor = regAttrs.getLoadFactor();
    boolean lockGrantor = regAttrs.isLockGrantor();
    boolean multicastEnabled = regAttrs.getMulticastEnabled();
    int concurrencyLevel = regAttrs.getConcurrencyLevel();
    boolean indexMaintenanceSynchronous = regAttrs.getIndexMaintenanceSynchronous();
    boolean statisticsEnabled = regAttrs.getStatisticsEnabled();
    boolean subsciptionConflationEnabled = regAttrs.getEnableSubscriptionConflation();
    boolean asyncConflationEnabled = regAttrs.getEnableAsyncConflation();
    String poolName = regAttrs.getPoolName();
    boolean isCloningEnabled = regAttrs.getCloningEnabled();
    String diskStoreName = regAttrs.getDiskStoreName();
    String interestPolicy = null;
    if (regAttrs.getSubscriptionAttributes() != null) {
        interestPolicy = regAttrs.getSubscriptionAttributes().getInterestPolicy().toString();
    }
    String compressorClassName = null;
    if (regAttrs.getCompressor() != null) {
        compressorClassName = regAttrs.getCompressor().getClass().getCanonicalName();
    }
    boolean diskSynchronus = regAttrs.isDiskSynchronous();
    boolean offheap = regAttrs.getOffHeap();
    RegionAttributesData regionAttributesData = new RegionAttributesData(cacheLoaderClassName, cacheWriteClassName, keyConstraintClassName, valueContstraintClassName, regionTimeToLive, regionIdleTimeout, entryTimeToLive, entryIdleTimeout, customEntryTimeToLive, customEntryIdleTimeout, ignoreJTA, dataPolicy, scope, initialCapacity, loadFactor, lockGrantor, multicastEnabled, concurrencyLevel, indexMaintenanceSynchronous, statisticsEnabled, subsciptionConflationEnabled, asyncConflationEnabled, poolName, isCloningEnabled, diskStoreName, interestPolicy, diskSynchronus, cacheListeners, compressorClassName, offheap);
    return regionAttributesData;
}
Also used : RegionAttributesData(org.apache.geode.management.RegionAttributesData) CacheListener(org.apache.geode.cache.CacheListener)

Example 22 with CacheListener

use of org.apache.geode.cache.CacheListener in project geode by apache.

the class AbstractRegion method setCacheListener.

@Override
public CacheListener setCacheListener(CacheListener aListener) {
    checkReadiness();
    CacheListener[] oldListeners;
    synchronized (this.clSync) {
        oldListeners = this.cacheListeners;
        if (oldListeners != null && oldListeners.length > 1) {
            throw new IllegalStateException(LocalizedStrings.AbstractRegion_MORE_THAN_ONE_CACHE_LISTENER_EXISTS.toLocalizedString());
        }
        this.cacheListeners = new CacheListener[] { aListener };
    }
    // moved the following out of the sync for bug 34512
    CacheListener result = null;
    if (oldListeners != null && oldListeners.length > 0) {
        if (oldListeners.length == 1) {
            result = oldListeners[0];
        }
        for (CacheListener oldListener : oldListeners) {
            if (aListener != oldListener) {
                closeCacheCallback(oldListener);
            }
        }
        if (aListener == null) {
            cacheListenersChanged(false);
        }
    } else {
        // we have no old listeners
        if (aListener != null) {
            // we have added a new listener
            cacheListenersChanged(true);
        }
    }
    return result;
}
Also used : CacheListener(org.apache.geode.cache.CacheListener)

Example 23 with CacheListener

use of org.apache.geode.cache.CacheListener in project geode by apache.

the class AbstractRegion method initPostCreateRegionMembershipListeners.

/**
   * Initialize any wrapped RegionMembershipListeners in the cache listener list
   */
void initPostCreateRegionMembershipListeners(Set initialMembers) {
    synchronized (this.clSync) {
        DistributedMember[] members = null;
        CacheListener[] newListeners = null;
        for (int i = 0; i < this.cacheListeners.length; i++) {
            CacheListener cl = this.cacheListeners[i];
            if (cl instanceof WrappedRegionMembershipListener) {
                WrappedRegionMembershipListener wrml = (WrappedRegionMembershipListener) cl;
                if (!wrml.isInitialized()) {
                    if (members == null) {
                        members = (DistributedMember[]) initialMembers.toArray(new DistributedMember[initialMembers.size()]);
                    }
                    wrml.initialMembers(this, members);
                    if (newListeners == null) {
                        newListeners = new CacheListener[this.cacheListeners.length];
                        System.arraycopy(this.cacheListeners, 0, newListeners, 0, newListeners.length);
                    }
                    newListeners[i] = wrml.getWrappedListener();
                }
            }
        }
        if (newListeners != null) {
            this.cacheListeners = newListeners;
        }
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) CacheListener(org.apache.geode.cache.CacheListener) ExtensionPoint(org.apache.geode.internal.cache.extension.ExtensionPoint) SimpleExtensionPoint(org.apache.geode.internal.cache.extension.SimpleExtensionPoint)

Example 24 with CacheListener

use of org.apache.geode.cache.CacheListener in project geode by apache.

the class Bug34948DUnitTest method doCreateOtherVm.

private void doCreateOtherVm() {
    VM vm = getOtherVm();
    vm.invoke(new CacheSerializableRunnable("create root") {

        public void run2() throws CacheException {
            getSystem();
            AttributesFactory af = new AttributesFactory();
            af.setScope(Scope.DISTRIBUTED_ACK);
            af.setDataPolicy(DataPolicy.PRELOADED);
            CacheListener cl = new CacheListenerAdapter() {

                public void afterCreate(EntryEvent event) {
                    // getLogWriter().info("afterCreate " + event.getKey());
                    if (event.getCallbackArgument() != null) {
                        lastCallback = event.getCallbackArgument();
                    }
                }

                public void afterUpdate(EntryEvent event) {
                    // getLogWriter().info("afterUpdate " + event.getKey());
                    if (event.getCallbackArgument() != null) {
                        lastCallback = event.getCallbackArgument();
                    }
                }

                public void afterInvalidate(EntryEvent event) {
                    if (event.getCallbackArgument() != null) {
                        lastCallback = event.getCallbackArgument();
                    }
                }

                public void afterDestroy(EntryEvent event) {
                    if (event.getCallbackArgument() != null) {
                        lastCallback = event.getCallbackArgument();
                    }
                }
            };
            af.setCacheListener(cl);
            createRootRegion("bug34948", af.create());
        }
    });
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) EntryEvent(org.apache.geode.cache.EntryEvent) CacheListener(org.apache.geode.cache.CacheListener)

Example 25 with CacheListener

use of org.apache.geode.cache.CacheListener in project geode by apache.

the class Bug35214DUnitTest method testNoEntryExpireDuringGII.

/**
   * make sure entries do not expire during a GII
   */
@Test
public void testNoEntryExpireDuringGII() throws Exception {
    initOtherVm();
    AsyncInvocation updater = null;
    try {
        updater = updateOtherVm();
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable e1) {
        Assert.fail("failed due to " + e1, e1);
    }
    System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
    org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 30;
    callbackFailure = false;
    try {
        AttributesFactory af = new AttributesFactory();
        af.setDataPolicy(DataPolicy.REPLICATE);
        af.setScope(Scope.DISTRIBUTED_ACK);
        af.setStatisticsEnabled(true);
        af.setEntryIdleTimeout(new ExpirationAttributes(1, ExpirationAction.INVALIDATE));
        CacheListener cl1 = new CacheListenerAdapter() {

            public void afterRegionCreate(RegionEvent re) {
                afterRegionCreateSeen = true;
            }

            public void afterInvalidate(EntryEvent e) {
                callbackAssertTrue("afterregionCreate not seen", afterRegionCreateSeen);
                // make sure region is initialized
                callbackAssertTrue("not initialized", ((LocalRegion) e.getRegion()).isInitialized());
                expirationCount++;
                org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
            }
        };
        af.addCacheListener(cl1);
        final Region r1 = createRootRegion("r1", af.create());
        ThreadUtils.join(updater, 60 * 1000);
        WaitCriterion ev = new WaitCriterion() {

            public boolean done() {
                return r1.values().size() == 0;
            }

            public String description() {
                return "region never became empty";
            }
        };
        Wait.waitForCriterion(ev, 2 * 1000, 200, true);
        {
            assertEquals(0, r1.values().size());
            assertEquals(ENTRY_COUNT, r1.keySet().size());
        }
    } finally {
        org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
        System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
        assertEquals(null, System.getProperty(LocalRegion.EXPIRY_MS_PROPERTY));
    }
    assertFalse("Errors in callbacks; check logs for details", callbackFailure);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) EntryEvent(org.apache.geode.cache.EntryEvent) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) RegionEvent(org.apache.geode.cache.RegionEvent) CacheListener(org.apache.geode.cache.CacheListener) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

CacheListener (org.apache.geode.cache.CacheListener)55 AttributesFactory (org.apache.geode.cache.AttributesFactory)28 Region (org.apache.geode.cache.Region)24 RegionAttributes (org.apache.geode.cache.RegionAttributes)17 EntryEvent (org.apache.geode.cache.EntryEvent)13 Test (org.junit.Test)13 CacheException (org.apache.geode.cache.CacheException)12 Properties (java.util.Properties)11 CacheListenerAdapter (org.apache.geode.cache.util.CacheListenerAdapter)11 VM (org.apache.geode.test.dunit.VM)11 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)11 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)8 CacheWriter (org.apache.geode.cache.CacheWriter)7 AttributesMutator (org.apache.geode.cache.AttributesMutator)6 Host (org.apache.geode.test.dunit.Host)6 Iterator (java.util.Iterator)5 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)5 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)5 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)5 CacheLoader (org.apache.geode.cache.CacheLoader)4