You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jb...@apache.org on 2020/02/03 15:44:38 UTC

[activemq-artemis] branch master updated: ARTEMIS-2610 Improve ActiveMQServer.getConnectionCount()

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

jbertram pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new cfa11bb  ARTEMIS-2610 Improve ActiveMQServer.getConnectionCount()
     new c2f7e9e  This closes #2956
cfa11bb is described below

commit cfa11bbadc577acc386a274c4c888a1d3c5a3c02
Author: sebthom <se...@users.noreply.github.com>
AuthorDate: Wed Jan 29 12:24:26 2020 +0100

    ARTEMIS-2610 Improve ActiveMQServer.getConnectionCount()
---
 .../artemis/core/remoting/server/RemotingService.java         | 11 +++++++++++
 .../core/remoting/server/impl/RemotingServiceImpl.java        |  8 +++++++-
 .../activemq/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 c5318e7..8421e15 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<RemotingConnection> getConnections();
 
+   /**
+    * @return the number of clients connected to this server.
+    */
+   default int getConnectionCount() {
+      final Set<RemotingConnection> 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 2faa8b2..96c0851 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<String, Acceptor> acceptors = new HashMap<>();
 
-   private final Map<Object, ConnectionEntry> connections = new ConcurrentHashMap<>();
+   private final ConcurrentMap<Object, ConnectionEntry> connections = new ConcurrentHashMap<>();
 
    private final ReusableLatch connectionCountLatch = new ReusableLatch(0);
 
@@ -501,6 +502,11 @@ public class RemotingServiceImpl implements RemotingService, ServerConnectionLif
    }
 
    @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 06ee52b..4cea428 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