Implement allocation-friendly method to get user count in SimpUserRegistry
SPR-14930
(cherry picked from commit a929e9c)
This commit is contained in:
committed by
Juergen Hoeller
parent
ac30bcb0eb
commit
8de100b116
@@ -135,6 +135,16 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUserCount() {
|
||||
int userCount = 0;
|
||||
for (UserRegistrySnapshot registry : this.remoteRegistries.values()) {
|
||||
userCount += registry.getUserMap().size();
|
||||
}
|
||||
userCount += this.localRegistry.getUserCount();
|
||||
return userCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SimpSubscription> findSubscriptions(SimpSubscriptionMatcher matcher) {
|
||||
Set<SimpSubscription> result = new HashSet<SimpSubscription>();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,21 +29,28 @@ public interface SimpUserRegistry {
|
||||
/**
|
||||
* Get the user for the given name.
|
||||
* @param userName the name of the user to look up
|
||||
* @return the user or {@code null} if not connected
|
||||
* @return the user, or {@code null} if not connected
|
||||
*/
|
||||
SimpUser getUser(String userName);
|
||||
|
||||
/**
|
||||
* Return a snapshot of all connected users. The returned set is a copy and
|
||||
* will never be modified.
|
||||
* @return the connected users or an empty set.
|
||||
* Return a snapshot of all connected users.
|
||||
* <p>The returned set is a copy and will not reflect further changes.
|
||||
* @return the connected users, or an empty set if none
|
||||
*/
|
||||
Set<SimpUser> getUsers();
|
||||
|
||||
/**
|
||||
* Return the count of all connected users.
|
||||
* @return the number of connected users
|
||||
* @since 4.3.5
|
||||
*/
|
||||
int getUserCount();
|
||||
|
||||
/**
|
||||
* Find subscriptions with the given matcher.
|
||||
* @param matcher the matcher to use
|
||||
* @return a set of matching subscriptions or an empty set.
|
||||
* @return a set of matching subscriptions, or an empty set if none
|
||||
*/
|
||||
Set<SimpSubscription> findSubscriptions(SimpSubscriptionMatcher matcher);
|
||||
|
||||
|
||||
@@ -59,6 +59,11 @@ public class UserSessionRegistryAdapter implements SimpUserRegistry {
|
||||
throw new UnsupportedOperationException("UserSessionRegistry does not expose a listing of users");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUserCount() {
|
||||
throw new UnsupportedOperationException("UserSessionRegistry does not expose a user count");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SimpSubscription> findSubscriptions(SimpSubscriptionMatcher matcher) {
|
||||
throw new UnsupportedOperationException("UserSessionRegistry does not support operations across users");
|
||||
|
||||
Reference in New Issue
Block a user