Skip to content

Commit

Permalink
Issue #5122 - make number of active WS Sessions a managed attribute o…
Browse files Browse the repository at this point in the history
…n SessionTracker

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Aug 6, 2020
1 parent be429f0 commit 8a3ff77
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Expand Up @@ -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<>());

Expand Down Expand Up @@ -57,4 +60,16 @@ protected void doStop() throws Exception
}
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);
}
}
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -61,6 +62,12 @@ protected void doStop() throws Exception
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
{
Expand Down

0 comments on commit 8a3ff77

Please sign in to comment.