public abstract class AbstractListenerWebSocketSession<T> extends AbstractWebSocketSession<T>
WebSocketSession
implementations that bridge between
event-listener WebSocket APIs (e.g. Java WebSocket API JSR-356, Jetty,
Undertow) and Reactive Streams.
Also an implementation of Subscriber<Void>
so it can be used as
the completion subscriber for session handling
Modifier and Type | Class and Description |
---|---|
private class |
AbstractListenerWebSocketSession.WebSocketReceivePublisher |
protected class |
AbstractListenerWebSocketSession.WebSocketSendProcessor |
Modifier and Type | Field and Description |
---|---|
private <any> |
completionMono |
private static int |
RECEIVE_BUFFER_SIZE
The "back-pressure" buffer size to use if the underlying WebSocket API
does not have flow control for receiving messages.
|
private AbstractListenerWebSocketSession.WebSocketReceivePublisher |
receivePublisher |
private java.util.concurrent.atomic.AtomicBoolean |
sendCalled |
private AbstractListenerWebSocketSession.WebSocketSendProcessor |
sendProcessor |
Constructor and Description |
---|
AbstractListenerWebSocketSession(T delegate,
java.lang.String id,
HandshakeInfo handshakeInfo,
DataBufferFactory bufferFactory)
Base constructor.
|
AbstractListenerWebSocketSession(T delegate,
java.lang.String id,
HandshakeInfo handshakeInfo,
DataBufferFactory bufferFactory,
<any> completionMono)
Alternative constructor with completion
Mono<Void> to propagate
the session completion (success or error) (for client-side use). |
Modifier and Type | Method and Description |
---|---|
protected abstract boolean |
canSuspendReceiving()
Whether the underlying WebSocket API has flow control and can suspend and
resume the receiving of messages.
|
protected AbstractListenerWebSocketSession.WebSocketSendProcessor |
getSendProcessor() |
(package private) void |
handleClose(CloseStatus reason)
Handle a close callback from the WebSocketHandler adapter
|
(package private) void |
handleError(java.lang.Throwable ex)
Handle an error callback from the WebSocketHandler adapter
|
(package private) void |
handleMessage(WebSocketMessage.Type type,
WebSocketMessage message)
Handle a message callback from the WebSocketHandler adapter
|
void |
onComplete() |
void |
onError(java.lang.Throwable ex) |
void |
onNext(java.lang.Void aVoid) |
void |
onSubscribe(Subscription subscription) |
<any> |
receive()
Get the flux of incoming messages.
|
protected abstract void |
resumeReceiving()
Resume receiving new message(s) after demand is generated by the
downstream Subscriber.
|
<any> |
send(<any> messages)
Write the given messages to the WebSocket connection.
|
protected abstract boolean |
sendMessage(WebSocketMessage message)
Send the given WebSocket message.
|
protected abstract void |
suspendReceiving()
Suspend receiving until received message(s) are processed and more demand
is generated by the downstream Subscriber.
|
binaryMessage, bufferFactory, getDelegate, getHandshakeInfo, getId, pingMessage, pongMessage, textMessage, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
close, close
private static final int RECEIVE_BUFFER_SIZE
@Nullable private final <any> completionMono
private final AbstractListenerWebSocketSession.WebSocketReceivePublisher receivePublisher
@Nullable private volatile AbstractListenerWebSocketSession.WebSocketSendProcessor sendProcessor
private final java.util.concurrent.atomic.AtomicBoolean sendCalled
public AbstractListenerWebSocketSession(T delegate, java.lang.String id, HandshakeInfo handshakeInfo, DataBufferFactory bufferFactory)
delegate
- the native WebSocket session, channel, or connectionid
- the session idhandshakeInfo
- the handshake infobufferFactory
- the DataBuffer factor for the current connectionpublic AbstractListenerWebSocketSession(T delegate, java.lang.String id, HandshakeInfo handshakeInfo, DataBufferFactory bufferFactory, @Nullable <any> completionMono)
Mono<Void>
to propagate
the session completion (success or error) (for client-side use).protected AbstractListenerWebSocketSession.WebSocketSendProcessor getSendProcessor()
public <any> receive()
WebSocketSession
receive
in interface WebSocketSession
receive
in class AbstractWebSocketSession<T>
public <any> send(<any> messages)
WebSocketSession
send
in interface WebSocketSession
send
in class AbstractWebSocketSession<T>
messages
- the messages to writeprotected abstract boolean canSuspendReceiving()
protected abstract void suspendReceiving()
Note: if the underlying WebSocket API does not provide
flow control for receiving messages, and this method should be a no-op
and canSuspendReceiving()
should return false
.
protected abstract void resumeReceiving()
Note: if the underlying WebSocket API does not provide
flow control for receiving messages, and this method should be a no-op
and canSuspendReceiving()
should return false
.
protected abstract boolean sendMessage(WebSocketMessage message) throws java.io.IOException
java.io.IOException
void handleMessage(WebSocketMessage.Type type, WebSocketMessage message)
void handleError(java.lang.Throwable ex)
void handleClose(CloseStatus reason)
public void onSubscribe(Subscription subscription)
public void onNext(java.lang.Void aVoid)
public void onError(java.lang.Throwable ex)
public void onComplete()