Przeglądaj źródła

ZOOKEEPER-910: Use SelectionKey.isXYZ() methods instead of complicated binary logic

ZOOKEEPER-910: Use SelectionKey.isXYZ() methods instead of complicated binary logic

Signed-off-by: tison <wander4096@gmail.com>
Co-authored-by: Michi Mutsuzaki <michim@apache.org>
Reviewers: kezhuw, anmolnar
Author: tisonkun
Closes #2063 from tisonkun/ZOOKEEPER-910
tison 1 rok temu
rodzic
commit
6c2d94d049

+ 3 - 3
zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxnSocketNIO.java

@@ -335,18 +335,18 @@ public class ClientCnxnSocketNIO extends ClientCnxnSocket {
             selected = selector.selectedKeys();
         }
         // Everything below and until we get back to the select is
-        // non blocking, so time is effectively a constant. That is
+        // non-blocking, so time is effectively a constant. That is
         // Why we just have to do this once, here
         updateNow();
         for (SelectionKey k : selected) {
             SocketChannel sc = ((SocketChannel) k.channel());
-            if ((k.readyOps() & SelectionKey.OP_CONNECT) != 0) {
+            if (k.isConnectable()) {
                 if (sc.finishConnect()) {
                     updateLastSendAndHeard();
                     updateSocketAddresses();
                     sendThread.primeConnection();
                 }
-            } else if ((k.readyOps() & (SelectionKey.OP_READ | SelectionKey.OP_WRITE)) != 0) {
+            } else if (k.isReadable() || k.isWritable()) {
                 doIO(pendingQueue, cnxn);
             }
         }