Package discord4j.gateway
Class GatewayWebsocketHandler
java.lang.Object
discord4j.gateway.GatewayWebsocketHandler
Represents a WebSocket handler specialized for Discord gateway operations.
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 Summary
ConstructorsConstructorDescriptionGatewayWebsocketHandler(Sinks.Many<ByteBuf> inbound, Flux<ByteBuf> outbound, ContextView context) Create a new handler with the given data pipelines.GatewayWebsocketHandler(Sinks.Many<ByteBuf> inbound, Flux<ByteBuf> outbound, ContextView context, boolean unpooled) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Initiates a close sequence that will terminate this session and instruct consumers downstream that a reconnect should take place afterwards.voidclose(DisconnectBehavior behavior) Initiates a close sequence that will terminate this session and then execute a givenDisconnectBehavior.voidInitiates a close sequence with the given error.handle(WebsocketInbound in, WebsocketOutbound out) Handle an upgraded websocket connection, given by bothWebsocketInboundandWebsocketOutboundto manage a session until the remote closes or one of the local methodsclose()orerror(Throwable)methods are called.
-
Constructor Details
-
GatewayWebsocketHandler
public GatewayWebsocketHandler(Sinks.Many<ByteBuf> inbound, Flux<ByteBuf> outbound, ContextView context) Create a new handler with the given data pipelines.- Parameters:
inbound- theSinks.ManyofByteBufto process inbound payloadsoutbound- theFluxofByteBufto process outbound payloadscontext- the ReactorContextViewthat owns this handler, to enrich logging
-
GatewayWebsocketHandler
public GatewayWebsocketHandler(Sinks.Many<ByteBuf> inbound, Flux<ByteBuf> outbound, ContextView context, boolean unpooled)
-
-
Method Details
-
handle
public Mono<Tuple2<DisconnectBehavior,CloseStatus>> handle(WebsocketInbound in, WebsocketOutbound out) Handle an upgraded websocket connection, given by bothWebsocketInboundandWebsocketOutboundto manage a session until the remote closes or one of the local methodsclose()orerror(Throwable)methods are called. When that happens, a close procedure will take place and ultimately emit a pair ofDisconnectBehaviorand remoteCloseStatus, if present or "-1" if none is present.- Parameters:
in- the websocket inboundout- the websocket outbound- Returns:
- a
Monothat upon subscription, manages a websocket session until it closes where aTuple2is emitted representing both theDisconnectBehaviorthat initiated the close procedure, and the inboundCloseStatus.
-
close
public void close()Initiates a close sequence that will terminate this session and instruct consumers downstream that a reconnect should take place afterwards. -
close
Initiates a close sequence that will terminate this session and then execute a givenDisconnectBehavior.- Parameters:
behavior- theDisconnectBehaviorto follow after the close sequence starts
-
error
Initiates a close sequence with the given error. The session will be terminated abruptly and then instruct consumers downstream that a reconnect should take place afterwards.- Parameters:
error- the cause for this session termination
-