Class NettyNetworkClient

java.lang.Object
eu.cloudnetservice.driver.impl.network.netty.client.NettyNetworkClient
All Implemented Interfaces:
eu.cloudnetservice.driver.network.NetworkClient, eu.cloudnetservice.driver.network.NetworkComponent, eu.cloudnetservice.driver.network.protocol.PacketSender, AutoCloseable

@Singleton public class NettyNetworkClient extends Object implements eu.cloudnetservice.driver.network.NetworkClient
The default implementation of a network client, using the netty network client implementations.
Since:
4.0
  • Field Details

    • CONNECTION_TIMEOUT_MILLIS

      private static final int CONNECTION_TIMEOUT_MILLIS
      See Also:
    • WATER_MARK

      private static final io.netty5.channel.WriteBufferWaterMark WATER_MARK
    • sslContext

      protected final io.netty5.handler.ssl.SslContext sslContext
    • eventLoopGroup

      protected final io.netty5.channel.EventLoopGroup eventLoopGroup
    • channels

      protected final Collection<eu.cloudnetservice.driver.network.NetworkChannel> channels
    • packetRegistry

      protected final eu.cloudnetservice.driver.network.protocol.PacketListenerRegistry packetRegistry
    • packetDispatcher

      protected final NetworkTaskScheduler packetDispatcher
    • handlerFactory

      protected final Callable<eu.cloudnetservice.driver.network.NetworkChannelHandler> handlerFactory
  • Constructor Details

    • NettyNetworkClient

      public NettyNetworkClient(@NonNull @NonNull eu.cloudnetservice.driver.ComponentInfo componentInfo, @NonNull @NonNull Callable<eu.cloudnetservice.driver.network.NetworkChannelHandler> handlerFactory)
      Constructs a new netty network client instance. Equivalent to new NettyNetworkClient(handlerFactory, null)
      Parameters:
      componentInfo - the component info of the current component the client is created for.
      handlerFactory - the factory for new handlers to be created with.
      Throws:
      NullPointerException - if the given event manager, component info or factory is null.
    • NettyNetworkClient

      public NettyNetworkClient(@NonNull @NonNull eu.cloudnetservice.driver.ComponentInfo componentInfo, @NonNull @NonNull Callable<eu.cloudnetservice.driver.network.NetworkChannelHandler> handlerFactory, @Nullable @Nullable eu.cloudnetservice.driver.network.ssl.SSLConfiguration sslConfiguration)
      Constructs a new netty network client instance.
      Parameters:
      componentInfo - the component info of the current component the client is created for.
      handlerFactory - the factory for new handler to be created with.
      sslConfiguration - the ssl configuration applying to this client, or null for no ssl configuration.
      Throws:
      NullPointerException - if the given event manager, component info or factory is null.
  • Method Details

    • initializeSslContext

      @Nullable private static @Nullable io.netty5.handler.ssl.SslContext initializeSslContext(@Nullable @Nullable eu.cloudnetservice.driver.network.ssl.SSLConfiguration sslConfig)
      Builds the ssl context for this client if a ssl configuration was supplied and is active.
      Parameters:
      sslConfig - the supplied ssl configuration to build the ssl context based on, can be null.
      Returns:
      the constructed ssl context based on the given configuration.
      Throws:
      IllegalStateException - if an error occurs during construction of the ssl context.
      IllegalArgumentException - if the trust certificate file does not contain any valid certificates.
    • sslEnabled

      public boolean sslEnabled()
      Specified by:
      sslEnabled in interface eu.cloudnetservice.driver.network.NetworkComponent
    • connect

      @NonNull public @NonNull CompletableFuture<Void> connect(@NonNull @NonNull eu.cloudnetservice.driver.network.HostAndPort hostAndPort)
      Specified by:
      connect in interface eu.cloudnetservice.driver.network.NetworkClient
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • channels

      @NonNull public @NonNull Collection<eu.cloudnetservice.driver.network.NetworkChannel> channels()
      Specified by:
      channels in interface eu.cloudnetservice.driver.network.NetworkComponent
    • packetDispatcher

      @NonNull public @NonNull Executor packetDispatcher()
      Specified by:
      packetDispatcher in interface eu.cloudnetservice.driver.network.NetworkComponent
    • packetRegistry

      @NonNull public @NonNull eu.cloudnetservice.driver.network.protocol.PacketListenerRegistry packetRegistry()
      Specified by:
      packetRegistry in interface eu.cloudnetservice.driver.network.NetworkComponent
    • sendPacket

      public void sendPacket(@NonNull @NonNull eu.cloudnetservice.driver.network.protocol.Packet packet)
      Specified by:
      sendPacket in interface eu.cloudnetservice.driver.network.protocol.PacketSender
    • sendPacketSync

      public void sendPacketSync(@NonNull @NonNull eu.cloudnetservice.driver.network.protocol.Packet packet)
      Specified by:
      sendPacketSync in interface eu.cloudnetservice.driver.network.protocol.PacketSender
    • closeChannels

      public void closeChannels()
      Specified by:
      closeChannels in interface eu.cloudnetservice.driver.network.NetworkComponent