You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/10/12 10:12:54 UTC

[tomcat] 01/03: Refactor in preparation for adding initial Loom endpoint

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

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

commit 1c21f344bed88f9846bd8c172e4181325b8a64ea
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Oct 12 10:48:19 2022 +0100

    Refactor in preparation for adding initial Loom endpoint
---
 .../apache/tomcat/util/net/AbstractEndpoint.java   | 17 +--------
 .../util/net/AbstractNetworkChannelEndpoint.java   | 43 ++++++++++++++++++++++
 java/org/apache/tomcat/util/net/Nio2Endpoint.java  |  2 +-
 java/org/apache/tomcat/util/net/NioEndpoint.java   |  2 +-
 4 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
index 1e473fe9a1..4e3b692ad1 100644
--- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
@@ -21,9 +21,7 @@ import java.io.OutputStreamWriter;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.NetworkInterface;
-import java.net.SocketAddress;
 import java.net.SocketException;
-import java.nio.channels.NetworkChannel;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -739,9 +737,6 @@ public abstract class AbstractEndpoint<S,U> {
     public void setAddress(InetAddress address) { this.address = address; }
 
 
-    protected abstract NetworkChannel getServerSocket();
-
-
     /**
      * Obtain the network address the server socket is bound to. This primarily
      * exists to enable the correct address to be used when unlocking the server
@@ -754,17 +749,7 @@ public abstract class AbstractEndpoint<S,U> {
      * @throws IOException If there is a problem determining the currently bound
      *                     socket
      */
-    protected final InetSocketAddress getLocalAddress() throws IOException {
-        NetworkChannel serverSock = getServerSocket();
-        if (serverSock == null) {
-            return null;
-        }
-        SocketAddress sa = serverSock.getLocalAddress();
-        if (sa instanceof InetSocketAddress) {
-            return (InetSocketAddress) sa;
-        }
-        return null;
-    }
+    protected abstract InetSocketAddress getLocalAddress() throws IOException;
 
 
     /**
diff --git a/java/org/apache/tomcat/util/net/AbstractNetworkChannelEndpoint.java b/java/org/apache/tomcat/util/net/AbstractNetworkChannelEndpoint.java
new file mode 100644
index 0000000000..b52291e778
--- /dev/null
+++ b/java/org/apache/tomcat/util/net/AbstractNetworkChannelEndpoint.java
@@ -0,0 +1,43 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.tomcat.util.net;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.nio.channels.Channel;
+import java.nio.channels.NetworkChannel;
+
+public abstract class AbstractNetworkChannelEndpoint<S extends Channel, U extends NetworkChannel>
+        extends AbstractEndpoint<S, U> {
+
+    protected abstract NetworkChannel getServerSocket();
+
+
+    @Override
+    protected final InetSocketAddress getLocalAddress() throws IOException {
+        NetworkChannel serverSock = getServerSocket();
+        if (serverSock == null) {
+            return null;
+        }
+        SocketAddress sa = serverSock.getLocalAddress();
+        if (sa instanceof InetSocketAddress) {
+            return (InetSocketAddress) sa;
+        }
+        return null;
+    }
+}
\ No newline at end of file
diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
index 75444cfbc2..9ad21cfbde 100644
--- a/java/org/apache/tomcat/util/net/Nio2Endpoint.java
+++ b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
@@ -52,7 +52,7 @@ import org.apache.tomcat.util.net.jsse.JSSESupport;
 /**
  * NIO2 endpoint.
  */
-public class Nio2Endpoint extends AbstractEndpoint<Nio2Channel,AsynchronousSocketChannel> {
+public class Nio2Endpoint extends AbstractNetworkChannelEndpoint<Nio2Channel,AsynchronousSocketChannel> {
 
 
     // -------------------------------------------------------------- Constants
diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java
index d15aef314e..bdc534263e 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -76,7 +76,7 @@ import org.apache.tomcat.util.net.jsse.JSSESupport;
  * @author Mladen Turk
  * @author Remy Maucherat
  */
-public class NioEndpoint extends AbstractEndpoint<NioChannel,SocketChannel> {
+public class NioEndpoint extends AbstractNetworkChannelEndpoint<NioChannel,SocketChannel> {
 
 
     // -------------------------------------------------------------- Constants


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