Class NettyNetworkHandler

java.lang.Object
io.netty5.channel.SimpleChannelInboundHandler<BasePacket>
eu.cloudnetservice.driver.network.netty.NettyNetworkHandler
All Implemented Interfaces:
io.netty5.channel.ChannelHandler
Direct Known Subclasses:
NettyNetworkClientHandler, NettyNetworkServerHandler

@Internal public abstract class NettyNetworkHandler extends io.netty5.channel.SimpleChannelInboundHandler<BasePacket>
The default netty inbound handler used to call downstream packet listeners when receiving a packet.
Since:
4.0
  • Field Details

    • LOGGER

      private static final eu.cloudnetservice.common.log.Logger LOGGER
    • eventManager

      protected final EventManager eventManager
    • channel

      protected volatile NettyNetworkChannel channel
  • Constructor Details

    • NettyNetworkHandler

      protected NettyNetworkHandler(@NonNull @NonNull EventManager eventManager)
      Constructs a new netty network handler instance.
      Parameters:
      eventManager - the event manager of the current component.
      Throws:
      NullPointerException - if the given event manager is null.
  • Method Details

    • channelInactive

      public void channelInactive(@NonNull @NonNull io.netty5.channel.ChannelHandlerContext ctx) throws Exception
      Throws:
      Exception
    • channelExceptionCaught

      public void channelExceptionCaught(@NonNull @NonNull io.netty5.channel.ChannelHandlerContext ctx, @NonNull @NonNull Throwable cause)
    • channelReadComplete

      public void channelReadComplete(@NonNull @NonNull io.netty5.channel.ChannelHandlerContext ctx)
    • messageReceived

      protected void messageReceived(@NonNull @NonNull io.netty5.channel.ChannelHandlerContext ctx, @NonNull @NonNull BasePacket msg)
      Specified by:
      messageReceived in class io.netty5.channel.SimpleChannelInboundHandler<BasePacket>
    • doHandlePacket

      protected void doHandlePacket(@NonNull @NonNull BasePacket packet)
      Handles the incoming packet and posts it either to the associated waiting query handler or directly into the packet registry, calling all associated handlers.
      Parameters:
      packet - the packet to handle.
      Throws:
      NullPointerException - if the given packet is null.
    • channels

      @NonNull protected abstract @NonNull Collection<NetworkChannel> channels()
      Get all channels which are connected to the underlying network component.
      Returns:
      all connected channels.
    • packetDispatcher

      @NonNull protected abstract @NonNull Executor packetDispatcher()
      Get the packet dispatcher used to dispatch incoming packets. Each dispatcher is normally bound to the network component which opened/received the connection and requested this handler.
      Returns:
      the dispatcher used to dispatch packets.