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 Summary
FieldsModifier and TypeFieldDescriptionprotected final Collection<NetworkChannel>private static final intprotected final io.netty5.channel.EventLoopGroupprotected final EventManagerprotected final Callable<NetworkChannelHandler>protected final Executorprotected final PacketListenerRegistryprotected final SSLConfigurationprotected io.netty5.handler.ssl.SslContextprivate static final io.netty5.channel.WriteBufferWaterMarkFields inherited from interface eu.cloudnetservice.driver.network.DefaultNetworkComponent
LOGGER -
Constructor Summary
ConstructorsConstructorDescriptionNettyNetworkClient(@NonNull EventManager eventManager, @NonNull ComponentInfo componentInfo, @NonNull Callable<NetworkChannelHandler> handlerFactory) Constructs a new netty network client instance.NettyNetworkClient(@NonNull EventManager eventManager, @NonNull ComponentInfo componentInfo, @NonNull Callable<NetworkChannelHandler> handlerFactory, @Nullable SSLConfiguration sslConfiguration) Constructs a new netty network client instance. -
Method Summary
Modifier and TypeMethodDescriptionchannels()Get an immutable collection of all channels which are associated with this component.voidclose()connect(@NonNull HostAndPort hostAndPort) Connects this network client to the network server running at the given host and port.private voidinit()Builds the ssl context for this client if a ssl configuration was supplied and is active.Get the collection of channels which are connected to this network component.Get the dispatching executor for received packets in any channel which is bound to this network component.Get the packet listener registry which will be the root registry for all channels initialized by this component.booleanGet if this component has ssl enabled.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.network.DefaultNetworkComponent
closeChannels, sendPacket, sendPacket, sendPacketSyncMethods inherited from interface eu.cloudnetservice.driver.network.NetworkComponent
firstChannelMethods inherited from interface eu.cloudnetservice.driver.network.protocol.PacketSender
sendPacketSync
-
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
-
packetRegistry
-
eventManager
-
packetDispatcher
-
sslConfiguration
-
handlerFactory
-
sslContext
protected io.netty5.handler.ssl.SslContext sslContext
-
-
Constructor Details
-
NettyNetworkClient
public NettyNetworkClient(@NonNull @NonNull EventManager eventManager, @NonNull @NonNull ComponentInfo componentInfo, @NonNull @NonNull Callable<NetworkChannelHandler> handlerFactory) Constructs a new netty network client instance. Equivalent tonew NettyNetworkClient(handlerFactory, null)- Parameters:
eventManager- the event manager of the current component.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 EventManager eventManager, @NonNull @NonNull ComponentInfo componentInfo, @NonNull @NonNull Callable<NetworkChannelHandler> handlerFactory, @Nullable @Nullable SSLConfiguration sslConfiguration) Constructs a new netty network client instance.- Parameters:
eventManager- the event manager of the current component.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
-
sslEnabled
public boolean sslEnabled()Get if this component has ssl enabled.- Specified by:
sslEnabledin interfaceNetworkComponent- 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:
connectin interfaceNetworkClient- 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:
closein interfaceAutoCloseable
-
channels
Get an immutable collection of all channels which are associated with this component.- Specified by:
channelsin interfaceNetworkComponent- Returns:
- an immutable collection of all channels which are associated with this component.
-
packetDispatcher
Get the dispatching executor for received packets in any channel which is bound to this network component.- Specified by:
packetDispatcherin interfaceNetworkComponent- Returns:
- the dispatching executor for received packets.
-
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 useNetworkComponent.channels()instead.- Specified by:
modifiableChannelsin interfaceDefaultNetworkComponent- Returns:
- all channels which are connected to this component, modifiable.
-
packetRegistry
Get the packet listener registry which will be the root registry for all channels initialized by this component.- Specified by:
packetRegistryin interfaceNetworkComponent- Returns:
- the root packet registry for all associated channels.
-
init
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.
-