mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-01 03:19:13 +00:00
428474 - Expose batch mode in the Jetty WebSocket API
This commit is contained in:
parent
11b5d320f8
commit
25cfffbe1e
@ -128,6 +128,15 @@ public interface RemoteEndpoint
|
||||
*/
|
||||
BatchMode getBatchMode();
|
||||
|
||||
/**
|
||||
* Set the batch mode with which messages are sent.
|
||||
*
|
||||
* @param mode
|
||||
* the batch mode to use
|
||||
* @see #flush()
|
||||
*/
|
||||
void setBatchMode(BatchMode mode);
|
||||
|
||||
/**
|
||||
* Flushes messages that may have been batched by the implementation.
|
||||
* @throws IOException if the flush fails
|
||||
|
@ -24,6 +24,8 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.BatchMode;
|
||||
|
||||
/**
|
||||
* Tags a POJO as being a WebSocket class.
|
||||
*/
|
||||
@ -40,4 +42,6 @@ public @interface WebSocket
|
||||
int maxIdleTime() default -2;
|
||||
|
||||
int maxTextMessageSize() default -2;
|
||||
|
||||
BatchMode batchMode() default BatchMode.AUTO;
|
||||
}
|
||||
|
@ -436,9 +436,7 @@ public class WebSocketRemoteEndpoint implements RemoteEndpoint
|
||||
return batchMode;
|
||||
}
|
||||
|
||||
// Only the JSR needs to have this method exposed.
|
||||
// In the Jetty implementation the batching is set
|
||||
// at the moment of opening the session.
|
||||
@Override
|
||||
public void setBatchMode(BatchMode batchMode)
|
||||
{
|
||||
this.batchMode = batchMode;
|
||||
|
@ -71,6 +71,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Inc
|
||||
private WebSocketPolicy policy;
|
||||
private UpgradeRequest upgradeRequest;
|
||||
private UpgradeResponse upgradeResponse;
|
||||
private BatchMode batchMode = BatchMode.AUTO;
|
||||
|
||||
public WebSocketSession(URI requestURI, EventDriver websocket, LogicalConnection connection, SessionListener... sessionListeners)
|
||||
{
|
||||
@ -400,14 +401,20 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Inc
|
||||
}
|
||||
|
||||
ClassLoader old = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
try
|
||||
{
|
||||
Thread.currentThread().setContextClassLoader(classLoader);
|
||||
|
||||
// Upgrade success
|
||||
connection.getIOState().onConnected();
|
||||
|
||||
// Connect remote
|
||||
remote = new WebSocketRemoteEndpoint(connection,outgoingHandler,getBatchMode());
|
||||
BatchMode endpointBatchMode = websocket.getBatchMode();
|
||||
if (endpointBatchMode == null)
|
||||
{
|
||||
endpointBatchMode = this.getBatchMode();
|
||||
}
|
||||
remote = new WebSocketRemoteEndpoint(connection,outgoingHandler,endpointBatchMode);
|
||||
|
||||
// Open WebSocket
|
||||
websocket.openSession(this);
|
||||
@ -496,11 +503,20 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Inc
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the default (initial) value for the batching mode.
|
||||
* @return the batching mode default for RemoteEndpoint behavior
|
||||
*/
|
||||
public BatchMode getBatchMode()
|
||||
{
|
||||
return BatchMode.AUTO;
|
||||
return batchMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the batch mode default for the RemoteEndpoint behavior.
|
||||
* @param mode the batching mode.
|
||||
*/
|
||||
public void setBatchMode(BatchMode mode)
|
||||
{
|
||||
this.batchMode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,6 +25,7 @@ import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Utf8Appendable.NotUtf8Exception;
|
||||
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.CloseException;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
@ -209,6 +210,12 @@ public abstract class AbstractEventDriver implements IncomingFrames, EventDriver
|
||||
/* TODO: provide annotation in future */
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatchMode getBatchMode()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openSession(WebSocketSession session)
|
||||
{
|
||||
|
@ -23,6 +23,7 @@ import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.BatchMode;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.api.extensions.Frame;
|
||||
import org.eclipse.jetty.websocket.api.extensions.IncomingFrames;
|
||||
@ -35,6 +36,8 @@ public interface EventDriver extends IncomingFrames
|
||||
|
||||
public WebSocketSession getSession();
|
||||
|
||||
public BatchMode getBatchMode();
|
||||
|
||||
public void onBinaryFrame(ByteBuffer buffer, boolean fin) throws IOException;
|
||||
|
||||
public void onBinaryMessage(byte[] data);
|
||||
|
@ -23,6 +23,7 @@ import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.BatchMode;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
import org.eclipse.jetty.websocket.api.extensions.Frame;
|
||||
@ -40,6 +41,7 @@ public class JettyAnnotatedEventDriver extends AbstractEventDriver
|
||||
{
|
||||
private final JettyAnnotatedMetadata events;
|
||||
private boolean hasCloseBeenCalled = false;
|
||||
private BatchMode batchMode;
|
||||
|
||||
public JettyAnnotatedEventDriver(WebSocketPolicy policy, Object websocket, JettyAnnotatedMetadata events)
|
||||
{
|
||||
@ -64,6 +66,13 @@ public class JettyAnnotatedEventDriver extends AbstractEventDriver
|
||||
{
|
||||
this.policy.setIdleTimeout(anno.maxIdleTime());
|
||||
}
|
||||
this.batchMode = anno.batchMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatchMode getBatchMode()
|
||||
{
|
||||
return this.batchMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user