Skip to content

Commit

Permalink
Issue #8991 - rename websocket isDemanding() method to isAutoDemanding()
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <[email protected]>
  • Loading branch information
lachlan-roberts committed Feb 8, 2023
1 parent b87f938 commit d2dcbeb
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* </p>
* <p>
* 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. <br>
* </p>
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -395,7 +395,7 @@ public void onOpen()
sessionState.onOpen();
if (LOG.isDebugEnabled())
LOG.debug("ConnectionState: Transition to OPEN");
if (!demanding)
if (autoDemanding)
autoDemand();
},
x ->
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public void onClosed(CloseStatus closeStatus, Callback callback)
}

@Override
public boolean isDemanding()
public boolean isAutoDemanding()
{
return true;
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void onFrame(Frame frame, Callback callback)
}
finally
{
if (!_coreSession.isDemanding())
if (_coreSession.isAutoDemanding())
_coreSession.autoDemand();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> textMessages = new ArrayList<>();
List<ByteBuffer> binaryMessages = new ArrayList<>();
Expand All @@ -57,7 +57,7 @@ public class MessageHandlerTest
@BeforeEach
public void beforeEach() throws Exception
{
demanding = false;
autoDemanding = true;

coreSession = new CoreSession.Empty()
{
Expand Down Expand Up @@ -94,9 +94,9 @@ protected void onBinary(ByteBuffer message, Callback callback)
}

@Override
public boolean isDemanding()
public boolean isAutoDemanding()
{
return demanding;
return autoDemanding;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,9 @@ public void onError(Throwable cause, Callback callback)
}

@Override
public boolean isDemanding()
public boolean isAutoDemanding()
{
return true;
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ public void onOpen(CoreSession coreSession, Callback callback)
}

@Override
public boolean isDemanding()
public boolean isAutoDemanding()
{
return true;
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void parseIncomingHex(String... rawhex)
public void succeeded()
{
super.succeeded();
if (!coreSession.isDemanding())
if (coreSession.isAutoDemanding())
coreSession.autoDemand();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ public void onClosed(CloseStatus closeStatus, Callback callback)
}

@Override
public boolean isDemanding()
public boolean isAutoDemanding()
{
return true;
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public void testSimpleDemand() throws Exception
TestFrameHandler serverHandler = new TestFrameHandler()
{
@Override
public boolean isDemanding()
public boolean isAutoDemanding()
{
return true;
return false;
}
};

Expand Down Expand Up @@ -153,9 +153,9 @@ public void onOpen(CoreSession coreSession, Callback callback)
}

@Override
public boolean isDemanding()
public boolean isAutoDemanding()
{
return true;
return false;
}

@Override
Expand Down Expand Up @@ -260,9 +260,9 @@ public void onOpen(CoreSession coreSession, Callback callback)
}

@Override
public boolean isDemanding()
public boolean isAutoDemanding()
{
return true;
return false;
}

@Override
Expand Down Expand Up @@ -326,9 +326,9 @@ public void onClosed(CloseStatus closeStatus)
}

@Override
public boolean isDemanding()
public boolean isAutoDemanding()
{
return true;
return false;
}

@Override
Expand Down Expand Up @@ -393,9 +393,9 @@ public void onOpen(CoreSession coreSession, Callback callback)
}

@Override
public boolean isDemanding()
public boolean isAutoDemanding()
{
return true;
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ public void onError(Throwable cause, Callback callback)
}

@Override
public boolean isDemanding()
public boolean isAutoDemanding()
{
return true;
return false;
}

public Set<MessageHandler> getMessageHandlers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ public void onError(Throwable cause, Callback callback)
}

@Override
public boolean isDemanding()
public boolean isAutoDemanding()
{
return true;
return false;
}

public Set<MessageHandler> getMessageHandlers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d2dcbeb

Please sign in to comment.