From cfa11bbadc577acc386a274c4c888a1d3c5a3c02 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 29 Jan 2020 12:24:26 +0100 Subject: [PATCH] ARTEMIS-2610 Improve ActiveMQServer.getConnectionCount() --- .../artemis/core/remoting/server/RemotingService.java | 11 +++++++++++ .../remoting/server/impl/RemotingServiceImpl.java | 8 +++++++- .../artemis/core/server/impl/ActiveMQServerImpl.java | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/RemotingService.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/RemotingService.java index c5318e7bad..8421e156b3 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/RemotingService.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/RemotingService.java @@ -43,6 +43,17 @@ public interface RemotingService { Set getConnections(); + /** + * @return the number of clients connected to this server. + */ + default int getConnectionCount() { + final Set connections = getConnections(); + return connections == null ? 0 : getConnections().size(); + } + + /** + * @return the number of clients which have connected to this server since it was started. + */ long getTotalConnectionCount(); ReusableLatch getConnectionCountLatch(); 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 2faa8b27b7..96c0851232 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 @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.ServiceLoader; import java.util.Set; +import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; @@ -93,7 +94,7 @@ public class RemotingServiceImpl implements RemotingService, ServerConnectionLif private final Map acceptors = new HashMap<>(); - private final Map connections = new ConcurrentHashMap<>(); + private final ConcurrentMap connections = new ConcurrentHashMap<>(); private final ReusableLatch connectionCountLatch = new ReusableLatch(0); @@ -500,6 +501,11 @@ public class RemotingServiceImpl implements RemotingService, ServerConnectionLif return conns; } + @Override + public int getConnectionCount() { + return connections.size(); + } + @Override public long getTotalConnectionCount() { return totalConnectionCount.get(); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index 06ee52b136..4cea4285a3 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -1677,7 +1677,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { @Override public int getConnectionCount() { - return remotingService.getConnections().size(); + return remotingService.getConnectionCount(); } @Override