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;
}
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;
}
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;
}
}
}
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());
}
});
}
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);
}
Aggregations