Class NettyNetworkServer
java.lang.Object
eu.cloudnetservice.driver.impl.network.netty.server.NettyNetworkServer
- All Implemented Interfaces:
eu.cloudnetservice.driver.network.NetworkComponent, eu.cloudnetservice.driver.network.NetworkServer, eu.cloudnetservice.driver.network.protocol.PacketSender, AutoCloseable
@Singleton
public class NettyNetworkServer
extends Object
implements eu.cloudnetservice.driver.network.NetworkServer
The default netty based implementation of the network server.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.netty5.channel.EventLoopGroupprotected final Map<eu.cloudnetservice.driver.network.HostAndPort, io.netty5.util.concurrent.Future<Void>> protected final Collection<eu.cloudnetservice.driver.network.NetworkChannel> protected final Callable<eu.cloudnetservice.driver.network.NetworkChannelHandler> protected final NetworkTaskSchedulerprotected final eu.cloudnetservice.driver.network.protocol.PacketListenerRegistryprotected final io.netty5.handler.ssl.SslContextprotected static final io.netty5.channel.WriteBufferWaterMarkprotected final io.netty5.channel.EventLoopGroup -
Constructor Summary
ConstructorsConstructorDescriptionNettyNetworkServer(@NonNull eu.cloudnetservice.driver.ComponentInfo componentInfo, @NonNull Callable<eu.cloudnetservice.driver.network.NetworkChannelHandler> handlerFactory) Constructs a new netty network server instance.NettyNetworkServer(@NonNull eu.cloudnetservice.driver.ComponentInfo componentInfo, @NonNull Callable<eu.cloudnetservice.driver.network.NetworkChannelHandler> handlerFactory, @Nullable eu.cloudnetservice.driver.network.ssl.SSLConfiguration sslConfiguration) Constructs a new netty network server instance. -
Method Summary
Modifier and TypeMethodDescriptionaddListener(int port) addListener(@NonNull eu.cloudnetservice.driver.network.HostAndPort hostAndPort) @NonNull Collection<eu.cloudnetservice.driver.network.NetworkChannel> channels()voidclose()voidprivate static @Nullable io.netty5.handler.ssl.SslContextinitializeSslContext(@Nullable eu.cloudnetservice.driver.network.ssl.SSLConfiguration sslConfig) Builds the ssl context for this server if a ssl configuration was supplied and is active.@NonNull eu.cloudnetservice.driver.network.protocol.PacketListenerRegistryvoidsendPacket(@NonNull eu.cloudnetservice.driver.network.protocol.Packet packet) voidsendPacketSync(@NonNull eu.cloudnetservice.driver.network.protocol.Packet packet) booleanMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.network.NetworkComponent
firstChannelMethods inherited from interface eu.cloudnetservice.driver.network.protocol.PacketSender
sendPacket
-
Field Details
-
WATER_MARK
protected static final io.netty5.channel.WriteBufferWaterMark WATER_MARK -
sslContext
protected final io.netty5.handler.ssl.SslContext sslContext -
bossEventLoopGroup
protected final io.netty5.channel.EventLoopGroup bossEventLoopGroup -
workerEventLoopGroup
protected final io.netty5.channel.EventLoopGroup workerEventLoopGroup -
channels
-
channelFutures
-
packetRegistry
protected final eu.cloudnetservice.driver.network.protocol.PacketListenerRegistry packetRegistry -
packetDispatcher
-
handlerFactory
-
-
Constructor Details
-
NettyNetworkServer
public NettyNetworkServer(@NonNull @NonNull eu.cloudnetservice.driver.ComponentInfo componentInfo, @NonNull @NonNull Callable<eu.cloudnetservice.driver.network.NetworkChannelHandler> handlerFactory) Constructs a new netty network server instance. Equivalent tonew NettyNetworkServer(factory, null).- Parameters:
componentInfo- the component info of the current component the server is created for.handlerFactory- the handler factory to use.- Throws:
NullPointerException- if the given event manager, component info or factory is null.
-
NettyNetworkServer
public NettyNetworkServer(@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 server instance.- Parameters:
componentInfo- the component info of the current component the server is created for.handlerFactory- the handler factory to use.sslConfiguration- the ssl configuration to apply, or null if ssl should be disabled.- 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 server 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 chain or private key file is invalid.
-
sslEnabled
public boolean sslEnabled()- Specified by:
sslEnabledin interfaceeu.cloudnetservice.driver.network.NetworkComponent
-
addListener
- Specified by:
addListenerin interfaceeu.cloudnetservice.driver.network.NetworkServer
-
addListener
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
channels
- Specified by:
channelsin interfaceeu.cloudnetservice.driver.network.NetworkComponent
-
packetDispatcher
-
packetRegistry
-
sendPacket
-
sendPacketSync
-
closeChannels
public void closeChannels()- Specified by:
closeChannelsin interfaceeu.cloudnetservice.driver.network.NetworkComponent
-