Search in sources :

Example 1 with BlackListListenerAdapter

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());
}
Also used : FailureTracker(org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) BlackListListenerAdapter(org.apache.geode.cache.client.internal.ServerBlackList.BlackListListenerAdapter) StopWatch(org.apache.geode.internal.util.StopWatch) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 2 with BlackListListenerAdapter

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();
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) BlackListListener(org.apache.geode.cache.client.internal.ServerBlackList.BlackListListener) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) BlackListListenerAdapter(org.apache.geode.cache.client.internal.ServerBlackList.BlackListListenerAdapter)

Aggregations

BlackListListenerAdapter (org.apache.geode.cache.client.internal.ServerBlackList.BlackListListenerAdapter)2 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)2 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BlackListListener (org.apache.geode.cache.client.internal.ServerBlackList.BlackListListener)1 FailureTracker (org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker)1 StopWatch (org.apache.geode.internal.util.StopWatch)1 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)1 UnitTest (org.apache.geode.test.junit.categories.UnitTest)1 Test (org.junit.Test)1