use of org.apache.geode.cache.CacheListener in project geode by apache.
the class CacheXmlParser method endCacheListener.
/**
* When a <code>cache-listener</code> element is finished, the {@link Parameter}s and class names
* are popped off the stack. The cache listener is instantiated and initialized with the
* parameters, if appropriate.
*/
private void endCacheListener() {
Declarable d = createDeclarable();
if (!(d instanceof CacheListener)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_CACHELISTENER.toLocalizedString(d.getClass().getName()));
}
RegionAttributesCreation attrs = peekRegionAttributesContext(CACHE_LISTENER);
attrs.addCacheListener((CacheListener) d);
}
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 RegionAlterFunction method alterRegion.
private <K, V> Region<?, ?> alterRegion(Cache cache, RegionFunctionArgs regionAlterArgs) {
final String regionPathString = regionAlterArgs.getRegionPath();
RegionPath regionPath = new RegionPath(regionPathString);
AbstractRegion region = (AbstractRegion) cache.getRegion(regionPathString);
if (region == null) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.ALTER_REGION__MSG__REGION_DOESNT_EXIST_0, new Object[] { regionPath }));
}
AttributesMutator mutator = region.getAttributesMutator();
if (regionAlterArgs.isCloningEnabled() != null) {
mutator.setCloningEnabled(regionAlterArgs.isCloningEnabled());
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - cloning");
}
}
if (regionAlterArgs.getEvictionMax() != null) {
mutator.getEvictionAttributesMutator().setMaximum(regionAlterArgs.getEvictionMax());
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - eviction attributes max");
}
}
// Alter expiration attributes
final RegionFunctionArgs.ExpirationAttrs newEntryExpirationIdleTime = regionAlterArgs.getEntryExpirationIdleTime();
if (newEntryExpirationIdleTime != null) {
mutator.setEntryIdleTimeout(parseExpirationAttributes(newEntryExpirationIdleTime, region.getEntryIdleTimeout()));
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - entry idle timeout");
}
}
final RegionFunctionArgs.ExpirationAttrs newEntryExpirationTTL = regionAlterArgs.getEntryExpirationTTL();
if (newEntryExpirationTTL != null) {
mutator.setEntryTimeToLive(parseExpirationAttributes(newEntryExpirationTTL, region.getEntryTimeToLive()));
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - entry TTL");
}
}
final RegionFunctionArgs.ExpirationAttrs newRegionExpirationIdleTime = regionAlterArgs.getRegionExpirationIdleTime();
if (newRegionExpirationIdleTime != null) {
mutator.setRegionIdleTimeout(parseExpirationAttributes(newRegionExpirationIdleTime, region.getRegionIdleTimeout()));
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - region idle timeout");
}
}
final RegionFunctionArgs.ExpirationAttrs newRegionExpirationTTL = regionAlterArgs.getRegionExpirationTTL();
if (newRegionExpirationTTL != null) {
mutator.setRegionTimeToLive(parseExpirationAttributes(newRegionExpirationTTL, region.getRegionTimeToLive()));
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - region TTL");
}
}
// Alter Gateway Sender Ids
final Set<String> newGatewaySenderIds = regionAlterArgs.getGatewaySenderIds();
if (newGatewaySenderIds != null) {
// Remove old gateway sender ids that aren't in the new list
Set<String> oldGatewaySenderIds = region.getGatewaySenderIds();
if (!oldGatewaySenderIds.isEmpty()) {
for (String gatewaySenderId : oldGatewaySenderIds) {
if (!newGatewaySenderIds.contains(gatewaySenderId)) {
mutator.removeGatewaySenderId(gatewaySenderId);
}
}
}
// Add new gateway sender ids that don't already exist
for (String gatewaySenderId : newGatewaySenderIds) {
if (!oldGatewaySenderIds.contains(gatewaySenderId)) {
mutator.addGatewaySenderId(gatewaySenderId);
}
}
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - gateway sender IDs");
}
}
// Alter Async Queue Ids
final Set<String> newAsyncEventQueueIds = regionAlterArgs.getAsyncEventQueueIds();
if (newAsyncEventQueueIds != null) {
// Remove old async event queue ids that aren't in the new list
Set<String> oldAsyncEventQueueIds = region.getAsyncEventQueueIds();
if (!oldAsyncEventQueueIds.isEmpty()) {
for (String asyncEventQueueId : oldAsyncEventQueueIds) {
if (!newAsyncEventQueueIds.contains(asyncEventQueueId)) {
mutator.removeAsyncEventQueueId(asyncEventQueueId);
}
}
}
// Add new async event queue ids that don't already exist
for (String asyncEventQueueId : newAsyncEventQueueIds) {
if (!oldAsyncEventQueueIds.contains(asyncEventQueueId)) {
mutator.addAsyncEventQueueId(asyncEventQueueId);
}
}
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - async event queue IDs");
}
}
// Alter Cache Listeners
final Set<String> newCacheListenerNames = regionAlterArgs.getCacheListeners();
if (newCacheListenerNames != null) {
// Remove old cache listeners that aren't in the new list
CacheListener[] oldCacheListeners = region.getCacheListeners();
for (CacheListener oldCacheListener : oldCacheListeners) {
if (!newCacheListenerNames.contains(oldCacheListener.getClass().getName())) {
mutator.removeCacheListener(oldCacheListener);
}
}
// Add new cache listeners that don't already exist
for (String newCacheListenerName : newCacheListenerNames) {
if (newCacheListenerName.isEmpty()) {
continue;
}
boolean nameFound = false;
for (CacheListener oldCacheListener : oldCacheListeners) {
if (oldCacheListener.getClass().getName().equals(newCacheListenerName)) {
nameFound = true;
break;
}
}
if (!nameFound) {
Class<CacheListener<K, V>> cacheListenerKlass = forName(newCacheListenerName, CliStrings.ALTER_REGION__CACHELISTENER);
mutator.addCacheListener(newInstance(cacheListenerKlass, CliStrings.ALTER_REGION__CACHELISTENER));
}
}
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - cache listeners");
}
}
final String cacheLoader = regionAlterArgs.getCacheLoader();
if (cacheLoader != null) {
if (cacheLoader.isEmpty()) {
mutator.setCacheLoader(null);
} else {
Class<CacheLoader<K, V>> cacheLoaderKlass = forName(cacheLoader, CliStrings.ALTER_REGION__CACHELOADER);
mutator.setCacheLoader(newInstance(cacheLoaderKlass, CliStrings.ALTER_REGION__CACHELOADER));
}
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - cache loader");
}
}
final String cacheWriter = regionAlterArgs.getCacheWriter();
if (cacheWriter != null) {
if (cacheWriter.isEmpty()) {
mutator.setCacheWriter(null);
} else {
Class<CacheWriter<K, V>> cacheWriterKlass = forName(cacheWriter, CliStrings.ALTER_REGION__CACHEWRITER);
mutator.setCacheWriter(newInstance(cacheWriterKlass, CliStrings.ALTER_REGION__CACHEWRITER));
}
if (logger.isDebugEnabled()) {
logger.debug("Region successfully altered - cache writer");
}
}
return region;
}
Aggregations