Package discord4j.gateway
Class DiscordWebSocketHandler
- java.lang.Object
-
- discord4j.gateway.DiscordWebSocketHandler
-
public class DiscordWebSocketHandler extends Object
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
ofGatewayPayload
to push inbound payloads and aFlux
ofGatewayPayload
to pull outbound payloads.The handler also provides two methods to control the lifecycle and proper cleanup, like
close()
anderror(Throwable)
which perform operations on the current session. It is necessary to use these methods in order to signal closure or errors and cleanly complete the session.All payloads going through this handler are passed to the given
PayloadReader
andPayloadWriter
.
-
-
Constructor Summary
Constructors Constructor Description DiscordWebSocketHandler(PayloadReader reader, PayloadWriter writer, reactor.core.publisher.FluxSink<GatewayPayload<?>> inbound, reactor.core.publisher.Flux<GatewayPayload<?>> outbound, reactor.core.publisher.Flux<GatewayPayload<Heartbeat>> heartbeat, int shardIndex, GatewayLimiter limiter)
Create a new handler with the given payload reader, payload writer and payload exchanges.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Initiates a close sequence that will terminate this session.void
error(Throwable error)
Initiates a close sequence with the given error.reactor.core.publisher.Mono<Void>
handle(reactor.netty.http.websocket.WebsocketInbound in, reactor.netty.http.websocket.WebsocketOutbound out)
-
-
-
Constructor Detail
-
DiscordWebSocketHandler
public DiscordWebSocketHandler(PayloadReader reader, PayloadWriter writer, reactor.core.publisher.FluxSink<GatewayPayload<?>> inbound, reactor.core.publisher.Flux<GatewayPayload<?>> outbound, reactor.core.publisher.Flux<GatewayPayload<Heartbeat>> heartbeat, int shardIndex, GatewayLimiter limiter)
Create a new handler with the given payload reader, payload writer and payload exchanges.- Parameters:
reader
- the PayloadReader to process each inbound payloadwriter
- the PayloadWriter to process each outbound payloadinbound
- the FluxSink of GatewayPayloads to process inbound payloadsoutbound
- the Flux of GatewayPayloads to process outbound payloadsheartbeat
- the Flux of heartbeat payloadsshardIndex
- the shard index of this connection, for tracinglimiter
- a GatewayLimiter to throttle IDENTIFY requests
-
-
Method Detail
-
handle
public reactor.core.publisher.Mono<Void> handle(reactor.netty.http.websocket.WebsocketInbound in, reactor.netty.http.websocket.WebsocketOutbound out)
-
close
public void close()
Initiates a close sequence that will terminate this session. It will notify all exchanges and the session completionMono
inhandle(reactor.netty.http.websocket.WebsocketInbound, reactor.netty.http.websocket.WebsocketOutbound)
through a complete signal, dropping all future signals.
-
error
public void error(Throwable error)
Initiates a close sequence with the given error. It will terminate this session with an error signal on thehandle(reactor.netty.http.websocket.WebsocketInbound, reactor.netty.http.websocket.WebsocketOutbound)
method, while completing both exchanges through normal complete signals.The error can then be channeled downstream and acted upon accordingly.
- Parameters:
error
- the cause for this session termination
-
-