From 9a2bebe443528d0e6d00ea2a9cd6509fe406b91a Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Wed, 4 Nov 2015 22:48:55 -0500 Subject: [PATCH] ARTEMIS-297 Including acceptor name on logs --- .../core/remoting/impl/invm/InVMAcceptor.java | 12 +++++++++++- .../core/remoting/impl/invm/InVMAcceptorFactory.java | 2 +- .../core/remoting/impl/netty/NettyAcceptor.java | 4 ++++ .../remoting/server/impl/RemotingServiceImpl.java | 6 +++--- .../artemis/core/server/ActiveMQServerLogger.java | 4 ++-- .../activemq/artemis/spi/core/remoting/Acceptor.java | 4 ++++ .../tests/unit/core/remoting/AcceptorsTest.java | 3 ++- .../server/impl/fake/FakeAcceptorFactory.java | 4 ++++ 8 files changed, 31 insertions(+), 8 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMAcceptor.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMAcceptor.java index a6033653e8..f6a00becc4 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMAcceptor.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMAcceptor.java @@ -66,11 +66,17 @@ public final class InVMAcceptor implements Acceptor { private final long connectionsAllowed; - public InVMAcceptor(final ClusterConnection clusterConnection, + private final String name; + + public InVMAcceptor(final String name, + final ClusterConnection clusterConnection, final Map configuration, final BufferHandler handler, final ConnectionLifeCycleListener listener, final Executor threadPool) { + + this.name = name; + this.clusterConnection = clusterConnection; this.configuration = configuration; @@ -86,6 +92,10 @@ public final class InVMAcceptor implements Acceptor { connectionsAllowed = ConfigurationHelper.getLongProperty(TransportConstants.CONNECTIONS_ALLOWED, TransportConstants.DEFAULT_CONNECTIONS_ALLOWED, configuration); } + public String getName() { + return name; + } + public Map getConfiguration() { return configuration; } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMAcceptorFactory.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMAcceptorFactory.java index e227bcea9d..49de7e9618 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMAcceptorFactory.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMAcceptorFactory.java @@ -37,6 +37,6 @@ public class InVMAcceptorFactory implements AcceptorFactory { final Executor threadPool, final ScheduledExecutorService scheduledThreadPool, final Map protocolHandler) { - return new InVMAcceptor(clusterConnection, configuration, handler, listener, threadPool); + return new InVMAcceptor(name, clusterConnection, configuration, handler, listener, threadPool); } } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java index 62e93bd331..9905ca1dbe 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java @@ -411,6 +411,10 @@ public class NettyAcceptor implements Acceptor { } } + public String getName() { + return name; + } + /** * Transfers the Netty channel that has been created outside of this NettyAcceptor * to control it and configure it according to this NettyAcceptor setting. diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/impl/RemotingServiceImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/impl/RemotingServiceImpl.java index d3bfdb1ad1..b2bca01c1d 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/impl/RemotingServiceImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/impl/RemotingServiceImpl.java @@ -304,7 +304,7 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle acceptor.pause(); } catch (Exception e) { - ActiveMQServerLogger.LOGGER.errorStoppingAcceptor(); + ActiveMQServerLogger.LOGGER.errorStoppingAcceptor(acceptor.getName()); } } } @@ -351,7 +351,7 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle acceptor.pause(); } catch (Throwable t) { - ActiveMQServerLogger.LOGGER.errorStoppingAcceptor(); + ActiveMQServerLogger.LOGGER.errorStoppingAcceptor(acceptor.getName()); } } @@ -379,7 +379,7 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle acceptor.stop(); } catch (Throwable t) { - ActiveMQServerLogger.LOGGER.errorStoppingAcceptor(); + ActiveMQServerLogger.LOGGER.errorStoppingAcceptor(acceptor.getName()); } } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java index be167ecdd7..ab521919e3 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java @@ -1292,8 +1292,8 @@ public interface ActiveMQServerLogger extends BasicLogger { void errorWritingToInvmConnector(@Cause Exception e, Runnable runnable); @LogMessage(level = Logger.Level.ERROR) - @Message(id = 224028, value = "Failed to stop acceptor", format = Message.Format.MESSAGE_FORMAT) - void errorStoppingAcceptor(); + @Message(id = 224028, value = "Failed to stop accepto {0}r", format = Message.Format.MESSAGE_FORMAT) + void errorStoppingAcceptor(String name); @LogMessage(level = Logger.Level.ERROR) @Message(id = 224029, value = "large message sync: largeMessage instance is incompatible with it, ignoring data", format = Message.Format.MESSAGE_FORMAT) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/remoting/Acceptor.java b/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/remoting/Acceptor.java index 517ea3c839..dbd261801b 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/remoting/Acceptor.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/remoting/Acceptor.java @@ -29,6 +29,10 @@ import org.apache.activemq.artemis.core.server.management.NotificationService; */ public interface Acceptor extends ActiveMQComponent { + /** The name of the acceptor used on the configuration. + * for logging and debug purposes. */ + String getName(); + /** * Pause the acceptor and stop it from receiving client requests. */ diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/AcceptorsTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/AcceptorsTest.java index 88f02b2660..f6aae80b7b 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/AcceptorsTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/AcceptorsTest.java @@ -24,6 +24,7 @@ import java.util.Set; import org.apache.activemq.artemis.api.core.TransportConfiguration; import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.server.ActiveMQServer; +import org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeAcceptorFactory; import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.junit.Test; @@ -32,7 +33,7 @@ public class AcceptorsTest extends ActiveMQTestBase { @Test public void testMultipleAcceptorsWithSameHostPortDifferentName() throws Exception { - final String acceptorFactoryClass = "org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeAcceptorFactory"; + final String acceptorFactoryClass = FakeAcceptorFactory.class.getName(); Map params = new HashMap<>(); params.put("host", "localhost"); diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/server/impl/fake/FakeAcceptorFactory.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/server/impl/fake/FakeAcceptorFactory.java index 3ced505e3a..f351dfb725 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/server/impl/fake/FakeAcceptorFactory.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/server/impl/fake/FakeAcceptorFactory.java @@ -47,6 +47,10 @@ public class FakeAcceptorFactory implements AcceptorFactory { private final class FakeAcceptor implements Acceptor { + public String getName() { + return "fake"; + } + @Override public void pause() {