Class NettyNetworkClient

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

@Singleton public class NettyNetworkClient extends Object implements DefaultNetworkComponent, 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
    • eventLoopGroup

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

      protected final Collection<NetworkChannel> channels
    • packetRegistry

      protected final PacketListenerRegistry packetRegistry
    • eventManager

      protected final EventManager eventManager
    • packetDispatcher

      protected final Executor packetDispatcher
    • sslConfiguration

      protected final SSLConfiguration sslConfiguration
    • handlerFactory

      protected final Callable<NetworkChannelHandler> handlerFactory
    • sslContext

      protected io.netty5.handler.ssl.SslContext sslContext
  • Constructor Details

  • Method Details

    • sslEnabled

      public boolean sslEnabled()
      Get if this component has ssl enabled.
      Specified by:
      sslEnabled in interface NetworkComponent
      Returns:
      true if this component has ssl enabled, false otherwise.
    • connect

      @NonNull public @NonNull eu.cloudnetservice.common.concurrent.Task<Void> connect(@NonNull @NonNull HostAndPort hostAndPort)
      Connects this network client to the network server running at the given host and port.
      Specified by:
      connect in interface NetworkClient
      Parameters:
      hostAndPort - the target host and port to which the client should get connected.
      Returns:
      a task completed successfully, or with the exception thrown during the connection process.
    • close

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

      Get an immutable collection of all channels which are associated with this component.
      Specified by:
      channels in interface NetworkComponent
      Returns:
      an immutable collection of all channels which are associated with this component.
    • packetDispatcher

      @NonNull public @NonNull Executor packetDispatcher()
      Get the dispatching executor for received packets in any channel which is bound to this network component.
      Specified by:
      packetDispatcher in interface NetworkComponent
      Returns:
      the dispatching executor for received packets.
    • modifiableChannels

      @NonNull public @NonNull Collection<NetworkChannel> modifiableChannels()
      Get the collection of channels which are connected to this network component. The returned collection is modifiable, but should not be used by developers to make any changes to it. If you need all channels which are connected to the component use NetworkComponent.channels() instead.
      Specified by:
      modifiableChannels in interface DefaultNetworkComponent
      Returns:
      all channels which are connected to this component, modifiable.
    • packetRegistry

      @NonNull public @NonNull PacketListenerRegistry packetRegistry()
      Get the packet listener registry which will be the root registry for all channels initialized by this component.
      Specified by:
      packetRegistry in interface NetworkComponent
      Returns:
      the root packet registry for all associated channels.
    • init

      private void init() throws Exception
      Builds the ssl context for this client if a ssl configuration was supplied and is active. If no certificates are set in the given ssl configuration, the client will self-sign a certificate.
      Throws:
      Exception - if any exception occurs during the creation of the ssl context.