|
|
@ -150,13 +150,13 @@ public abstract class AbstractListenerWebSocketSession<T> extends AbstractWebSoc |
|
|
|
protected abstract void resumeReceiving(); |
|
|
|
protected abstract void resumeReceiving(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns {@code true} if receiving new message(s) is suspended otherwise |
|
|
|
* Whether receiving new message(s) is suspended. |
|
|
|
* {@code false}. |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> if the underlying WebSocket API does not provide |
|
|
|
* <p><strong>Note:</strong> if the underlying WebSocket API does not provide |
|
|
|
* flow control for receiving messages, and this method should return |
|
|
|
* flow control for receiving messages, then this method as well as |
|
|
|
* {@code false} and {@link #canSuspendReceiving()} should return {@code false}. |
|
|
|
* {@link #canSuspendReceiving()} should both return {@code false}. |
|
|
|
* @return returns {@code true} if receiving new message(s) is suspended |
|
|
|
* @return returns {@code true} if receiving new message(s) is suspended, |
|
|
|
* otherwise {@code false}. |
|
|
|
* or otherwise {@code false}. |
|
|
|
|
|
|
|
* @since 5.0.2 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected abstract boolean isSuspended(); |
|
|
|
protected abstract boolean isSuspended(); |
|
|
|
|
|
|
|
|
|
|
@ -226,14 +226,15 @@ public abstract class AbstractListenerWebSocketSession<T> extends AbstractWebSoc |
|
|
|
|
|
|
|
|
|
|
|
private final class WebSocketReceivePublisher extends AbstractListenerReadPublisher<WebSocketMessage> { |
|
|
|
private final class WebSocketReceivePublisher extends AbstractListenerReadPublisher<WebSocketMessage> { |
|
|
|
|
|
|
|
|
|
|
|
private volatile Queue<Object> pendingWebSocketMessages = Queues.unbounded().get(); |
|
|
|
private volatile Queue<Object> pendingMessages = Queues.unbounded(Queues.SMALL_BUFFER_SIZE).get(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void checkOnDataAvailable() { |
|
|
|
protected void checkOnDataAvailable() { |
|
|
|
if (isSuspended()) { |
|
|
|
if (isSuspended()) { |
|
|
|
resumeReceiving(); |
|
|
|
resumeReceiving(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!pendingWebSocketMessages.isEmpty()) { |
|
|
|
if (!this.pendingMessages.isEmpty()) { |
|
|
|
onDataAvailable(); |
|
|
|
onDataAvailable(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -246,7 +247,7 @@ public abstract class AbstractListenerWebSocketSession<T> extends AbstractWebSoc |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
protected WebSocketMessage read() throws IOException { |
|
|
|
protected WebSocketMessage read() throws IOException { |
|
|
|
return (WebSocketMessage) pendingWebSocketMessages.poll(); |
|
|
|
return (WebSocketMessage) this.pendingMessages.poll(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -258,7 +259,7 @@ public abstract class AbstractListenerWebSocketSession<T> extends AbstractWebSoc |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void handleMessage(WebSocketMessage webSocketMessage) { |
|
|
|
void handleMessage(WebSocketMessage webSocketMessage) { |
|
|
|
this.pendingWebSocketMessages.offer(webSocketMessage); |
|
|
|
this.pendingMessages.offer(webSocketMessage); |
|
|
|
onDataAvailable(); |
|
|
|
onDataAvailable(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|