public class GatewayWebsocketHandler extends Object
Includes a zlib-based decompressor and dedicated handling of closing events that normally occur during Discord gateway lifecycle.
This handler uses a FluxSink of ByteBuf to push inbound payloads and a Flux of
ByteBuf to pull outbound payloads.
The handler also provides methods to control the lifecycle, which perform operations on the current session. It is required to use them to properly release important resources and complete the session.
| Constructor and Description |
|---|
GatewayWebsocketHandler(FluxSink<ByteBuf> inbound,
Flux<ByteBuf> outbound,
Context context)
Create a new handler with the given data pipelines.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Initiates a close sequence that will terminate this session and instruct consumers downstream that a reconnect
should take place afterwards.
|
void |
close(DisconnectBehavior behavior)
Initiates a close sequence that will terminate this session and then execute a given
DisconnectBehavior. |
void |
error(Throwable error)
Initiates a close sequence with the given error.
|
Mono<Tuple2<DisconnectBehavior,CloseStatus>> |
handle(WebsocketInbound in,
WebsocketOutbound out)
Handle an upgraded websocket connection, given by both
WebsocketInbound and WebsocketOutbound to
manage a session until the remote closes or one of the local methods close() or
error(Throwable) methods are called. |
public Mono<Tuple2<DisconnectBehavior,CloseStatus>> handle(WebsocketInbound in, WebsocketOutbound out)
WebsocketInbound and WebsocketOutbound to
manage a session until the remote closes or one of the local methods close() or
error(Throwable) methods are called. When that happens, a close procedure will take place and ultimately
emit a pair of DisconnectBehavior and remote CloseStatus, if present or "-1" if none is present.in - the websocket inboundout - the websocket outboundMono that upon subscription, manages a websocket session until it closes where a Tuple2
is emitted representing both the DisconnectBehavior that initiated the close procedure, and the inbound
CloseStatus.public void close()
public void close(DisconnectBehavior behavior)
DisconnectBehavior.behavior - the DisconnectBehavior to follow after the close sequence startspublic void error(Throwable error)
error - the cause for this session termination