Search in sources :

Example 1 with FailureTracker

use of org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker in project geode by apache.

the class ServerBlackListJUnitTest method testBlackListing.

@Test
public void testBlackListing() throws Exception {
    ServerLocation location1 = new ServerLocation("localhost", 1);
    FailureTracker tracker1 = blackList.getFailureTracker(location1);
    tracker1.addFailure();
    tracker1.addFailure();
    assertEquals(Collections.EMPTY_SET, blackList.getBadServers());
    tracker1.addFailure();
    assertEquals(Collections.singleton(location1), blackList.getBadServers());
    boolean done = false;
    for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 10000; done = (blackList.getBadServers().size() == 0)) {
        Thread.sleep(200);
    }
    assertTrue("blackList still has bad servers", done);
    assertEquals(Collections.EMPTY_SET, blackList.getBadServers());
}
Also used : FailureTracker(org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) 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 FailureTracker

use of org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker 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 3 with FailureTracker

use of org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker in project geode by apache.

the class QueueManagerImpl method initializeQueueConnection.

private QueueConnectionImpl initializeQueueConnection(Connection connection, boolean isPrimary, ClientUpdater failedUpdater) {
    QueueConnectionImpl queueConnection = null;
    FailureTracker failureTracker = blackList.getFailureTracker(connection.getServer());
    try {
        ClientUpdater updater = factory.createServerToClientConnection(connection.getEndpoint(), this, isPrimary, failedUpdater);
        if (updater != null) {
            queueConnection = new QueueConnectionImpl(this, connection, updater, failureTracker);
        } else {
            logger.warn(LocalizedMessage.create(LocalizedStrings.QueueManagerImpl_UNABLE_TO_CREATE_A_SUBSCRIPTION_CONNECTION_TO_SERVER_0, connection.getEndpoint()));
        }
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("error creating subscription connection to server {}", connection.getEndpoint(), e);
        }
    }
    if (queueConnection == null) {
        failureTracker.addFailure();
        connection.destroy();
    }
    return queueConnection;
}
Also used : FailureTracker(org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker) CacheClientUpdater(org.apache.geode.internal.cache.tier.sockets.CacheClientUpdater) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) GemFireException(org.apache.geode.GemFireException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) GemFireConfigException(org.apache.geode.GemFireConfigException) NoSubscriptionServersAvailableException(org.apache.geode.cache.NoSubscriptionServersAvailableException)

Example 4 with FailureTracker

use of org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker in project geode by apache.

the class ConnectionFactoryImpl method createClientToServerConnection.

public Connection createClientToServerConnection(ServerLocation location, boolean forQueue) throws GemFireSecurityException {
    ConnectionImpl connection = new ConnectionImpl(this.ds, this.cancelCriterion);
    FailureTracker failureTracker = blackList.getFailureTracker(location);
    boolean initialized = false;
    try {
        HandShake connHandShake = new HandShake(handshake);
        connection.connect(endpointManager, location, connHandShake, socketBufferSize, handShakeTimeout, readTimeout, getCommMode(forQueue), this.gatewaySender, this.socketCreator);
        failureTracker.reset();
        connection.setHandShake(connHandShake);
        authenticateIfRequired(connection);
        initialized = true;
    } catch (GemFireConfigException e) {
        throw e;
    } catch (CancelException e) {
        // propagate this up, don't retry
        throw e;
    } catch (GemFireSecurityException e) {
        // propagate this up, don't retry
        throw e;
    } catch (GatewayConfigurationException e) {
        // propagate this up, don't retry
        throw e;
    } catch (ServerRefusedConnectionException src) {
        // propagate this up, don't retry
        logger.warn(LocalizedMessage.create(LocalizedStrings.AutoConnectionSourceImpl_COULD_NOT_CREATE_A_NEW_CONNECTION_TO_SERVER_0, src.getMessage()));
        testFailedConnectionToServer = true;
        throw src;
    } catch (Exception e) {
        if (e.getMessage() != null && (e.getMessage().equals("Connection refused") || e.getMessage().equals("Connection reset"))) {
            // print an exception
            if (logger.isDebugEnabled()) {
                logger.debug("Unable to connect to {}: connection refused", location);
            }
        } else {
            // print a warning with the exception stack trace
            logger.warn(LocalizedMessage.create(LocalizedStrings.ConnectException_COULD_NOT_CONNECT_TO_0, location), e);
        }
        testFailedConnectionToServer = true;
    } finally {
        if (!initialized) {
            connection.destroy();
            failureTracker.addFailure();
            connection = null;
        }
    }
    return connection;
}
Also used : HandShake(org.apache.geode.internal.cache.tier.sockets.HandShake) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) FailureTracker(org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker) GatewayConfigurationException(org.apache.geode.cache.GatewayConfigurationException) GemFireConfigException(org.apache.geode.GemFireConfigException) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) CancelException(org.apache.geode.CancelException) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) GatewayConfigurationException(org.apache.geode.cache.GatewayConfigurationException) GemFireConfigException(org.apache.geode.GemFireConfigException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException)

Aggregations

FailureTracker (org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker)4 CancelException (org.apache.geode.CancelException)2 GemFireConfigException (org.apache.geode.GemFireConfigException)2 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)2 StopWatch (org.apache.geode.internal.util.StopWatch)2 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)2 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2 Test (org.junit.Test)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 GemFireException (org.apache.geode.GemFireException)1 GatewayConfigurationException (org.apache.geode.cache.GatewayConfigurationException)1 NoSubscriptionServersAvailableException (org.apache.geode.cache.NoSubscriptionServersAvailableException)1 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)1 ServerRefusedConnectionException (org.apache.geode.cache.client.ServerRefusedConnectionException)1 BlackListListenerAdapter (org.apache.geode.cache.client.internal.ServerBlackList.BlackListListenerAdapter)1 CacheClientUpdater (org.apache.geode.internal.cache.tier.sockets.CacheClientUpdater)1 HandShake (org.apache.geode.internal.cache.tier.sockets.HandShake)1