A partial implementation of MessageSink for methods that consume WebSocket
messages using blocking stream APIs, typically via InputStream or Reader.
The first call to accept(Frame, Callback) triggers the application function
specified in the constructor to be invoked in a different thread.
Subsequent calls to accept(Frame, Callback) feed a nested MessageSink
that in turns feeds the InputStream or Reader stream.
Implementations of this class must manage the demand for WebSocket frames, and therefore must always be auto-demanding.
Upon return from the application function, the stream is closed. This means that the stream must be consumed synchronously within the invocation of the application function.
The demand for the next WebSocket message is performed when both the application function has returned and the last frame has been consumed (signaled by completing the callback associated with the frame).
Throwing from the application function results in the WebSocket connection to be closed.
| Modifier and Type | Field and Description |
|---|---|
| private volatile CompletableFuture | |
| private final Executor | |
| private MessageSink |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | accept(Frame
the frame to consume frame, final Callback the callback to complete when the frame is consumed callback)Implements org. Consumes the WebSocket frame, possibly asynchronously when this method has returned. |
| public void | fail(Throwable
the cause of the failure failure)Overrides default org. Fails this |
| public boolean | |
| public abstract MessageSink |
| dispatchComplete | back to summary |
|---|---|
| private volatile CompletableFuture<Void> dispatchComplete | |
| executor | back to summary |
|---|---|
| private final Executor executor | |
| typeSink | back to summary |
|---|---|
| private MessageSink typeSink | |
| DispatchedMessageSink | back to summary |
|---|---|
| public DispatchedMessageSink(CoreSession session, MethodHandle methodHandle, boolean autoDemand) | |
| accept | back to summary |
|---|---|
| public void accept(Frame frame, final Callback callback) Implements org. Doc from org. Consumes the WebSocket frame, possibly asynchronously when this method has returned. The callback argument must be completed when the frame payload is consumed. The demand for more frames must be explicitly invoked,
or arranged to be invoked asynchronously, by the implementation
of this method, by calling | |
| fail | back to summary |
|---|---|
| public void fail(Throwable failure) Overrides default org. Doc from org. Fails this | |
| isDispatched | back to summary |
|---|---|
| public boolean isDispatched() | |
| newMessageSink | back to summary |
|---|---|
| public abstract MessageSink newMessageSink() | |