From d2dcbeba5b72263eb6d4b2da1f01c49092a172a9 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Wed, 8 Feb 2023 14:18:02 +1100 Subject: [PATCH] Issue #8991 - rename websocket isDemanding() method to isAutoDemanding() Signed-off-by: Lachlan Roberts --- .../jetty/websocket/core/CoreSession.java | 2 +- .../jetty/websocket/core/FrameHandler.java | 14 ++++++------- .../core/internal/MessageHandler.java | 4 ++-- .../core/internal/WebSocketCoreSession.java | 14 ++++++------- .../jetty/websocket/core/DemandTest.java | 4 ++-- .../core/DemandingIncomingFramesCapture.java | 2 +- .../websocket/core/MessageHandlerTest.java | 8 ++++---- .../websocket/core/WebSocketCloseTest.java | 4 ++-- .../websocket/core/WebSocketOpenTest.java | 4 ++-- .../core/extensions/ExtensionTool.java | 2 +- .../PermessageDeflateDemandTest.java | 4 ++-- .../core/server/WebSocketServerTest.java | 20 +++++++++---------- .../common/JakartaWebSocketFrameHandler.java | 4 ++-- .../common/JettyWebSocketFrameHandler.java | 4 ++-- .../common/JakartaWebSocketFrameHandler.java | 4 ++-- .../common/JettyWebSocketFrameHandler.java | 4 ++-- 16 files changed, 49 insertions(+), 49 deletions(-) diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java b/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java index 0fb82bef2eab..3f2701de6c2b 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java +++ b/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/CoreSession.java @@ -163,7 +163,7 @@ public interface CoreSession extends OutgoingFrames, Configuration * Manage flow control by indicating demand for handling Frames. A call to * {@link FrameHandler#onFrame(Frame, Callback)} will only be made if a * corresponding demand has been signaled. It is an error to call this method - * if {@link FrameHandler#isDemanding()} returns false. + * if {@link FrameHandler#isAutoDemanding()} returns true. * * @param n The number of frames that can be handled (in sequential calls to * {@link FrameHandler#onFrame(Frame, Callback)}). May not be negative. diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java b/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java index f812ae4ff073..28d54c139b93 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java +++ b/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/FrameHandler.java @@ -54,8 +54,8 @@ public interface FrameHandler extends IncomingFrames * FrameHandler can write during this call, but can not receive frames until the callback is succeeded. *

*

