diff options
author | Simone Bordet | 2014-02-18 17:22:05 +0000 |
---|---|---|
committer | Simone Bordet | 2014-02-18 17:31:49 +0000 |
commit | 1ac6b82912bee462fe39114a838a5bd1be72576b (patch) | |
tree | 021efa06a7f0e7660ad20a2f264c66ff52e53495 /jetty-websocket/websocket-api/src | |
parent | 3240e7383b18ae24420a72cc36dfe305a9f6970a (diff) | |
download | org.eclipse.jetty.project-1ac6b82912bee462fe39114a838a5bd1be72576b.tar.gz org.eclipse.jetty.project-1ac6b82912bee462fe39114a838a5bd1be72576b.tar.xz org.eclipse.jetty.project-1ac6b82912bee462fe39114a838a5bd1be72576b.zip |
428232 - Rework batch mode / buffering in websocket.
Introduced the automatic batch mode, akin to Jetty 8's WebSocket
implementation.
Now, if there are no more frames to process, and the previous frames
have been aggregated, FrameFlusher auto-flushes the aggregated frames.
This simplifies applications because they don't need to call flush()
explicitly.
Diffstat (limited to 'jetty-websocket/websocket-api/src')
3 files changed, 56 insertions, 24 deletions
diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/BatchMode.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/BatchMode.java new file mode 100644 index 0000000000..a3f7aab753 --- /dev/null +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/BatchMode.java @@ -0,0 +1,50 @@ +// +// ======================================================================== +// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.api; + +import org.eclipse.jetty.websocket.api.extensions.Frame; +import org.eclipse.jetty.websocket.api.extensions.OutgoingFrames; + +/** + * The possible batch modes when invoking {@link OutgoingFrames#outgoingFrame(Frame, WriteCallback, BatchMode)}. + */ +public enum BatchMode +{ + /** + * Implementers are free to decide whether to send or not frames + * to the network layer. + */ + AUTO, + + /** + * Implementers must batch frames. + */ + ON, + + /** + * Implementers must send frames to the network layer. + */ + OFF; + + public static BatchMode max(BatchMode one, BatchMode two) + { + // Return the BatchMode that has the higher priority, where AUTO < ON < OFF. + return one.ordinal() < two.ordinal() ? two : one; + } +} diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java index ad08f59e87..c1a880a153 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/RemoteEndpoint.java @@ -123,16 +123,15 @@ public interface RemoteEndpoint void sendString(String text, WriteCallback callback); /** - * @return whether the implementation is allowed to batch messages. + * @return the batch mode with which messages are sent. * @see #flush() */ - boolean isBatching(); - + BatchMode getBatchMode(); /** * Flushes messages that may have been batched by the implementation. * @throws IOException if the flush fails - * @see #isBatching() + * @see #getBatchMode() */ void flush() throws IOException; } diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/extensions/OutgoingFrames.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/extensions/OutgoingFrames.java index 1634c4cc3d..9a3aed27da 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/extensions/OutgoingFrames.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/extensions/OutgoingFrames.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.websocket.api.extensions; +import org.eclipse.jetty.websocket.api.BatchMode; import org.eclipse.jetty.websocket.api.WriteCallback; /** @@ -36,26 +37,8 @@ public interface OutgoingFrames * * @param frame the frame to eventually write to the network layer. * @param callback the callback to notify when the frame is written. - * @param flushMode the flush mode required by the sender. + * @param batchMode the batch mode requested by the sender. */ - void outgoingFrame(Frame frame, WriteCallback callback, FlushMode flushMode); + void outgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode); - /** - * The possible flush modes when invoking {@link #outgoingFrame(Frame, WriteCallback, OutgoingFrames.FlushMode)}. - */ - public enum FlushMode - { - /** - * Implementers of {@link #outgoingFrame(Frame, WriteCallback, OutgoingFrames.FlushMode)} - * are free to decide whether to flush or not the given frame - * to the network layer. - */ - AUTO, - - /** - * Implementers of {@link #outgoingFrame(Frame, WriteCallback, OutgoingFrames.FlushMode)} - * must send the given frame to the network layer. - */ - SEND - } } |