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:
parent
be429f0910
commit
8a3ff775d5
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue