directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject [2/2] directory-kerberos git commit: Avoided some unnecessarily thrown exception
Date Wed, 21 Jan 2015 08:01:28 GMT
Avoided some unnecessarily thrown exception


Project: http://git-wip-us.apache.org/repos/asf/directory-kerberos/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerberos/commit/a69651e9
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerberos/tree/a69651e9
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerberos/diff/a69651e9

Branch: refs/heads/master
Commit: a69651e9daef6f88ce7ab1bb3d2415d0b213701b
Parents: 795e982
Author: drankye <drankye@gmail.com>
Authored: Wed Jan 21 23:58:04 2015 +0800
Committer: drankye <drankye@gmail.com>
Committed: Wed Jan 21 23:58:04 2015 +0800

----------------------------------------------------------------------
 .../apache/haox/event/ExecutedEventHandler.java |  4 +++
 .../java/org/apache/haox/transport/Network.java | 26 +++++++++----------
 .../apache/haox/transport/tcp/TcpAcceptor.java  | 27 +++++++++-----------
 3 files changed, 29 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/a69651e9/contrib/haox-event/src/main/java/org/apache/haox/event/ExecutedEventHandler.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/event/ExecutedEventHandler.java
b/contrib/haox-event/src/main/java/org/apache/haox/event/ExecutedEventHandler.java
index c6ab5b5..c707648 100644
--- a/contrib/haox-event/src/main/java/org/apache/haox/event/ExecutedEventHandler.java
+++ b/contrib/haox-event/src/main/java/org/apache/haox/event/ExecutedEventHandler.java
@@ -35,6 +35,10 @@ public class ExecutedEventHandler extends AbstractInternalEventHandler
{
 
     @Override
     protected void doHandle(final Event event) throws Exception {
+        if (executorService.isTerminated()) {
+            return;
+        }
+
         executorService.execute(new Runnable() {
             @Override
             public void run() {

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/a69651e9/contrib/haox-event/src/main/java/org/apache/haox/transport/Network.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/transport/Network.java b/contrib/haox-event/src/main/java/org/apache/haox/transport/Network.java
index c8b4776..a61925e 100644
--- a/contrib/haox-event/src/main/java/org/apache/haox/transport/Network.java
+++ b/contrib/haox-event/src/main/java/org/apache/haox/transport/Network.java
@@ -260,25 +260,25 @@ public class Network extends LongRunningEventHandler {
         dispatch(event);
     }
 
-    void doTcpAccept(SelectionKey key) throws IOException {
+    protected void doTcpAccept(SelectionKey key) throws IOException {
         ServerSocketChannel server = (ServerSocketChannel) key.channel();
         SocketChannel channel;
-        while ((channel = server.accept()) != null) {
-            // Quick fix: avoid exception during exiting
-            if (! selector.isOpen()) {
-                channel.close();
-                break;
-            };
 
-            channel.configureBlocking(false);
-            channel.socket().setTcpNoDelay(true);
-            channel.socket().setKeepAlive(true);
+        try {
+            while ((channel = server.accept()) != null) {
+                channel.configureBlocking(false);
+                channel.socket().setTcpNoDelay(true);
+                channel.socket().setKeepAlive(true);
 
-            Transport transport = new TcpTransport(channel,
+                Transport transport = new TcpTransport(channel,
                     tcpTransportHandler.getStreamingDecoder());
-            channel.register(selector,
+
+                channel.register(selector,
                     SelectionKey.OP_READ | SelectionKey.OP_WRITE, transport);
-            onNewTransport(transport);
+                onNewTransport(transport);
+            }
+        } catch (ClosedByInterruptException e) {
+            // No op as normal
         }
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/a69651e9/contrib/haox-event/src/main/java/org/apache/haox/transport/tcp/TcpAcceptor.java
----------------------------------------------------------------------
diff --git a/contrib/haox-event/src/main/java/org/apache/haox/transport/tcp/TcpAcceptor.java
b/contrib/haox-event/src/main/java/org/apache/haox/transport/tcp/TcpAcceptor.java
index b6241cf..32d6614 100644
--- a/contrib/haox-event/src/main/java/org/apache/haox/transport/tcp/TcpAcceptor.java
+++ b/contrib/haox-event/src/main/java/org/apache/haox/transport/tcp/TcpAcceptor.java
@@ -29,6 +29,7 @@ import org.apache.haox.transport.event.AddressEvent;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
+import java.nio.channels.ClosedByInterruptException;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.SocketChannel;
@@ -81,26 +82,22 @@ public class TcpAcceptor extends Acceptor {
     void doAccept(SelectionKey key) throws IOException {
         ServerSocketChannel server = (ServerSocketChannel) key.channel();
         SocketChannel channel;
-        while ((channel = server.accept()) != null) {
-            // Quick fix: avoid exception during exiting
-            if (! selector.isOpen()) {
-                channel.close();
-                break;
-            };
 
-            channel.configureBlocking(false);
-            channel.socket().setTcpNoDelay(true);
-            channel.socket().setKeepAlive(true);
+        try {
+            while ((channel = server.accept()) != null) {
+                channel.configureBlocking(false);
+                channel.socket().setTcpNoDelay(true);
+                channel.socket().setKeepAlive(true);
 
-            Transport transport = new TcpTransport(channel,
+                Transport transport = new TcpTransport(channel,
                     ((TcpTransportHandler) transportHandler).getStreamingDecoder());
 
-            if (! selector.isOpen()) {
-                break;
+                channel.register(selector,
+                    SelectionKey.OP_READ | SelectionKey.OP_WRITE, transport);
+                onNewTransport(transport);
             }
-            channel.register(selector,
-                SelectionKey.OP_READ | SelectionKey.OP_WRITE, transport);
-            onNewTransport(transport);
+        } catch (ClosedByInterruptException e) {
+            // No op as normal
         }
     }
 


Mime
View raw message