Permalink
Browse files

ISPN-2509 Force transport instance creation if pingOnStartup enabled

  • Loading branch information...
galderz authored and Mircea Markus committed Mar 1, 2013
1 parent c6f6e71 commit d334b7d19fe651b9fda82319b9ff35cf20f7dcb5
@@ -39,6 +39,7 @@
import org.infinispan.client.hotrod.impl.ConfigurationProperties;
import org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash;
import org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashFactory;
+import org.infinispan.client.hotrod.impl.operations.PingOperation;
import org.infinispan.client.hotrod.impl.protocol.Codec;
import org.infinispan.client.hotrod.impl.transport.Transport;
import org.infinispan.client.hotrod.impl.transport.TransportFactory;
@@ -100,6 +101,27 @@ public void start(Codec codec, ConfigurationProperties cfg,
balancer.setServers(servers);
updateTransportCount();
}
+
+ if (cfg.getPingOnStartup())
+ pingServers(staticConfiguredServers);
+ }
+
+ private void pingServers(Collection<SocketAddress> staticConfiguredServers) {
+ GenericKeyedObjectPool<SocketAddress, TcpTransport> pool = getConnectionPool();
+ for (SocketAddress addr : staticConfiguredServers) {
+ try {
+ // Go through all statically configured nodes and force a
+ // connection to be established and a ping message to be sent.
+ pool.returnObject(addr, pool.borrowObject(addr));
+ } catch (Exception e) {
+ // Ping's objective is to retrieve a potentially newer
+ // version of the Hot Rod cluster topology, so ignore
+ // exceptions from nodes that might not be up any more.
+ if (log.isTraceEnabled())
+ log.tracef(e, "Ignoring exception pinging configured servers %s to establish a connection",
+ staticConfiguredServers);
+ }
+ }
}
/**
@@ -38,6 +38,9 @@
import static org.testng.AssertJUnit.assertFalse;
/**
+ * Tests ping-on-startup logic whose objective is to retrieve the Hot Rod
+ * server topology before a client executes an operation against the server.
+ *
* @author Mircea.Markus@jboss.com
* @since 4.1
*/
@@ -56,7 +59,6 @@ public void testTopologyFetched() {
props.put("infinispan.client.hotrod.server_list",
"localhost:" + hotRodServer2.getPort() + ";localhost:" + hotRodServer2.getPort());
props.put("infinispan.client.hotrod.ping_on_startup", "true");
- props.put("timeBetweenEvictionRunsMillis", "500");
withRemoteCacheManager(new RemoteCacheManagerCallable(
new RemoteCacheManager(props)) {
@@ -131,7 +133,6 @@ public void testGetCacheWorksIfNodeDown() {
props.put("infinispan.client.hotrod.server_list",
"boomoo:12345;localhost:" + hotRodServer2.getPort());
props.put("infinispan.client.hotrod.ping_on_startup", "true");
- props.put("timeBetweenEvictionRunsMillis", "500");
withRemoteCacheManager(new RemoteCacheManagerCallable(
new RemoteCacheManager(props)) {
@@ -148,7 +149,6 @@ public void testGetCacheWorksIfNodeNotDown() {
props.put("infinispan.client.hotrod.server_list",
"localhost:" + hotRodServer2.getPort());
props.put("infinispan.client.hotrod.ping_on_startup", "true");
- props.put("timeBetweenEvictionRunsMillis", "500");
withRemoteCacheManager(new RemoteCacheManagerCallable(
new RemoteCacheManager(props)) {
@Override

0 comments on commit d334b7d

Please sign in to comment.