Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
3f6119eb13
commit
d47264960e
|
@ -48,7 +48,8 @@ public class JettyWebSocketFrameHandler implements FrameHandler
|
||||||
{
|
{
|
||||||
DEMANDING,
|
DEMANDING,
|
||||||
SUSPENDING,
|
SUSPENDING,
|
||||||
SUSPENDED
|
SUSPENDED,
|
||||||
|
CLOSED
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Logger log;
|
private final Logger log;
|
||||||
|
@ -191,7 +192,6 @@ public class JettyWebSocketFrameHandler implements FrameHandler
|
||||||
state = SuspendState.SUSPENDED;
|
state = SuspendState.SUSPENDED;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case SUSPENDED:
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
@ -280,6 +280,12 @@ public class JettyWebSocketFrameHandler implements FrameHandler
|
||||||
@Override
|
@Override
|
||||||
public void onClosed(CloseStatus closeStatus, Callback callback)
|
public void onClosed(CloseStatus closeStatus, Callback callback)
|
||||||
{
|
{
|
||||||
|
synchronized (this)
|
||||||
|
{
|
||||||
|
// We are now closed and cannot suspend or resume
|
||||||
|
state = SuspendState.CLOSED;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (closeHandle != null)
|
if (closeHandle != null)
|
||||||
|
@ -405,18 +411,15 @@ public class JettyWebSocketFrameHandler implements FrameHandler
|
||||||
state = SuspendState.SUSPENDING;
|
state = SuspendState.SUSPENDING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SUSPENDED:
|
|
||||||
case SUSPENDING:
|
|
||||||
throw new IllegalStateException("Already Suspended");
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException(state.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resume()
|
public void resume()
|
||||||
{
|
{
|
||||||
|
boolean needDemand = false;
|
||||||
Runnable delayedFrame = null;
|
Runnable delayedFrame = null;
|
||||||
synchronized (this)
|
synchronized (this)
|
||||||
{
|
{
|
||||||
|
@ -426,6 +429,7 @@ public class JettyWebSocketFrameHandler implements FrameHandler
|
||||||
throw new IllegalStateException("Already Resumed");
|
throw new IllegalStateException("Already Resumed");
|
||||||
|
|
||||||
case SUSPENDED:
|
case SUSPENDED:
|
||||||
|
needDemand = true;
|
||||||
delayedFrame = delayedOnFrame;
|
delayedFrame = delayedOnFrame;
|
||||||
delayedOnFrame = null;
|
delayedOnFrame = null;
|
||||||
state = SuspendState.DEMANDING;
|
state = SuspendState.DEMANDING;
|
||||||
|
@ -438,15 +442,18 @@ public class JettyWebSocketFrameHandler implements FrameHandler
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException(state.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (needDemand)
|
||||||
|
{
|
||||||
if (delayedFrame != null)
|
if (delayedFrame != null)
|
||||||
delayedFrame.run();
|
delayedFrame.run();
|
||||||
else
|
else
|
||||||
session.getCoreSession().demand(1);
|
session.getCoreSession().demand(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void demand()
|
private void demand()
|
||||||
{
|
{
|
||||||
|
@ -459,15 +466,12 @@ public class JettyWebSocketFrameHandler implements FrameHandler
|
||||||
demand = true;
|
demand = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SUSPENDED:
|
|
||||||
throw new IllegalStateException("Suspended");
|
|
||||||
|
|
||||||
case SUSPENDING:
|
case SUSPENDING:
|
||||||
state = SuspendState.SUSPENDED;
|
state = SuspendState.SUSPENDED;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException(state.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@ import org.eclipse.jetty.websocket.server.JettyWebSocketServletFactory;
|
||||||
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
|
import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
@ -170,7 +169,6 @@ public class SuspendResumeTest
|
||||||
assertNull(serverSocket.error);
|
assertNull(serverSocket.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuspendAfterClose() throws Exception
|
public void testSuspendAfterClose() throws Exception
|
||||||
{
|
{
|
||||||
|
|
|
@ -470,7 +470,7 @@ public class WebSocketCoreSession implements IncomingFrames, FrameHandler.CoreSe
|
||||||
if (!demanding)
|
if (!demanding)
|
||||||
throw new IllegalStateException("FrameHandler is not demanding: " + this);
|
throw new IllegalStateException("FrameHandler is not demanding: " + this);
|
||||||
if (!sessionState.isInputOpen())
|
if (!sessionState.isInputOpen())
|
||||||
throw new IllegalStateException("FrameHandler input not open: " + this); // TODO Perhaps this is a NOOP?
|
throw new IllegalStateException("FrameHandler input not open: " + this);
|
||||||
connection.demand(n);
|
connection.demand(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue