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());
}
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());
}
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;
}
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;
}
Aggregations