Class ClientConnectionHandler

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.SimpleChannelInboundHandler<I>
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

public class ClientConnectionHandler extends ThreeWayHandshakeClientHandler<JoinMessage,WelcomeMessage>
This handler performs the handshake with the server and processes incoming messages during the session.

The handshake is initiated by a JoinMessage sent by the client, which is answered with a WelcomeMessage from the server. The client must then confirm this message with a SuccessMessage.

  • Field Details

    • CLIENT_CONNECTION_HANDLER

      public static final String CLIENT_CONNECTION_HANDLER
      See Also:
    • timeout

      protected final Duration timeout
    • handshakeFuture

      protected final CompletableFuture<Void> handshakeFuture
    • pipeline

      protected final Pipeline pipeline
    • networkId

      protected final int networkId
    • identity

      protected final Identity identity
    • timeoutFuture

      protected io.netty.util.concurrent.ScheduledFuture<?> timeoutFuture
  • Constructor Details

    • ClientConnectionHandler

      public ClientConnectionHandler(ClientEnvironment environment)
  • Method Details

    • getLogger

      protected org.slf4j.Logger getLogger()
    • validateSessionOffer

      protected ErrorMessage.Error validateSessionOffer(WelcomeMessage offerMessage)
      Description copied from class: ThreeWayHandshakeClientHandler
      This method validates the session offered by the server and must return an ErrorMessage.Error in case of error. Otherwise null must be returned.
      Specified by:
      validateSessionOffer in class ThreeWayHandshakeClientHandler<JoinMessage,WelcomeMessage>
      Parameters:
      offerMessage - the message that should be validated
      Returns:
      ErrorMessage.Error in case of error, otherwise null
    • createConnection

      protected void createConnection(io.netty.channel.ChannelHandlerContext ctx, WelcomeMessage offerMessage)
      Specified by:
      createConnection in class ThreeWayHandshakeClientHandler<JoinMessage,WelcomeMessage>
    • processUnexpectedMessageDuringHandshake

      protected void processUnexpectedMessageDuringHandshake(io.netty.channel.ChannelHandlerContext ctx, Message message)
    • channelRead0

      public void channelRead0(io.netty.channel.ChannelHandlerContext ctx, Message msg)
      Description copied from class: SimpleChannelDuplexHandler
      Is called for each message of type SimpleChannelDuplexHandler on inbound channel.
      Specified by:
      channelRead0 in class SimpleChannelDuplexHandler<Message,Message>
      Parameters:
      ctx - the ChannelHandlerContext which this SimpleChannelDuplexHandler belongs to
      msg - the message to handle
    • close

      public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception
      Specified by:
      close in interface io.netty.channel.ChannelOutboundHandler
      Overrides:
      close in class SimpleChannelDuplexHandler<Message,Message>
      Throws:
      Exception
    • channelWrite0

      protected void channelWrite0(io.netty.channel.ChannelHandlerContext ctx, Message msg, io.netty.channel.ChannelPromise promise)
      Description copied from class: SimpleChannelDuplexHandler
      Is called for each message of type SimpleChannelDuplexHandler on the outbound channel.
      Specified by:
      channelWrite0 in class SimpleChannelDuplexHandler<Message,Message>
      Parameters:
      ctx - the ChannelHandlerContext which this SimpleChannelDuplexHandler belongs to
      msg - the message to handle
      promise - the corresponding promise
    • processMessageAfterHandshake

      protected void processMessageAfterHandshake(io.netty.channel.ChannelHandlerContext ctx, Message message)
    • channelActive

      public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelActive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelActive in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • startTimeoutGuard

      protected void startTimeoutGuard(io.netty.channel.ChannelHandlerContext ctx)
    • rejectSession

      protected void rejectSession(io.netty.channel.ChannelHandlerContext ctx, String error)
    • exceptionCaught

      public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelHandler
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      exceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapter