Class NettyNetworkChannel

java.lang.Object
eu.cloudnetservice.driver.network.DefaultNetworkChannel
eu.cloudnetservice.driver.network.netty.NettyNetworkChannel
All Implemented Interfaces:
NetworkChannel, PacketSender

@Internal public final class NettyNetworkChannel extends DefaultNetworkChannel implements NetworkChannel
The default netty based implementation of a network channel.
Since:
4.0
  • Field Details

    • channel

      private final io.netty5.channel.Channel channel
    • eventManager

      private final EventManager eventManager
  • Constructor Details

  • Method Details

    • sendPacket

      public void sendPacket(@NonNull @NonNull Packet... packets)
      Sends all the given packets to the associated target.
      Specified by:
      sendPacket in interface PacketSender
      Parameters:
      packets - the packets to send.
    • sendPacketSync

      public void sendPacketSync(@NonNull @NonNull Packet... packets)
      Sends all the given packets to the associated target, waiting for the packet writes to the channel to complete before resuming the current thread.
      Specified by:
      sendPacketSync in interface PacketSender
      Parameters:
      packets - the packets to send.
    • sendPacket

      public void sendPacket(@NonNull @NonNull Packet packet)
      Sends the given packet to the associated target.
      Specified by:
      sendPacket in interface PacketSender
      Parameters:
      packet - the packet to send.
    • sendPacketSync

      public void sendPacketSync(@NonNull @NonNull Packet packet)
      Sends the given packet to the associated target, waiting for the packet write to the channel to complete before resuming the current thread.
      Specified by:
      sendPacketSync in interface PacketSender
      Parameters:
      packet - the packet to send.
    • writeable

      public boolean writeable()
      Get if the underlying channel is currently writeable and will perform writes to the channel immediately.
      Specified by:
      writeable in interface NetworkChannel
      Returns:
      true if the channel can instantly process i/o requests, false otherwise.
    • active

      public boolean active()
      Get if the underlying channel is still active and therefore connected.
      Specified by:
      active in interface NetworkChannel
      Returns:
      true if the channel is connected and active, false otherwise.
    • close

      public void close()
      Requests the close of the channel, flushing all outbound i/o requests before. After a channel was closed it cannot be used again.
      Specified by:
      close in interface NetworkChannel
    • writePacket

      @Nullable private @Nullable io.netty5.util.concurrent.Future<Void> writePacket(@NonNull @NonNull Packet packet, boolean flushAfter)
      Writes the given packet into the channel, calling the packet send event beforehand and not writing when the event gets cancelled by a module/plugin.
      Parameters:
      packet - the packet to write if the send operation is not cancelled.
      flushAfter - if the send queue should be flushed directly after the write process.
      Returns:
      the future completed once the write operation (and flush) of the channel succeeded, null if cancelled.
      Throws:
      NullPointerException - if the given packet is null.