ARTEMIS-2610 Improve ActiveMQServer.getConnectionCount()

This commit is contained in:
sebthom 2020-01-29 12:24:26 +01:00 committed by Justin Bertram
parent d1558f172b
commit cfa11bbadc
3 changed files with 19 additions and 2 deletions

View File

@ -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();

View File

@ -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);
@ -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();

View File

@ -1677,7 +1677,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
@Override
public int getConnectionCount() {
return remotingService.getConnections().size();
return remotingService.getConnectionCount();
}
@Override