This is an automated email from the ASF dual-hosted git repository. jbertram pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/main by this push: new 691771c766 ARTEMIS-4174 fix style & rat 691771c766 is described below commit 691771c7661efea52c8be3c4f535db4f939e3077 Author: Justin Bertram <jbert...@apache.org> AuthorDate: Fri Sep 1 11:23:48 2023 -0500 ARTEMIS-4174 fix style & rat --- .../core/server/management/RmiRegistryFactory.java | 21 +++--- .../server/management/JMXRMIRegistryPortTest.java | 87 +++++++++++++--------- 2 files changed, 60 insertions(+), 48 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/RmiRegistryFactory.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/RmiRegistryFactory.java index dd0d87ded5..ed505a7d22 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/RmiRegistryFactory.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/RmiRegistryFactory.java @@ -36,6 +36,7 @@ public class RmiRegistryFactory { private Registry registry; private String host; private HostLimitedServerSocketFactory socketFactory; + /** * @return the port */ @@ -62,7 +63,7 @@ public class RmiRegistryFactory { * Create a server socket for testing purposes. */ ServerSocket createTestSocket() throws IOException { - return socketFactory.createServerSocket(1100); + return socketFactory.createServerSocket(1100); } public Object getObject() throws Exception { @@ -72,13 +73,13 @@ public class RmiRegistryFactory { class HostLimitedServerSocketFactory implements RMIServerSocketFactory { @Override public ServerSocket createServerSocket(int port) throws IOException { - InetAddress hostAddress; - if (host != null) { - hostAddress = InetAddress.getByName(host); - } else { - hostAddress = null; // accept connections on all local addresses - } - return ServerSocketFactory.getDefault().createServerSocket(port, 0, hostAddress); + InetAddress hostAddress; + if (host != null) { + hostAddress = InetAddress.getByName(host); + } else { + hostAddress = null; // accept connections on all local addresses + } + return ServerSocketFactory.getDefault().createServerSocket(port, 0, hostAddress); } } @@ -91,9 +92,7 @@ public class RmiRegistryFactory { public void init() throws RemoteException, UnknownHostException { socketFactory = new HostLimitedServerSocketFactory(); - registry = LocateRegistry.createRegistry(port, - new PassThroughToDefaultSocketFactory(), - socketFactory); + registry = LocateRegistry.createRegistry(port, new PassThroughToDefaultSocketFactory(), socketFactory); } public void destroy() throws RemoteException { diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/management/JMXRMIRegistryPortTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/management/JMXRMIRegistryPortTest.java index 9e3ac560d4..b6713c8797 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/management/JMXRMIRegistryPortTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/management/JMXRMIRegistryPortTest.java @@ -1,3 +1,19 @@ +/* + * 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.activemq.artemis.core.server.management; import org.apache.activemq.artemis.core.config.JMXConnectorConfiguration; @@ -10,43 +26,40 @@ import java.net.ServerSocket; public class JMXRMIRegistryPortTest { - @Test - public void explicitLocalhostRegistry() throws IOException { - RmiRegistryFactory registryFactory = new RmiRegistryFactory(); - registryFactory.setHost("localhost"); - registryFactory.setPort(1099); - registryFactory.init(); - try (ServerSocket testSocket = registryFactory.createTestSocket()) { - Assert.assertEquals(InetAddress.getByName("localhost"), - testSocket.getInetAddress()); - } - registryFactory.destroy(); - } + @Test + public void explicitLocalhostRegistry() throws IOException { + RmiRegistryFactory registryFactory = new RmiRegistryFactory(); + registryFactory.setHost("localhost"); + registryFactory.setPort(1099); + registryFactory.init(); + try (ServerSocket testSocket = registryFactory.createTestSocket()) { + Assert.assertEquals(InetAddress.getByName("localhost"), testSocket.getInetAddress()); + } + registryFactory.destroy(); + } - @Test - public void unlimitedHostRegistry() throws IOException { - RmiRegistryFactory registryFactory = new RmiRegistryFactory(); - registryFactory.setHost(null); - registryFactory.setPort(1099); - registryFactory.init(); - try (ServerSocket testSocket = registryFactory.createTestSocket()) { - Assert.assertEquals(InetAddress.getByAddress(new byte[] { 0, 0, 0, 0 }), - testSocket.getInetAddress()); - } - registryFactory.destroy(); - } + @Test + public void unlimitedHostRegistry() throws IOException { + RmiRegistryFactory registryFactory = new RmiRegistryFactory(); + registryFactory.setHost(null); + registryFactory.setPort(1099); + registryFactory.init(); + try (ServerSocket testSocket = registryFactory.createTestSocket()) { + Assert.assertEquals(InetAddress.getByAddress(new byte[]{0, 0, 0, 0}), testSocket.getInetAddress()); + } + registryFactory.destroy(); + } - @Test - public void defaultRegistry() throws IOException { - RmiRegistryFactory registryFactory = new RmiRegistryFactory(); - JMXConnectorConfiguration configuration = new JMXConnectorConfiguration(); - registryFactory.setHost(configuration.getConnectorHost()); - registryFactory.setPort(configuration.getConnectorPort()); - registryFactory.init(); - try (ServerSocket testSocket = registryFactory.createTestSocket()) { - Assert.assertEquals(InetAddress.getByName("localhost"), - testSocket.getInetAddress()); - } - registryFactory.destroy(); - } + @Test + public void defaultRegistry() throws IOException { + RmiRegistryFactory registryFactory = new RmiRegistryFactory(); + JMXConnectorConfiguration configuration = new JMXConnectorConfiguration(); + registryFactory.setHost(configuration.getConnectorHost()); + registryFactory.setPort(configuration.getConnectorPort()); + registryFactory.init(); + try (ServerSocket testSocket = registryFactory.createTestSocket()) { + Assert.assertEquals(InetAddress.getByName("localhost"), testSocket.getInetAddress()); + } + registryFactory.destroy(); + } }