zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cami...@apache.org
Subject svn commit: r1172404 - /zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/ClientCnxn.java
Date Mon, 19 Sep 2011 00:59:16 GMT
Author: camille
Date: Mon Sep 19 00:59:16 2011
New Revision: 1172404

URL: http://svn.apache.org/viewvc?rev=1172404&view=rev
Log:
rolling back excess checkin from ZOOKEEPER-961

Modified:
    zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/ClientCnxn.java

Modified: zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/ClientCnxn.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/ClientCnxn.java?rev=1172404&r1=1172403&r2=1172404&view=diff
==============================================================================
--- zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/ClientCnxn.java (original)
+++ zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/ClientCnxn.java Mon Sep
19 00:59:16 2011
@@ -1031,7 +1031,7 @@ public class ClientCnxn {
 
         Random r = new Random(System.nanoTime());
 
-        private boolean startConnect() throws IOException {
+        private void startConnect() throws IOException {
             if (lastConnectIndex == -1) {
                 // We don't want to delay the first try at a connect, so we
                 // start with -1 the first time around
@@ -1051,37 +1051,32 @@ public class ClientCnxn {
                     }
                 }
             }
-            // don't re-establish connection if we are closing
-            if (!closing && zooKeeper.state.isAlive()) {
-                zooKeeper.state = States.CONNECTING;
-                currentConnectIndex = nextAddrToTry;
-                InetSocketAddress addr = serverAddrs.get(nextAddrToTry);
-                nextAddrToTry++;
-                if (nextAddrToTry == serverAddrs.size()) {
-                    nextAddrToTry = 0;
-                }
-                LOG.info("Opening socket connection to server " + addr);
-                SocketChannel sock;
-                sock = SocketChannel.open();
-                sock.configureBlocking(false);
-                sock.socket().setSoLinger(false, -1);
-                sock.socket().setTcpNoDelay(true);
-                setName(getName().replaceAll("\\(.*\\)",
-                        "(" + addr.getHostName() + ":" + addr.getPort() + ")"));
-                sockKey = sock.register(selector, SelectionKey.OP_CONNECT);
-                if (sock.connect(addr)) {
-                    primeConnection(sockKey);
-                }
-                initialized = false;
-    
-                /*
-                 * Reset incomingBuffer
-                 */
-                lenBuffer.clear();
-                incomingBuffer = lenBuffer;
-                return true;
-            }
-            return false;
+            zooKeeper.state = States.CONNECTING;
+            currentConnectIndex = nextAddrToTry;
+            InetSocketAddress addr = serverAddrs.get(nextAddrToTry);
+            nextAddrToTry++;
+            if (nextAddrToTry == serverAddrs.size()) {
+                nextAddrToTry = 0;
+            }
+            LOG.info("Opening socket connection to server " + addr);
+            SocketChannel sock;
+            sock = SocketChannel.open();
+            sock.configureBlocking(false);
+            sock.socket().setSoLinger(false, -1);
+            sock.socket().setTcpNoDelay(true);
+            setName(getName().replaceAll("\\(.*\\)",
+                    "(" + addr.getHostName() + ":" + addr.getPort() + ")"));
+            sockKey = sock.register(selector, SelectionKey.OP_CONNECT);
+            if (sock.connect(addr)) {
+                primeConnection(sockKey);
+            }
+            initialized = false;
+
+            /*
+             * Reset incomingBuffer
+             */
+            lenBuffer.clear();
+            incomingBuffer = lenBuffer;
         }
 
         private static final String RETRY_CONN_MSG =
@@ -1095,10 +1090,11 @@ public class ClientCnxn {
             while (zooKeeper.state.isAlive()) {
                 try {
                     if (sockKey == null) {
-                        boolean connecting = startConnect();
-                        if (!connecting) {
+                        // don't re-establish connection if we are closing
+                        if (closing) {
                             break;
                         }
+                        startConnect();
                         lastSend = now;
                         lastHeard = now;
                     }
@@ -1165,7 +1161,7 @@ public class ClientCnxn {
                     }
                     selected.clear();
                 } catch (Exception e) {
-                    if (closing || !zooKeeper.state.isAlive()) {
+                    if (closing) {
                         if (LOG.isDebugEnabled()) {
                             // closing so this is expected
                             LOG.debug("An exception was thrown while closing send thread
for session 0x"



Mime
View raw message