Issue #5122 - make number of active WS Sessions a managed attribute on SessionTracker

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2020-08-06 20:45:06 +10:00
parent be429f0910
commit 8a3ff775d5
2 changed files with 23 additions and 1 deletions

View File

@ -18,16 +18,19 @@
package org.eclipse.jetty.websocket.jsr356;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.websocket.Session;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.component.LifeCycle;
public class JsrSessionTracker extends AbstractLifeCycle implements JsrSessionListener
public class JsrSessionTracker extends AbstractLifeCycle implements JsrSessionListener, Dumpable
{
private final Set<JsrSession> sessions = Collections.newSetFromMap(new ConcurrentHashMap<>());
@ -57,4 +60,16 @@ public class JsrSessionTracker extends AbstractLifeCycle implements JsrSessionLi
}
super.doStop();
}
@ManagedAttribute("Total number of active WebSocket Sessions")
public int getNumSessions()
{
return sessions.size();
}
@Override
public void dump(Appendable out, String indent) throws IOException
{
Dumpable.dumpObjects(out, indent, this, sessions);
}
}

View File

@ -24,6 +24,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.component.LifeCycle;
@ -61,6 +62,12 @@ public class SessionTracker extends AbstractLifeCycle implements WebSocketSessio
super.doStop();
}
@ManagedAttribute("Total number of active WebSocket Sessions")
public int getNumSessions()
{
return sessions.size();
}
@Override
public void dump(Appendable out, String indent) throws IOException
{