- * If the FrameHandler succeeds the callback we transition to OPEN state and can now receive frames if - * not demanding, or can now call {@link CoreSession#demand(long)} to receive frames if demanding. + * If the FrameHandler succeeds the callback we transition to OPEN state and can now receive frames if auto-demanding, + * or can now call {@link CoreSession#demand(long)} to receive frames if it is not auto-demanding. * If the FrameHandler fails the callback a close frame will be sent with {@link CloseStatus#SERVER_ERROR} and * the connection will be closed.
*

@@ -106,12 +106,12 @@ public interface FrameHandler extends IncomingFrames /** * Does the FrameHandler manage it's own demand? * - * @return true iff the FrameHandler will manage its own flow control by calling {@link CoreSession#demand(long)} when it - * is willing to receive new Frames. Otherwise the demand will be managed by an automatic call to demand(1) after every - * succeeded callback passed to {@link #onFrame(Frame, Callback)}. + * @return true if demand will be managed by an automatic call to demand(1) after every * succeeded callback passed to + * {@link #onFrame(Frame, Callback)}. If false the FrameHandler will need to manage its own flow control by calling + * {@link CoreSession#demand(long)} when it is willing to receive new Frames. */ - default boolean isDemanding() + default boolean isAutoDemanding() { - return false; + return true; } } diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/MessageHandler.java b/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/MessageHandler.java index 2b9a50130137..55934c490351 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/MessageHandler.java +++ b/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/MessageHandler.java @@ -36,8 +36,8 @@ * A utility implementation of FrameHandler that defragments * text frames into a String message before calling {@link #onText(String, Callback)}. * Flow control is by default automatic, but an implementation - * may extend {@link #isDemanding()} to return true and then explicityly control - * demand with calls to {@link CoreSession#demand(long)} + * may extend {@link #isAutoDemanding()} to return false and then explicitly control + * demand with calls to {@link CoreSession#demand(long)}. */ public class MessageHandler implements FrameHandler { diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketCoreSession.java b/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketCoreSession.java index ac2ea5f6f8a3..46577eca5f0e 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketCoreSession.java +++ b/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketCoreSession.java @@ -65,7 +65,7 @@ public class WebSocketCoreSession implements IncomingFrames, CoreSession, Dumpab private final WebSocketSessionState sessionState = new WebSocketSessionState(); private final FrameHandler handler; private final Negotiated negotiated; - private final boolean demanding; + private final boolean autoDemanding; private final Flusher flusher = new Flusher(this); private final ExtensionStack extensionStack; @@ -90,7 +90,7 @@ public WebSocketCoreSession(FrameHandler handler, Behavior behavior, Negotiated this.handler = handler; this.behavior = behavior; this.negotiated = negotiated; - this.demanding = handler.isDemanding(); + this.autoDemanding = handler.isAutoDemanding(); extensionStack = negotiated.getExtensions(); extensionStack.initialize(new IncomingAdaptor(), new OutgoingAdaptor(), this); } @@ -126,9 +126,9 @@ protected void handle(Runnable runnable) /** * @return True if the sessions handling is demanding. */ - public boolean isDemanding() + public boolean isAutoDemanding() { - return demanding; + return autoDemanding; } public ExtensionStack getExtensionStack() @@ -395,7 +395,7 @@ public void onOpen() sessionState.onOpen(); if (LOG.isDebugEnabled()) LOG.debug("ConnectionState: Transition to OPEN"); - if (!demanding) + if (autoDemanding) autoDemand(); }, x -> @@ -424,7 +424,7 @@ public void onOpen() @Override public void demand(long n) { - if (!demanding) + if (autoDemanding) throw new IllegalStateException("FrameHandler is not demanding: " + this); getExtensionStack().demand(n); } @@ -662,7 +662,7 @@ public void onFrame(Frame frame, Callback callback) // Handle inbound frame if (frame.getOpCode() != OpCode.CLOSE) { - Callback handlerCallback = isDemanding() ? callback : Callback.from(() -> + Callback handlerCallback = !isAutoDemanding() ? callback : Callback.from(() -> { callback.succeeded(); autoDemand(); diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/DemandTest.java b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/DemandTest.java index 9eb0acd89768..e88702dc7cfc 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/DemandTest.java +++ b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/DemandTest.java @@ -93,9 +93,9 @@ public void onClosed(CloseStatus closeStatus, Callback callback) } @Override - public boolean isDemanding() + public boolean isAutoDemanding() { - return true; + return false; } } diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/DemandingIncomingFramesCapture.java b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/DemandingIncomingFramesCapture.java index 5cb0883ae73e..70f65036dd61 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/DemandingIncomingFramesCapture.java +++ b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/DemandingIncomingFramesCapture.java @@ -34,7 +34,7 @@ public void onFrame(Frame frame, Callback callback) } finally { - if (!_coreSession.isDemanding()) + if (_coreSession.isAutoDemanding()) _coreSession.autoDemand(); } } diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/MessageHandlerTest.java b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/MessageHandlerTest.java index 691e0e6e9a31..c0050c0f0581 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/MessageHandlerTest.java +++ b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/MessageHandlerTest.java @@ -46,7 +46,7 @@ public class MessageHandlerTest static byte[] fourByteUtf8Bytes = fourByteUtf8String.getBytes(StandardCharsets.UTF_8); static byte[] nonUtf8Bytes = {0x7F, (byte)0xFF, (byte)0xFF}; - boolean demanding; + boolean autoDemanding; CoreSession coreSession; List textMessages = new ArrayList<>(); List binaryMessages = new ArrayList<>(); @@ -57,7 +57,7 @@ public class MessageHandlerTest @BeforeEach public void beforeEach() throws Exception { - demanding = false; + autoDemanding = true; coreSession = new CoreSession.Empty() { @@ -94,9 +94,9 @@ protected void onBinary(ByteBuffer message, Callback callback) } @Override - public boolean isDemanding() + public boolean isAutoDemanding() { - return demanding; + return autoDemanding; } }; diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java index 591db976be55..65faac9c69b9 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java +++ b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/WebSocketCloseTest.java @@ -585,9 +585,9 @@ public void onError(Throwable cause, Callback callback) } @Override - public boolean isDemanding() + public boolean isAutoDemanding() { - return true; + return false; } } } diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/WebSocketOpenTest.java b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/WebSocketOpenTest.java index 6d62fd177157..6c5ea6e5df45 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/WebSocketOpenTest.java +++ b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/WebSocketOpenTest.java @@ -204,9 +204,9 @@ public void onOpen(CoreSession coreSession, Callback callback) } @Override - public boolean isDemanding() + public boolean isAutoDemanding() { - return true; + return false; } } } diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java index 35d2014d440c..ebe6139422c2 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java +++ b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionTool.java @@ -102,7 +102,7 @@ public void parseIncomingHex(String... rawhex) public void succeeded() { super.succeeded(); - if (!coreSession.isDemanding()) + if (coreSession.isAutoDemanding()) coreSession.autoDemand(); } }; diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/extensions/PermessageDeflateDemandTest.java b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/extensions/PermessageDeflateDemandTest.java index d7a975dca624..dffbf6d8074a 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/extensions/PermessageDeflateDemandTest.java +++ b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/extensions/PermessageDeflateDemandTest.java @@ -187,9 +187,9 @@ public void onClosed(CloseStatus closeStatus, Callback callback) } @Override - public boolean isDemanding() + public boolean isAutoDemanding() { - return true; + return false; } } } diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/server/WebSocketServerTest.java b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/server/WebSocketServerTest.java index 4a4c27c14e12..41202c10abe9 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/server/WebSocketServerTest.java +++ b/jetty-core/jetty-websocket/jetty-websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/server/WebSocketServerTest.java @@ -94,9 +94,9 @@ public void testSimpleDemand() throws Exception TestFrameHandler serverHandler = new TestFrameHandler() { @Override - public boolean isDemanding() + public boolean isAutoDemanding() { - return true; + return false; } }; @@ -153,9 +153,9 @@ public void onOpen(CoreSession coreSession, Callback callback) } @Override - public boolean isDemanding() + public boolean isAutoDemanding() { - return true; + return false; } @Override @@ -260,9 +260,9 @@ public void onOpen(CoreSession coreSession, Callback callback) } @Override - public boolean isDemanding() + public boolean isAutoDemanding() { - return true; + return false; } @Override @@ -326,9 +326,9 @@ public void onClosed(CloseStatus closeStatus) } @Override - public boolean isDemanding() + public boolean isAutoDemanding() { - return true; + return false; } @Override @@ -393,9 +393,9 @@ public void onOpen(CoreSession coreSession, Callback callback) } @Override - public boolean isDemanding() + public boolean isAutoDemanding() { - return true; + return false; } @Override diff --git a/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jakarta-common/src/main/java/org/eclipse/jetty/ee10/websocket/jakarta/common/JakartaWebSocketFrameHandler.java b/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jakarta-common/src/main/java/org/eclipse/jetty/ee10/websocket/jakarta/common/JakartaWebSocketFrameHandler.java index c28869faf187..b539a2f7aaa2 100644 --- a/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jakarta-common/src/main/java/org/eclipse/jetty/ee10/websocket/jakarta/common/JakartaWebSocketFrameHandler.java +++ b/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jakarta-common/src/main/java/org/eclipse/jetty/ee10/websocket/jakarta/common/JakartaWebSocketFrameHandler.java @@ -323,9 +323,9 @@ public void onError(Throwable cause, Callback callback) } @Override - public boolean isDemanding() + public boolean isAutoDemanding() { - return true; + return false; } public Set getMessageHandlers() diff --git a/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jetty-common/src/main/java/org/eclipse/jetty/ee10/websocket/common/JettyWebSocketFrameHandler.java b/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jetty-common/src/main/java/org/eclipse/jetty/ee10/websocket/common/JettyWebSocketFrameHandler.java index 38fcda548f0c..27ad83f26d04 100644 --- a/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jetty-common/src/main/java/org/eclipse/jetty/ee10/websocket/common/JettyWebSocketFrameHandler.java +++ b/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jetty-common/src/main/java/org/eclipse/jetty/ee10/websocket/common/JettyWebSocketFrameHandler.java @@ -423,9 +423,9 @@ private void onTextFrame(Frame frame, Callback callback) } @Override - public boolean isDemanding() + public boolean isAutoDemanding() { - return true; + return false; } public void suspend() diff --git a/jetty-ee9/jetty-ee9-websocket/jetty-ee9-websocket-jakarta-common/src/main/java/org/eclipse/jetty/ee9/websocket/jakarta/common/JakartaWebSocketFrameHandler.java b/jetty-ee9/jetty-ee9-websocket/jetty-ee9-websocket-jakarta-common/src/main/java/org/eclipse/jetty/ee9/websocket/jakarta/common/JakartaWebSocketFrameHandler.java index 1fa957c8ef3a..3b0cf0d33aa9 100644 --- a/jetty-ee9/jetty-ee9-websocket/jetty-ee9-websocket-jakarta-common/src/main/java/org/eclipse/jetty/ee9/websocket/jakarta/common/JakartaWebSocketFrameHandler.java +++ b/jetty-ee9/jetty-ee9-websocket/jetty-ee9-websocket-jakarta-common/src/main/java/org/eclipse/jetty/ee9/websocket/jakarta/common/JakartaWebSocketFrameHandler.java @@ -323,9 +323,9 @@ public void onError(Throwable cause, Callback callback) } @Override - public boolean isDemanding() + public boolean isAutoDemanding() { - return true; + return false; } public Set getMessageHandlers() diff --git a/jetty-ee9/jetty-ee9-websocket/jetty-ee9-websocket-jetty-common/src/main/java/org/eclipse/jetty/ee9/websocket/common/JettyWebSocketFrameHandler.java b/jetty-ee9/jetty-ee9-websocket/jetty-ee9-websocket-jetty-common/src/main/java/org/eclipse/jetty/ee9/websocket/common/JettyWebSocketFrameHandler.java index 1c80cfa8dae2..1630a1b3b6d4 100644 --- a/jetty-ee9/jetty-ee9-websocket/jetty-ee9-websocket-jetty-common/src/main/java/org/eclipse/jetty/ee9/websocket/common/JettyWebSocketFrameHandler.java +++ b/jetty-ee9/jetty-ee9-websocket/jetty-ee9-websocket-jetty-common/src/main/java/org/eclipse/jetty/ee9/websocket/common/JettyWebSocketFrameHandler.java @@ -423,9 +423,9 @@ private void onTextFrame(Frame frame, Callback callback) } @Override - public boolean isDemanding() + public boolean isAutoDemanding() { - return true; + return false; } public void suspend()