Class NettyNetworkHandler

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

public abstract class NettyNetworkHandler extends io.netty5.channel.SimpleChannelInboundHandler<eu.cloudnetservice.driver.network.protocol.BasePacket>
The default netty inbound handler used to call downstream packet listeners when receiving a packet.
Since:
4.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    private static final org.slf4j.Logger
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelExceptionCaught(@NonNull io.netty5.channel.ChannelHandlerContext ctx, @NonNull Throwable cause)
    void
    channelInactive(@NonNull io.netty5.channel.ChannelHandlerContext ctx)
    void
    channelReadComplete(@NonNull io.netty5.channel.ChannelHandlerContext ctx)
    protected abstract @NonNull Collection<eu.cloudnetservice.driver.network.NetworkChannel>
    Get all channels which are connected to the underlying network component.
    protected void
    doHandlePacket(@NonNull eu.cloudnetservice.driver.network.protocol.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.
    private void
    handlePacket(@NonNull eu.cloudnetservice.driver.network.protocol.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.
    protected void
    messageReceived(@NonNull io.netty5.channel.ChannelHandlerContext ctx, @NonNull eu.cloudnetservice.driver.network.protocol.BasePacket msg)
    protected abstract @NonNull Executor
    Get the packet dispatcher used to dispatch incoming packets.

    Methods inherited from class io.netty5.channel.SimpleChannelInboundHandler

    acceptInboundMessage, channelRead

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.netty5.channel.ChannelHandler

    bind, channelActive, channelInboundEvent, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • channel

      protected volatile NettyNetworkChannel channel
  • Constructor Details

    • NettyNetworkHandler

      public NettyNetworkHandler()
  • 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 eu.cloudnetservice.driver.network.protocol.BasePacket msg)
      Specified by:
      messageReceived in class io.netty5.channel.SimpleChannelInboundHandler<eu.cloudnetservice.driver.network.protocol.BasePacket>
    • handlePacket

      private void handlePacket(@NonNull @NonNull eu.cloudnetservice.driver.network.protocol.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. This method applies exception handling which is not done by doHandlePacket(BasePacket).
      Parameters:
      packet - the packet hto handle.
      Throws:
      NullPointerException - if the given packet is null.
    • doHandlePacket

      protected void doHandlePacket(@NonNull @NonNull eu.cloudnetservice.driver.network.protocol.BasePacket packet) throws Exception
      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.
      Exception - if an exception occurs while handling the given packet.
    • channels

      @NonNull protected abstract @NonNull Collection<eu.cloudnetservice.driver.network.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.