Issue #3479 - Wire up batchMode annotation for jetty-websockets

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2019-03-21 14:27:18 +11:00 committed by Greg Wilkins
parent f7354bc90e
commit 9e3eb3df35
5 changed files with 24 additions and 19 deletions

View File

@ -27,6 +27,7 @@ import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.BatchMode;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
@ -55,6 +56,7 @@ public class JettyWebSocketFrameHandler implements FrameHandler
private final Logger log;
private final WebSocketContainer container;
private final Object endpointInstance;
private final BatchMode batchMode;
private MethodHandle openHandle;
private MethodHandle closeHandle;
private MethodHandle errorHandle;
@ -92,6 +94,7 @@ public class JettyWebSocketFrameHandler implements FrameHandler
MethodHandle frameHandle,
MethodHandle pingHandle, MethodHandle pongHandle,
CompletableFuture<Session> futureSession,
BatchMode batchMode,
Customizer customizer)
{
this.log = Log.getLogger(endpointInstance.getClass());
@ -113,7 +116,7 @@ public class JettyWebSocketFrameHandler implements FrameHandler
this.pongHandle = pongHandle;
this.futureSession = futureSession;
this.batchMode = batchMode;
this.customizer = customizer;
}
@ -128,8 +131,7 @@ public class JettyWebSocketFrameHandler implements FrameHandler
try
{
customizer.customize(coreSession);
session = new WebSocketSession(coreSession, this, upgradeRequest, upgradeResponse);
session = new WebSocketSession(coreSession, this, batchMode, upgradeRequest, upgradeResponse);
frameHandle = JettyWebSocketFrameHandlerFactory.bindTo(frameHandle, session);
openHandle = JettyWebSocketFrameHandlerFactory.bindTo(openHandle, session);

View File

@ -36,6 +36,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.websocket.api.BatchMode;
import org.eclipse.jetty.websocket.api.Frame;
import org.eclipse.jetty.websocket.api.InvalidWebSocketException;
import org.eclipse.jetty.websocket.api.Session;
@ -133,6 +134,7 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle
MethodHandle frameHandle = metadata.getFrameHandle();
MethodHandle pingHandle = metadata.getPingHandle();
MethodHandle pongHandle = metadata.getPongHandle();
BatchMode batchMode = metadata.getBatchMode(); // TODO: what if we're not annotating, who else sets this
openHandle = bindTo(openHandle, endpointInstance);
closeHandle = bindTo(closeHandle, endpointInstance);
@ -156,6 +158,7 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle
textSinkClass, binarySinkClass,
frameHandle, pingHandle, pongHandle,
future,
batchMode,
metadata);
return frameHandler;

View File

@ -18,13 +18,12 @@
package org.eclipse.jetty.websocket.common;
import java.lang.invoke.MethodHandle;
import org.eclipse.jetty.websocket.api.BatchMode;
import org.eclipse.jetty.websocket.api.InvalidWebSocketException;
import org.eclipse.jetty.websocket.core.FrameHandler;
import java.lang.invoke.MethodHandle;
import java.time.Duration;
public class JettyWebSocketFrameHandlerMetadata extends FrameHandler.ConfigurationCustomizer
{
private MethodHandle openHandle;
@ -42,7 +41,6 @@ public class JettyWebSocketFrameHandlerMetadata extends FrameHandler.Configurati
private MethodHandle pongHandle;
// Batch Configuration
// TODO remove?
private BatchMode batchMode = BatchMode.OFF;
public void setBatchMode(BatchMode batchMode)

View File

@ -18,6 +18,12 @@
package org.eclipse.jetty.websocket.common;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.Objects;
import java.util.concurrent.Future;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.FutureCallback;
@ -29,12 +35,6 @@ import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.OpCode;
import org.eclipse.jetty.websocket.core.ProtocolException;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.Objects;
import java.util.concurrent.Future;
import static java.nio.charset.StandardCharsets.UTF_8;
public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket.api.RemoteEndpoint
@ -44,9 +44,10 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket
private final SharedBlockingCallback blocker = new SharedBlockingCallback();
private BatchMode batchMode;
public JettyWebSocketRemoteEndpoint(FrameHandler.CoreSession coreSession)
public JettyWebSocketRemoteEndpoint(FrameHandler.CoreSession coreSession, BatchMode batchMode)
{
this.coreSession = Objects.requireNonNull(coreSession);
this.batchMode = batchMode;
}
/**

View File

@ -28,6 +28,7 @@ import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.BatchMode;
import org.eclipse.jetty.websocket.api.CloseStatus;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode;
@ -47,14 +48,14 @@ public class WebSocketSession extends AbstractLifeCycle implements Session, Susp
private final UpgradeResponse upgradeResponse;
public WebSocketSession(
FrameHandler.CoreSession coreSession,
JettyWebSocketFrameHandler frameHandler,
UpgradeRequest upgradeRequest,
UpgradeResponse upgradeResponse)
FrameHandler.CoreSession coreSession,
JettyWebSocketFrameHandler frameHandler, BatchMode batchMode,
UpgradeRequest upgradeRequest,
UpgradeResponse upgradeResponse)
{
this.coreSession = Objects.requireNonNull(coreSession);
this.frameHandler = Objects.requireNonNull(frameHandler);
this.remoteEndpoint = new JettyWebSocketRemoteEndpoint(coreSession);
this.remoteEndpoint = new JettyWebSocketRemoteEndpoint(coreSession, batchMode);
this.upgradeRequest = upgradeRequest;
this.upgradeResponse = upgradeResponse;
}