This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new 204c4fa  Avoid using named classes for closed channel
204c4fa is described below

commit 204c4fa6c05b644dee31b96f0fff2ed64829d0dc
Author: remm <r...@apache.org>
AuthorDate: Wed Mar 11 14:44:13 2020 +0100

    Avoid using named classes for closed channel
    
    Only the constant is needed.
---
 java/org/apache/tomcat/util/net/Nio2Channel.java | 8 ++------
 java/org/apache/tomcat/util/net/NioChannel.java  | 8 ++------
 java/org/apache/tomcat/util/net/NioEndpoint.java | 5 ++---
 3 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/Nio2Channel.java 
b/java/org/apache/tomcat/util/net/Nio2Channel.java
index 4980170..9c57f02 100644
--- a/java/org/apache/tomcat/util/net/Nio2Channel.java
+++ b/java/org/apache/tomcat/util/net/Nio2Channel.java
@@ -248,11 +248,7 @@ public class Nio2Channel implements 
AsynchronousByteChannel {
         }
     };
 
-    static final Nio2Channel CLOSED_NIO2_CHANNEL = new ClosedNio2Channel();
-    public static class ClosedNio2Channel extends Nio2Channel {
-        public ClosedNio2Channel() {
-            super(SocketBufferHandler.EMPTY);
-        }
+    static final Nio2Channel CLOSED_NIO2_CHANNEL = new 
Nio2Channel(SocketBufferHandler.EMPTY) {
         @Override
         public void close() throws IOException {
         }
@@ -304,5 +300,5 @@ public class Nio2Channel implements AsynchronousByteChannel 
{
         public String toString() {
             return "Closed Nio2Channel";
         }
-    }
+    };
 }
diff --git a/java/org/apache/tomcat/util/net/NioChannel.java 
b/java/org/apache/tomcat/util/net/NioChannel.java
index 065d23b..f35794c 100644
--- a/java/org/apache/tomcat/util/net/NioChannel.java
+++ b/java/org/apache/tomcat/util/net/NioChannel.java
@@ -230,11 +230,7 @@ public class NioChannel implements ByteChannel, 
ScatteringByteChannel, Gathering
         return appReadBufHandler;
     }
 
-    static final NioChannel CLOSED_NIO_CHANNEL = new ClosedNioChannel();
-    public static class ClosedNioChannel extends NioChannel {
-        public ClosedNioChannel() {
-            super(SocketBufferHandler.EMPTY);
-        }
+    static final NioChannel CLOSED_NIO_CHANNEL = new 
NioChannel(SocketBufferHandler.EMPTY) {
         @Override
         public void close() throws IOException {
         }
@@ -274,6 +270,6 @@ public class NioChannel implements ByteChannel, 
ScatteringByteChannel, Gathering
         public String toString() {
             return "Closed NioChannel";
         }
-    }
+    };
 
 }
diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java 
b/java/org/apache/tomcat/util/net/NioEndpoint.java
index 88bddda..9c46678 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -51,7 +51,6 @@ import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.collections.SynchronizedQueue;
 import org.apache.tomcat.util.collections.SynchronizedStack;
 import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState;
-import org.apache.tomcat.util.net.NioChannel.ClosedNioChannel;
 import org.apache.tomcat.util.net.jsse.JSSESupport;
 
 /**
@@ -1139,7 +1138,7 @@ public class NioEndpoint extends 
AbstractJsseEndpoint<NioChannel,SocketChannel>
         private int fillReadBuffer(boolean block, ByteBuffer buffer) throws 
IOException {
             int n = 0;
             NioChannel socket = getSocket();
-            if (socket instanceof ClosedNioChannel) {
+            if (socket == NioChannel.CLOSED_NIO_CHANNEL) {
                 throw new ClosedChannelException();
             }
             if (block) {
@@ -1193,7 +1192,7 @@ public class NioEndpoint extends 
AbstractJsseEndpoint<NioChannel,SocketChannel>
         protected void doWrite(boolean block, ByteBuffer buffer) throws 
IOException {
             int n = 0;
             NioChannel socket = getSocket();
-            if (socket instanceof ClosedNioChannel) {
+            if (socket == NioChannel.CLOSED_NIO_CHANNEL) {
                 throw new ClosedChannelException();
             }
             if (block) {


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to