mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
fix user count
This commit is contained in:
@@ -19,12 +19,13 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class WebSocketSessions {
|
public class WebSocketSessions {
|
||||||
|
|
||||||
// a user may have multiple sessions (two tabs, on mobile, ...)
|
// a user may have multiple sessions (two tabs, two devices, ...)
|
||||||
private final Map<Long, Set<Session>> sessions = new ConcurrentHashMap<>();
|
private final Map<Long, Set<Session>> sessions = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public WebSocketSessions(MetricRegistry metrics) {
|
public WebSocketSessions(MetricRegistry metrics) {
|
||||||
metrics.register(MetricRegistry.name(getClass(), "users"), (Gauge<Integer>) sessions::size);
|
metrics.register(MetricRegistry.name(getClass(), "users"),
|
||||||
|
(Gauge<Long>) () -> sessions.values().stream().filter(v -> !v.isEmpty()).count());
|
||||||
metrics.register(MetricRegistry.name(getClass(), "sessions"),
|
metrics.register(MetricRegistry.name(getClass(), "sessions"),
|
||||||
(Gauge<Long>) () -> sessions.values().stream().mapToLong(Set::size).sum());
|
(Gauge<Long>) () -> sessions.values().stream().mapToLong(Set::size).sum());
|
||||||
}
|
}
|
||||||
@@ -34,7 +35,7 @@ public class WebSocketSessions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Session session) {
|
public void remove(Session session) {
|
||||||
sessions.values().forEach(v -> v.removeIf(e -> e.equals(session)));
|
sessions.values().forEach(v -> v.remove(session));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(User user, String text) {
|
public void sendMessage(User user, String text) {
|
||||||
|
|||||||
Reference in New Issue
Block a user