diff --git a/src/main/java/net/spy/memcached/ConnectionFactory.java b/src/main/java/net/spy/memcached/ConnectionFactory.java index 0c0cde78e..a85a6dda3 100644 --- a/src/main/java/net/spy/memcached/ConnectionFactory.java +++ b/src/main/java/net/spy/memcached/ConnectionFactory.java @@ -124,6 +124,15 @@ MemcachedNode createMemcachedNode(SocketAddress sa, SocketChannel c, */ boolean useNagleAlgorithm(); + /** + * If true, keep alive will be used on connected sockets. + * + *
+ * See {@link java.net.Socket#setKeepAlive(boolean)} for more information. + *
+ */ + boolean getKeepAlive(); + /** * Observers that should be established at the time of connection * instantiation. diff --git a/src/main/java/net/spy/memcached/ConnectionFactoryBuilder.java b/src/main/java/net/spy/memcached/ConnectionFactoryBuilder.java index e7c74209d..b3ece2eec 100644 --- a/src/main/java/net/spy/memcached/ConnectionFactoryBuilder.java +++ b/src/main/java/net/spy/memcached/ConnectionFactoryBuilder.java @@ -61,6 +61,7 @@ public class ConnectionFactoryBuilder { protected boolean isDaemon = false; protected boolean shouldOptimize = false; protected boolean useNagle = false; + protected boolean keepAlive = false; protected long maxReconnectDelay = DefaultConnectionFactory.DEFAULT_MAX_RECONNECT_DELAY; @@ -222,6 +223,11 @@ public ConnectionFactoryBuilder setUseNagleAlgorithm(boolean to) { return this; } + public ConnectionFactoryBuilder setKeepAlive(boolean on) { + keepAlive = on; + return this; + } + /** * Convenience method to specify the protocol to use. */ @@ -400,6 +406,10 @@ public boolean shouldOptimize() { return shouldOptimize; } + public boolean getKeepAlive() { + return keepAlive; + } + @Override public boolean useNagleAlgorithm() { return useNagle; diff --git a/src/main/java/net/spy/memcached/DefaultConnectionFactory.java b/src/main/java/net/spy/memcached/DefaultConnectionFactory.java index bee0c4e30..16623cd3b 100644 --- a/src/main/java/net/spy/memcached/DefaultConnectionFactory.java +++ b/src/main/java/net/spy/memcached/DefaultConnectionFactory.java @@ -388,6 +388,15 @@ public boolean useNagleAlgorithm() { return false; } + /* + * (non-Javadoc) + * + * @see net.spy.memcached.ConnectionFactory#getKeepAlive() + */ + public boolean getKeepAlive() { + return false; + } + /* * (non-Javadoc) * diff --git a/src/main/java/net/spy/memcached/MemcachedConnection.java b/src/main/java/net/spy/memcached/MemcachedConnection.java index 074461728..47f432fb1 100644 --- a/src/main/java/net/spy/memcached/MemcachedConnection.java +++ b/src/main/java/net/spy/memcached/MemcachedConnection.java @@ -47,6 +47,7 @@ import java.io.IOException; import java.net.ConnectException; import java.net.InetSocketAddress; +import java.net.Socket; import java.net.SocketAddress; import java.net.SocketException; import java.nio.ByteBuffer; @@ -349,8 +350,10 @@ protected List