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
  • Constructor Details

    • NettyNetworkChannel

      public NettyNetworkChannel(@NonNull @NonNull io.netty5.channel.Channel channel, @NonNull @NonNull PacketListenerRegistry packetRegistry, @NonNull @NonNull NetworkChannelHandler handler, @NonNull @NonNull HostAndPort serverAddress, @NonNull @NonNull HostAndPort clientAddress, boolean clientProvidedChannel)
      Constructs a new netty network channel instance.
      Parameters:
      channel - the netty channel to wrap.
      packetRegistry - the packet registry for this channel.
      handler - the handler to post events to.
      serverAddress - the server address to which the client connected.
      clientAddress - the client address which is assigned to the connection.
      clientProvidedChannel - true if the channel is handled by a server, false otherwise.
      Throws:
      NullPointerException - if one of the required constructor paramters is null.
  • 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.
    • 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