Repository: storm
Updated Branches:
  refs/heads/1.x-branch e00151469 -> 8922f2037


Merge branch 'netty-best-effort' of https://github.com/redsanket/storm into 
STORM-1609


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/2cfa136a
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/2cfa136a
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/2cfa136a

Branch: refs/heads/1.x-branch
Commit: 2cfa136a4ac1dca7d3ef4169ebdb9b315bcf2cae
Parents: e001514
Author: Sriharsha Chintalapani <[email protected]>
Authored: Sat Mar 12 17:47:10 2016 -0800
Committer: Sriharsha Chintalapani <[email protected]>
Committed: Sat Mar 12 17:56:09 2016 -0800

----------------------------------------------------------------------
 .../apache/storm/messaging/netty/Client.java    | 34 ++++++++++++++++++++
 1 file changed, 34 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/2cfa136a/storm-core/src/jvm/org/apache/storm/messaging/netty/Client.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/org/apache/storm/messaging/netty/Client.java 
b/storm-core/src/jvm/org/apache/storm/messaging/netty/Client.java
index 976b550..035eb1b 100644
--- a/storm-core/src/jvm/org/apache/storm/messaging/netty/Client.java
+++ b/storm-core/src/jvm/org/apache/storm/messaging/netty/Client.java
@@ -23,6 +23,7 @@ import java.util.Iterator;
 import java.util.Collection;
 import java.util.Map;
 import java.util.HashMap;
+import java.util.Timer;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
@@ -74,6 +75,7 @@ public class Client extends ConnectionWithStatus implements 
IStatefulObject, ISa
     private static final Logger LOG = LoggerFactory.getLogger(Client.class);
     private static final String PREFIX = "Netty-Client-";
     private static final long NO_DELAY_MS = 0L;
+    private static final Timer timer = new Timer("Netty-ChannelAlive-Timer", 
true);
 
     private final Map stormConf;
     private final StormBoundedExponentialBackoffRetry retryPolicy;
@@ -108,6 +110,12 @@ public class Client extends ConnectionWithStatus 
implements IStatefulObject, ISa
     private final AtomicInteger messagesLost = new AtomicInteger(0);
 
     /**
+     * Periodically checks for connected channel in order to avoid loss
+     * of messages
+     */
+    private final long CHANNEL_ALIVE_INTERVAL_MS = 30000L;
+
+    /**
      * Number of messages buffered in memory.
      */
     private final AtomicLong pendingMessages = new AtomicLong(0);
@@ -151,10 +159,36 @@ public class Client extends ConnectionWithStatus 
implements IStatefulObject, ISa
         bootstrap = createClientBootstrap(factory, bufferSize, stormConf);
         dstAddress = new InetSocketAddress(host, port);
         dstAddressPrefixedName = prefixedName(dstAddress);
+        launchChannelAliveThread();
         scheduleConnect(NO_DELAY_MS);
         batcher = new MessageBuffer(messageBatchSize);
     }
 
+    /**
+     * This thread helps us to check for channel connection periodically.
+     * This is performed just to know whether the destination address
+     * is alive or attempts to refresh connections if not alive. This
+     * solution is better than what we have now in case of a bad channel.
+     */
+    private void launchChannelAliveThread() {
+        // netty TimerTask is already defined and hence a fully
+        // qualified name
+        timer.schedule(new java.util.TimerTask() {
+            public void run() {
+                try {
+                    LOG.debug("running timer task, address {}", dstAddress);
+                    if(closing) {
+                        this.cancel();
+                        return;
+                    }
+                    getConnectedChannel();
+                } catch (Exception exp) {
+                    LOG.error("channel connection error {}", exp);
+                }
+            }
+        }, 0, CHANNEL_ALIVE_INTERVAL_MS);
+    }
+
     private ClientBootstrap createClientBootstrap(ChannelFactory factory, int 
bufferSize, Map stormConf) {
         ClientBootstrap bootstrap = new ClientBootstrap(factory);
         bootstrap.setOption("tcpNoDelay", true);

Reply via email to