use of org.apache.geode.cache.client.internal.ServerBlackList.BlackListListenerAdapter in project geode by apache.
the class ServerBlackListJUnitTest method testListener.
@Test
public void testListener() throws Exception {
final AtomicInteger adds = new AtomicInteger();
final AtomicInteger removes = new AtomicInteger();
blackList.addListener(new BlackListListenerAdapter() {
@Override
public void serverAdded(ServerLocation location) {
adds.incrementAndGet();
}
@Override
public void serverRemoved(ServerLocation location) {
removes.incrementAndGet();
}
});
ServerLocation location1 = new ServerLocation("localhost", 1);
FailureTracker tracker1 = blackList.getFailureTracker(location1);
tracker1.addFailure();
tracker1.addFailure();
assertEquals(0, adds.get());
assertEquals(0, removes.get());
tracker1.addFailure();
assertEquals(1, adds.get());
assertEquals(0, removes.get());
boolean done = false;
for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 10000; done = (removes.get() != 0)) {
Thread.sleep(200);
}
assertTrue("removes still empty", done);
assertEquals(1, adds.get());
assertEquals(1, removes.get());
}
use of org.apache.geode.cache.client.internal.ServerBlackList.BlackListListenerAdapter in project geode by apache.
the class QueueManagerImpl method start.
public void start(ScheduledExecutorService background) {
try {
blackList.start(background);
endpointManager.addListener(endpointListener);
// Use a separate timer for queue management tasks
// We don't want primary recovery (and therefore user threads) to wait for
// things like pinging connections for health checks.
// this.background = background;
final String name = "queueTimer-" + this.pool.getName();
this.recoveryThread = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
public Thread newThread(Runnable r) {
Thread result = new Thread(r, name);
result.setDaemon(true);
return result;
}
});
recoveryThread.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
// TODO - use yet another Timer or the like for these tasks? We know
// we don't want them in the recoveryThread, because the ThreadIdToSequenceIdExpiryTask
// will wait for primary recovery.
getState().start(background, getPool().getSubscriptionAckInterval());
// initialize connections
initializeConnections();
scheduleRedundancySatisfierIfNeeded(redundancyRetryInterval);
// When a server is removed from the blacklist, try again
// to establish redundancy (if we need to)
BlackListListener blackListListener = new BlackListListenerAdapter() {
@Override
public void serverRemoved(ServerLocation location) {
QueueManagerImpl.this.scheduleRedundancySatisfierIfNeeded(0);
}
};
blackList.addListener(blackListListener);
factory.getBlackList().addListener(blackListListener);
} finally {
initializedLatch.countDown();
}
}
Aggregations