use of org.apache.geode.cache.CacheListener in project geode by apache.
the class HAClientCountEventListener method createClientCache.
public static void createClientCache(String host, Integer port1, Boolean isListenerPresent) throws Exception {
int PORT1 = port1.intValue();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new HAConflationDUnitTest().createCache(props);
AttributesFactory factory = new AttributesFactory();
ClientServerTestCase.configureConnectionPool(factory, host, new int[] { PORT1 }, true, -1, -1, null);
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setEnableConflation(true);
if (isListenerPresent.booleanValue() == true) {
CacheListener clientListener = new HAClientCountEventListener();
factory.setCacheListener(clientListener);
}
RegionAttributes attrs = factory.create();
basicGetCache().createRegion(regionName, attrs);
Region region = basicGetCache().getRegion(Region.SEPARATOR + regionName);
assertNotNull(region);
region.registerInterest(KEY1);
region.registerInterest(KEY2);
region.registerInterest(KEY3);
region.registerInterest(LAST_KEY);
lastKeyArrived = false;
actualNoEvents = 0;
}
use of org.apache.geode.cache.CacheListener in project geode by apache.
the class DurableClientQueueSizeDUnitTest method ackedEventsShouldBeRemovedFromTheQueueEventuallyEvenIfNoNewMessagesAreSent.
// Slows down client consumption from queue, this should cause a delay from server queue dispatch
// and receiving an ack from the client. The server should still clean up acked events from the
// queue even if no more messages are being sent. Previously events would get stuck in the queue
// if no new messages were sent because clean up was only done while sending messages
@Test
public void ackedEventsShouldBeRemovedFromTheQueueEventuallyEvenIfNoNewMessagesAreSent() throws Exception {
int num = 10;
CacheListener slowListener = new SlowListener();
vm1.invoke(() -> DurableClientQueueSizeDUnitTest.closeCache());
vm2.invoke(DurableClientQueueSizeDUnitTest.class, "createClientCache", new Object[] { vm2.getHost(), new Integer[] { port0, port1 }, "300", Boolean.TRUE, Boolean.FALSE, slowListener });
vm2.invoke(() -> DurableClientQueueSizeDUnitTest.doRI());
vm2.invoke(() -> DurableClientQueueSizeDUnitTest.readyForEvents());
vm0.invoke(() -> DurableClientQueueSizeDUnitTest.doPutsIntoRegion(REGION_NAME, num));
vm0.invoke(() -> Awaitility.waitAtMost(45, TimeUnit.SECONDS).until(() -> {
CacheClientProxy ccp = DurableClientQueueSizeDUnitTest.getCacheClientProxy(MY_DURABLE_CLIENT);
assertEquals(0, ccp.getQueueSize());
assertEquals(0, ccp.getQueueSizeStat());
}));
}
use of org.apache.geode.cache.CacheListener in project geode by apache.
the class GemfireDataCommandsDUnitTest method verifyCacheListenerInvocations.
private SerializableRunnable verifyCacheListenerInvocations(final String regionName, boolean callbacksShouldHaveBeenInvoked) {
return new SerializableRunnable() {
public void run() {
Region region = getCache().getRegion(regionName);
CacheListener<?, ?>[] listeners = region.getAttributes().getCacheListeners();
for (CacheListener<?, ?> listener : listeners) {
if (listener instanceof CountingCacheListener) {
CountingCacheListener ccl = (CountingCacheListener) listener;
if (callbacksShouldHaveBeenInvoked) {
assertNotEquals(0, ccl.getEvents());
} else {
assertEquals(0, ccl.getEvents());
}
}
}
}
};
}
use of org.apache.geode.cache.CacheListener in project geode by apache.
the class AbstractRegion method initCacheListeners.
@Override
public void initCacheListeners(CacheListener[] newListeners) {
checkReadiness();
CacheListener[] listenersToAdd = null;
if (newListeners != null) {
listenersToAdd = new CacheListener[newListeners.length];
for (int i = 0; i < newListeners.length; i++) {
listenersToAdd[i] = wrapRegionMembershipListener(newListeners[i]);
}
}
CacheListener[] oldListeners;
synchronized (this.clSync) {
oldListeners = this.cacheListeners;
if (listenersToAdd == null || listenersToAdd.length == 0) {
this.cacheListeners = EMPTY_LISTENERS;
} else {
// we have some listeners to add
if (Arrays.asList(listenersToAdd).contains(null)) {
throw new IllegalArgumentException(LocalizedStrings.AbstractRegion_INITCACHELISTENERS_PARAMETER_HAD_A_NULL_ELEMENT.toLocalizedString());
}
CacheListener[] newCacheListeners = new CacheListener[listenersToAdd.length];
System.arraycopy(listenersToAdd, 0, newCacheListeners, 0, newCacheListeners.length);
this.cacheListeners = newCacheListeners;
}
}
// moved the following out of the sync for bug 34512
if (listenersToAdd == null || listenersToAdd.length == 0) {
if (oldListeners != null && oldListeners.length > 0) {
for (CacheListener oldListener : oldListeners) {
closeCacheCallback(oldListener);
}
cacheListenersChanged(false);
}
} else {
// we had some listeners to add
if (oldListeners != null && oldListeners.length > 0) {
for (CacheListener oldListener : oldListeners) {
closeCacheCallback(oldListener);
}
} else {
cacheListenersChanged(true);
}
}
}
use of org.apache.geode.cache.CacheListener in project geode by apache.
the class AbstractRegion method addCacheListener.
@Override
public void addCacheListener(CacheListener aListener) {
checkReadiness();
if (aListener == null) {
throw new IllegalArgumentException(LocalizedStrings.AbstractRegion_ADDCACHELISTENER_PARAMETER_WAS_NULL.toLocalizedString());
}
CacheListener wcl = wrapRegionMembershipListener(aListener);
boolean changed = false;
synchronized (this.clSync) {
CacheListener[] oldListeners = this.cacheListeners;
if (oldListeners == null || oldListeners.length == 0) {
this.cacheListeners = new CacheListener[] { wcl };
changed = true;
} else {
List<CacheListener> listeners = Arrays.asList(oldListeners);
if (!listeners.contains(aListener)) {
this.cacheListeners = (CacheListener[]) ArrayUtils.insert(oldListeners, oldListeners.length, wcl);
}
}
}
if (changed) {
// moved the following out of the sync for bug 34512
cacheListenersChanged(true);
}
}
Aggregations