Merge pull request #5109 from eclipse/jetty-9.4.x-5108-SessionTrackerScalability
Issue #5108 - improve scalability of WebSocket SessionTrackers
This commit is contained in:
commit
8af767f3a6
|
@ -19,19 +19,21 @@
|
|||
package org.eclipse.jetty.websocket.jsr356;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.websocket.Session;
|
||||
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
|
||||
public class JsrSessionTracker extends AbstractLifeCycle implements JsrSessionListener
|
||||
{
|
||||
private CopyOnWriteArraySet<JsrSession> sessions = new CopyOnWriteArraySet<>();
|
||||
private final Set<JsrSession> sessions = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
|
||||
public Set<javax.websocket.Session> getSessions()
|
||||
public Set<Session> getSessions()
|
||||
{
|
||||
return Collections.unmodifiableSet(sessions);
|
||||
return Collections.unmodifiableSet(new HashSet<>(sessions));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,7 +51,7 @@ public class JsrSessionTracker extends AbstractLifeCycle implements JsrSessionLi
|
|||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
for (JsrSession session : sessions)
|
||||
for (Session session : sessions)
|
||||
{
|
||||
LifeCycle.stop(session);
|
||||
}
|
||||
|
|
|
@ -20,8 +20,9 @@ package org.eclipse.jetty.websocket.common;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
|
@ -29,11 +30,11 @@ import org.eclipse.jetty.util.component.LifeCycle;
|
|||
|
||||
public class SessionTracker extends AbstractLifeCycle implements WebSocketSessionListener, Dumpable
|
||||
{
|
||||
private CopyOnWriteArraySet<WebSocketSession> sessions = new CopyOnWriteArraySet<>();
|
||||
private final Set<WebSocketSession> sessions = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
|
||||
public Set<WebSocketSession> getSessions()
|
||||
{
|
||||
return Collections.unmodifiableSet(sessions);
|
||||
return Collections.unmodifiableSet(new HashSet<>(sessions));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue