[infinispan-commits] Infinispan SVN: r1697 - in trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod: impl and 3 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Thu Apr 15 20:18:57 EDT 2010
Author: mircea.markus
Date: 2010-04-15 20:18:56 -0400 (Thu, 15 Apr 2010)
New Revision: 1697
Added:
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/exceptions/TransportException.java
Removed:
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/TransportException.java
Modified:
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperationsImpl.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/VHelper.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/HotrodClientDecoder.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/HotrodClientEncoder.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/InputStreamAdapter.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransport.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransport.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransportFactory.java
Log:
better sync
Copied: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/exceptions/TransportException.java (from rev 1693, trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/TransportException.java)
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/exceptions/TransportException.java (rev 0)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/exceptions/TransportException.java 2010-04-16 00:18:56 UTC (rev 1697)
@@ -0,0 +1,26 @@
+package org.infinispan.client.hotrod.exceptions;
+
+import org.infinispan.client.hotrod.exceptions.HotRodException;
+
+/**
+ * // TODO: Document this
+ *
+ * @author mmarkus
+ * @since 4.1
+ */
+public class TransportException extends HotRodException {
+ public TransportException() {
+ }
+
+ public TransportException(String message) {
+ super(message);
+ }
+
+ public TransportException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public TransportException(Throwable cause) {
+ super(cause);
+ }
+}
\ No newline at end of file
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperationsImpl.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperationsImpl.java 2010-04-15 23:46:26 UTC (rev 1696)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperationsImpl.java 2010-04-16 00:18:56 UTC (rev 1697)
@@ -4,7 +4,7 @@
import org.infinispan.client.hotrod.exceptions.HotRodClientException;
import org.infinispan.client.hotrod.exceptions.InvalidResponseException;
import org.infinispan.client.hotrod.exceptions.TimeoutException;
-import org.infinispan.client.hotrod.impl.transport.TransportException;
+import org.infinispan.client.hotrod.exceptions.TransportException;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
Deleted: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/TransportException.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/TransportException.java 2010-04-15 23:46:26 UTC (rev 1696)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/TransportException.java 2010-04-16 00:18:56 UTC (rev 1697)
@@ -1,26 +0,0 @@
-package org.infinispan.client.hotrod.impl.transport;
-
-import org.infinispan.client.hotrod.exceptions.HotRodException;
-
-/**
- * // TODO: Document this
- *
- * @author mmarkus
- * @since 4.1
- */
-public class TransportException extends HotRodException {
- public TransportException() {
- }
-
- public TransportException(String message) {
- super(message);
- }
-
- public TransportException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public TransportException(Throwable cause) {
- super(cause);
- }
-}
\ No newline at end of file
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/VHelper.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/VHelper.java 2010-04-15 23:46:26 UTC (rev 1696)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/VHelper.java 2010-04-16 00:18:56 UTC (rev 1697)
@@ -1,6 +1,7 @@
package org.infinispan.client.hotrod.impl.transport;
import org.infinispan.client.hotrod.exceptions.HotRodClientException;
+import org.infinispan.client.hotrod.exceptions.TransportException;
import org.infinispan.io.UnsignedNumeric;
import org.infinispan.util.Util;
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/HotrodClientDecoder.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/HotrodClientDecoder.java 2010-04-15 23:46:26 UTC (rev 1696)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/HotrodClientDecoder.java 2010-04-16 00:18:56 UTC (rev 1697)
@@ -1,6 +1,6 @@
package org.infinispan.client.hotrod.impl.transport.netty;
-import org.infinispan.client.hotrod.impl.transport.TransportException;
+import org.infinispan.client.hotrod.exceptions.TransportException;
import org.infinispan.client.hotrod.impl.transport.VHelper;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/HotrodClientEncoder.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/HotrodClientEncoder.java 2010-04-15 23:46:26 UTC (rev 1696)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/HotrodClientEncoder.java 2010-04-16 00:18:56 UTC (rev 1697)
@@ -1,8 +1,7 @@
package org.infinispan.client.hotrod.impl.transport.netty;
-import org.infinispan.client.hotrod.impl.transport.TransportException;
+import org.infinispan.client.hotrod.exceptions.TransportException;
import org.infinispan.client.hotrod.impl.transport.VHelper;
-import org.infinispan.io.ExposedByteArrayOutputStream;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/InputStreamAdapter.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/InputStreamAdapter.java 2010-04-15 23:46:26 UTC (rev 1696)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/InputStreamAdapter.java 2010-04-16 00:18:56 UTC (rev 1697)
@@ -1,6 +1,6 @@
package org.infinispan.client.hotrod.impl.transport.netty;
-import org.infinispan.client.hotrod.impl.transport.TransportException;
+import org.infinispan.client.hotrod.exceptions.TransportException;
import org.jboss.netty.buffer.ChannelBuffer;
import java.io.IOException;
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransport.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransport.java 2010-04-15 23:46:26 UTC (rev 1696)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/netty/NettyTransport.java 2010-04-16 00:18:56 UTC (rev 1697)
@@ -1,7 +1,7 @@
package org.infinispan.client.hotrod.impl.transport.netty;
+import org.infinispan.client.hotrod.exceptions.TransportException;
import org.infinispan.client.hotrod.impl.AbstractTransport;
-import org.infinispan.client.hotrod.impl.transport.TransportException;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
import org.jboss.netty.bootstrap.ClientBootstrap;
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransport.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransport.java 2010-04-15 23:46:26 UTC (rev 1696)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransport.java 2010-04-16 00:18:56 UTC (rev 1697)
@@ -1,7 +1,7 @@
package org.infinispan.client.hotrod.impl.transport.tcp;
import org.infinispan.client.hotrod.impl.AbstractTransport;
-import org.infinispan.client.hotrod.impl.transport.TransportException;
+import org.infinispan.client.hotrod.exceptions.TransportException;
import org.infinispan.client.hotrod.impl.transport.VHelper;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransportFactory.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransportFactory.java 2010-04-15 23:46:26 UTC (rev 1696)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/tcp/TcpTransportFactory.java 2010-04-16 00:18:56 UTC (rev 1697)
@@ -1,21 +1,22 @@
package org.infinispan.client.hotrod.impl.transport.tcp;
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
+import org.infinispan.client.hotrod.exceptions.TransportException;
import org.infinispan.client.hotrod.impl.Transport;
import org.infinispan.client.hotrod.impl.TransportFactory;
-import org.infinispan.client.hotrod.impl.transport.TransportException;
import org.infinispan.client.hotrod.impl.transport.VHelper;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
import java.net.InetSocketAddress;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
/**
* // TODO: Document this
- *
+ * <p/>
* todo - all methods but start and start can be called from multiple threads, add proper sync
*
* @author Mircea.Markus at jboss.com
@@ -23,19 +24,22 @@
*/
public class TcpTransportFactory implements TransportFactory {
- private static Log log = LogFactory.getLog(TcpTransportFactory.class);
+ private static final Log log = LogFactory.getLog(TcpTransportFactory.class);
+ /**
+ * These are declared volatile as the thread that calls {@link #start(java.util.Properties, java.util.Collection)}
+ * might(and likely will) be different from the thread that calls {@link #getTransport()} or other methods
+ */
private volatile GenericKeyedObjectPool connectionPool;
- private PropsKeyedObjectPoolFactory poolFactory;
- private RequestBalancingStrategy balancer;
- private Collection<InetSocketAddress> servers;
+ private volatile RequestBalancingStrategy balancer;
+ private volatile Collection<InetSocketAddress> servers;
@Override
public void start(Properties props, Collection<InetSocketAddress> staticConfiguredServers) {
servers = staticConfiguredServers;
String balancerClass = props.getProperty("requestBalancingStrategy", RoundRobinBalancingStrategy.class.getName());
balancer = (RequestBalancingStrategy) VHelper.newInstance(balancerClass);
- poolFactory = new PropsKeyedObjectPoolFactory(new TcpConnectionFactory(), props);
+ PropsKeyedObjectPoolFactory poolFactory = new PropsKeyedObjectPoolFactory(new TcpConnectionFactory(), props);
connectionPool = (GenericKeyedObjectPool) poolFactory.createPool();
balancer.setServers(servers);
}
@@ -68,34 +72,46 @@
try {
connectionPool.returnObject(tcpTransport.getServerAddress(), tcpTransport);
} catch (Exception e) {
- log.warn("Could not release connection: " + tcpTransport,e);
+ log.warn("Could not release connection: " + tcpTransport, e);
}
}
@Override
public void updateServers(Collection<InetSocketAddress> newServers) {
- if (newServers.containsAll(servers) && servers.containsAll(newServers)) {
- log.info("Same list of servers, not changing the pool");
- return;
- }
- for (InetSocketAddress server : newServers) {
- if (!servers.contains(server)) {
- log.info("New server added(" + server + "), adding to the pool.");
+ synchronized (this) {//only one updateServers at a time.
+ Set<InetSocketAddress> addedServers = new HashSet<InetSocketAddress>(newServers);
+ addedServers.removeAll(servers);
+ Set<InetSocketAddress> failedServers = new HashSet<InetSocketAddress>(servers);
+ failedServers.removeAll(newServers);
+ if (failedServers.isEmpty() || newServers.isEmpty()) {
+ log.info("Same list of servers, not changing the pool");
+ return;
+ }
+
+ //1. first add new servers. For servers that went down, the returned transport will fail for now
+ for (InetSocketAddress server : newServers) {
try {
connectionPool.addObject(server);
} catch (Exception e) {
- log.warn("Failed adding server " + server, e);
+ log.warn("Failed adding new server " + server, e);
}
+ log.info("New server added(" + server + "), adding to the pool.");
}
- }
- for (InetSocketAddress server : servers) {
- if (!newServers.contains(server)) {
+
+ //2. now set the server list to the active list of servers. All the active servers (potentially together with some
+ // failed servers) are in the pool now. But after this, the pool won't be asked for connections to failed servers,
+ // as the balancer will only know about the active servers
+ balancer.setServers(newServers);
+
+
+ //3. Now just remove failed servers
+ for (InetSocketAddress server : failedServers) {
log.info("Server not in cluster anymore(" + server + "), removing from the pool.");
connectionPool.clear(server);
}
+
+ servers.clear();
+ servers.addAll(addedServers);
}
- servers.clear();
- servers.addAll(newServers);
}
-
}
More information about the infinispan-commits
mailing list