Issue #4315 - Jetty and Javax WebSocketSessions are no longer LifeCycles
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
738de7bb02
commit
2410f9d6c4
|
@ -38,12 +38,9 @@ import javax.websocket.RemoteEndpoint.Basic;
|
||||||
import javax.websocket.Session;
|
import javax.websocket.Session;
|
||||||
import javax.websocket.WebSocketContainer;
|
import javax.websocket.WebSocketContainer;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.Callback;
|
|
||||||
import org.eclipse.jetty.util.SharedBlockingCallback;
|
import org.eclipse.jetty.util.SharedBlockingCallback;
|
||||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.websocket.core.CloseStatus;
|
|
||||||
import org.eclipse.jetty.websocket.core.ExtensionConfig;
|
import org.eclipse.jetty.websocket.core.ExtensionConfig;
|
||||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||||
import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders;
|
import org.eclipse.jetty.websocket.javax.common.decoders.AvailableDecoders;
|
||||||
|
@ -53,7 +50,7 @@ import org.eclipse.jetty.websocket.javax.common.util.ReflectUtils;
|
||||||
/**
|
/**
|
||||||
* Client Session for the JSR.
|
* Client Session for the JSR.
|
||||||
*/
|
*/
|
||||||
public class JavaxWebSocketSession extends AbstractLifeCycle implements javax.websocket.Session
|
public class JavaxWebSocketSession implements javax.websocket.Session
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(JavaxWebSocketSession.class);
|
private static final Logger LOG = Log.getLogger(JavaxWebSocketSession.class);
|
||||||
|
|
||||||
|
@ -547,25 +544,6 @@ public class JavaxWebSocketSession extends AbstractLifeCycle implements javax.we
|
||||||
return coreSession.isSecure();
|
return coreSession.isSecure();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doStop()
|
|
||||||
{
|
|
||||||
coreSession.close(CloseStatus.SHUTDOWN, "Container being shut down", new Callback()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void succeeded()
|
|
||||||
{
|
|
||||||
coreSession.abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void failed(Throwable x)
|
|
||||||
{
|
|
||||||
coreSession.abort();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void removeMessageHandler(MessageHandler handler)
|
public synchronized void removeMessageHandler(MessageHandler handler)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,10 +21,10 @@ package org.eclipse.jetty.websocket.javax.common;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
import javax.websocket.CloseReason;
|
||||||
import javax.websocket.Session;
|
import javax.websocket.Session;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||||
import org.eclipse.jetty.util.component.LifeCycle;
|
|
||||||
|
|
||||||
public class SessionTracker extends AbstractLifeCycle implements JavaxWebSocketSessionListener
|
public class SessionTracker extends AbstractLifeCycle implements JavaxWebSocketSessionListener
|
||||||
{
|
{
|
||||||
|
@ -50,10 +50,12 @@ public class SessionTracker extends AbstractLifeCycle implements JavaxWebSocketS
|
||||||
@Override
|
@Override
|
||||||
protected void doStop() throws Exception
|
protected void doStop() throws Exception
|
||||||
{
|
{
|
||||||
for (JavaxWebSocketSession session : sessions)
|
for (Session session : sessions)
|
||||||
{
|
{
|
||||||
LifeCycle.stop(session);
|
// GOING_AWAY is abnormal close status so it will hard close connection after sent.
|
||||||
|
session.close(new CloseReason(CloseReason.CloseCodes.GOING_AWAY, "Container being shut down"));
|
||||||
}
|
}
|
||||||
|
|
||||||
super.doStop();
|
super.doStop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,6 @@ public abstract class AbstractSessionTest
|
||||||
JavaxWebSocketFrameHandler frameHandler = container.newFrameHandler(websocketPojo, upgradeRequest);
|
JavaxWebSocketFrameHandler frameHandler = container.newFrameHandler(websocketPojo, upgradeRequest);
|
||||||
FrameHandler.CoreSession coreSession = new FrameHandler.CoreSession.Empty();
|
FrameHandler.CoreSession coreSession = new FrameHandler.CoreSession.Empty();
|
||||||
session = new JavaxWebSocketSession(container, coreSession, frameHandler, null);
|
session = new JavaxWebSocketSession(container, coreSession, frameHandler, null);
|
||||||
container.addManaged(session);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
|
|
|
@ -44,7 +44,6 @@ public abstract class AbstractClientSessionTest
|
||||||
JavaxWebSocketFrameHandler frameHandler = container.newFrameHandler(websocketPojo, upgradeRequest);
|
JavaxWebSocketFrameHandler frameHandler = container.newFrameHandler(websocketPojo, upgradeRequest);
|
||||||
FrameHandler.CoreSession coreSession = new FrameHandler.CoreSession.Empty();
|
FrameHandler.CoreSession coreSession = new FrameHandler.CoreSession.Empty();
|
||||||
session = new JavaxWebSocketSession(container, coreSession, frameHandler, null);
|
session = new JavaxWebSocketSession(container, coreSession, frameHandler, null);
|
||||||
container.addManaged(session);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
|
|
|
@ -82,13 +82,11 @@ public class SessionAddMessageHandlerTest
|
||||||
|
|
||||||
// Session
|
// Session
|
||||||
session = frameHandler.getSession();
|
session = frameHandler.getSession();
|
||||||
session.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void stopSession() throws Exception
|
public void stopSession() throws Exception
|
||||||
{
|
{
|
||||||
session.stop();
|
|
||||||
container.stop();
|
container.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||||
import org.eclipse.jetty.util.component.LifeCycle;
|
|
||||||
import org.eclipse.jetty.websocket.api.Session;
|
import org.eclipse.jetty.websocket.api.Session;
|
||||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||||
import org.eclipse.jetty.websocket.api.WebSocketSessionListener;
|
import org.eclipse.jetty.websocket.api.WebSocketSessionListener;
|
||||||
|
@ -40,7 +39,6 @@ public class SessionTracker extends AbstractLifeCycle implements WebSocketSessio
|
||||||
@Override
|
@Override
|
||||||
public void onWebSocketSessionOpened(Session session)
|
public void onWebSocketSessionOpened(Session session)
|
||||||
{
|
{
|
||||||
LifeCycle.start(session);
|
|
||||||
sessions.add(session);
|
sessions.add(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +46,6 @@ public class SessionTracker extends AbstractLifeCycle implements WebSocketSessio
|
||||||
public void onWebSocketSessionClosed(Session session)
|
public void onWebSocketSessionClosed(Session session)
|
||||||
{
|
{
|
||||||
sessions.remove(session);
|
sessions.remove(session);
|
||||||
LifeCycle.stop(session);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -23,7 +23,6 @@ import java.net.SocketAddress;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
|
||||||
import org.eclipse.jetty.util.component.Dumpable;
|
import org.eclipse.jetty.util.component.Dumpable;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
@ -35,7 +34,7 @@ import org.eclipse.jetty.websocket.api.UpgradeResponse;
|
||||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||||
|
|
||||||
public class WebSocketSession extends AbstractLifeCycle implements Session, SuspendToken, Dumpable
|
public class WebSocketSession implements Session, SuspendToken, Dumpable
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(WebSocketSession.class);
|
private static final Logger LOG = Log.getLogger(WebSocketSession.class);
|
||||||
private final FrameHandler.CoreSession coreSession;
|
private final FrameHandler.CoreSession coreSession;
|
||||||
|
|
|
@ -134,11 +134,6 @@ public class ConcurrentConnectTest
|
||||||
}
|
}
|
||||||
|
|
||||||
closeListener.closeLatch.await(5, TimeUnit.SECONDS);
|
closeListener.closeLatch.await(5, TimeUnit.SECONDS);
|
||||||
for (EventSocket l : listeners)
|
|
||||||
{
|
|
||||||
assertTrue(((WebSocketSession)l.session).isStopped());
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(client.getOpenSessions().isEmpty());
|
assertTrue(client.getOpenSessions().isEmpty());
|
||||||
assertTrue(client.getContainedBeans(WebSocketSession.class).isEmpty());
|
assertTrue(client.getContainedBeans(WebSocketSession.class).isEmpty());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue