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 2023/02/16 16:42:04 UTC
[tomcat] branch main updated: Minimum Java version now 17 - remove unnecessary code
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
The following commit(s) were added to refs/heads/main by this push:
new 2f94c7bc7f Minimum Java version now 17 - remove unnecessary code
2f94c7bc7f is described below
commit 2f94c7bc7fa331c9faf5dc54c052a9548be84c88
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Feb 16 16:41:57 2023 +0000
Minimum Java version now 17 - remove unnecessary code
---
.../tribes/membership/McastServiceImpl.java | 4 +-
.../apache/catalina/tribes/util/Jre14Compat.java | 60 ----------------------
.../org/apache/catalina/tribes/util/JreCompat.java | 55 --------------------
.../apache/catalina/tribes/TesterMulticast.java | 7 ++-
4 files changed, 5 insertions(+), 121 deletions(-)
diff --git a/java/org/apache/catalina/tribes/membership/McastServiceImpl.java b/java/org/apache/catalina/tribes/membership/McastServiceImpl.java
index c0d79c049e..1fac0a4207 100644
--- a/java/org/apache/catalina/tribes/membership/McastServiceImpl.java
+++ b/java/org/apache/catalina/tribes/membership/McastServiceImpl.java
@@ -25,6 +25,7 @@ import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
import java.net.SocketTimeoutException;
+import java.net.StandardSocketOptions;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -34,7 +35,6 @@ import org.apache.catalina.tribes.MembershipListener;
import org.apache.catalina.tribes.MessageListener;
import org.apache.catalina.tribes.io.ChannelData;
import org.apache.catalina.tribes.io.XByteBuffer;
-import org.apache.catalina.tribes.util.JreCompat;
import org.apache.catalina.tribes.util.StringManager;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
@@ -220,7 +220,7 @@ public class McastServiceImpl extends MembershipProviderBase {
socket = new MulticastSocket(port);
}
// Hint if we want disable loop back(local machine) messages
- JreCompat.getInstance().setSocketoptionIpMulticastLoop(socket, !localLoopbackDisabled);
+ socket.setOption(StandardSocketOptions.IP_MULTICAST_LOOP, Boolean.valueOf(!localLoopbackDisabled));
if (mcastBindAddress != null) {
if(log.isInfoEnabled()) {
log.info(sm.getString("mcastServiceImpl.setInterface", mcastBindAddress));
diff --git a/java/org/apache/catalina/tribes/util/Jre14Compat.java b/java/org/apache/catalina/tribes/util/Jre14Compat.java
deleted file mode 100644
index ad155e6b8e..0000000000
--- a/java/org/apache/catalina/tribes/util/Jre14Compat.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.catalina.tribes.util;
-
-import java.io.IOException;
-import java.net.MulticastSocket;
-import java.net.StandardSocketOptions;
-
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-
-public class Jre14Compat extends JreCompat {
-
- private static final Log log = LogFactory.getLog(Jre14Compat.class);
- private static final StringManager sm = StringManager.getManager(Jre14Compat.class);
-
- private static final boolean supported;
-
- static {
- // Don't need any Java 19 specific classes (yet) so just test for one of
- // the new ones for now.
- Class<?> c1 = null;
- try {
- c1 = Class.forName("java.io.Serial");
- } catch (ClassNotFoundException cnfe) {
- // Must be pre-Java 16
- log.debug(sm.getString("jre14Compat.javaPre14"), cnfe);
- }
-
- supported = (c1 != null);
- }
-
- static boolean isSupported() {
- return supported;
- }
-
-
- @Override
- public void setSocketoptionIpMulticastLoop(MulticastSocket socket, boolean enabled) throws IOException {
- /*
- * Java < 14, a value of true means loopback is disabled. Java 14+ a value of true means loopback is enabled.
- */
- socket.setOption(StandardSocketOptions.IP_MULTICAST_LOOP, Boolean.valueOf(enabled));
- }
-
-}
diff --git a/java/org/apache/catalina/tribes/util/JreCompat.java b/java/org/apache/catalina/tribes/util/JreCompat.java
deleted file mode 100644
index 563675da39..0000000000
--- a/java/org/apache/catalina/tribes/util/JreCompat.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.catalina.tribes.util;
-
-import java.io.IOException;
-import java.net.MulticastSocket;
-import java.net.StandardSocketOptions;
-
-/**
- * This is the base implementation class for JRE compatibility and provides an implementation based on Java 11.
- * Sub-classes may extend this class and provide alternative implementations for later JRE versions
- */
-public class JreCompat {
-
- private static final JreCompat instance;
-
- static {
- // This is Tomcat 11.0.x with a minimum Java version of Java 11.
- // Look for the highest supported JVM first
- if (Jre14Compat.isSupported()) {
- instance = new Jre14Compat();
- } else {
- instance = new JreCompat();
- }
- }
-
-
- public static JreCompat getInstance() {
- return instance;
- }
-
-
- // Java 11 implementations of Java 14 methods
-
- public void setSocketoptionIpMulticastLoop(MulticastSocket socket, boolean enabled) throws IOException {
- /*
- * Java < 14, a value of true means loopback is disabled. Java 14+ a value of true means loopback is enabled.
- */
- socket.setOption(StandardSocketOptions.IP_MULTICAST_LOOP, Boolean.valueOf(!enabled));
- }
-}
diff --git a/test/org/apache/catalina/tribes/TesterMulticast.java b/test/org/apache/catalina/tribes/TesterMulticast.java
index c0f1c95874..c39dbb8941 100644
--- a/test/org/apache/catalina/tribes/TesterMulticast.java
+++ b/test/org/apache/catalina/tribes/TesterMulticast.java
@@ -20,10 +20,9 @@ import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
+import java.net.StandardSocketOptions;
import java.net.UnknownHostException;
-import org.apache.catalina.tribes.util.JreCompat;
-
/**
* A simple multicast test that replicates the core elements of Tomcat's
* multicast membership. If this works then multicast membership should work.
@@ -83,7 +82,7 @@ public class TesterMulticast {
@Override
public void run() {
try (MulticastSocket s = new MulticastSocket(PORT)) {
- JreCompat.getInstance().setSocketoptionIpMulticastLoop(s, true);
+ s.setOption(StandardSocketOptions.IP_MULTICAST_LOOP, Boolean.valueOf(true));
s.joinGroup(new InetSocketAddress(INET_ADDRESS, 0), null);
DatagramPacket p = new DatagramPacket(new byte[4], 4);
p.setAddress(INET_ADDRESS);
@@ -110,7 +109,7 @@ public class TesterMulticast {
@Override
public void run() {
try (MulticastSocket s = new MulticastSocket(PORT)) {
- JreCompat.getInstance().setSocketoptionIpMulticastLoop(s, true);
+ s.setOption(StandardSocketOptions.IP_MULTICAST_LOOP, Boolean.valueOf(true));
s.joinGroup(new InetSocketAddress(INET_ADDRESS, 0), null);
DatagramPacket p = new DatagramPacket(new byte[4], 4);
p.setAddress(INET_ADDRESS);
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org