Class NettyNetworkServer
java.lang.Object
eu.cloudnetservice.driver.network.netty.NettySslServer
eu.cloudnetservice.driver.network.netty.server.NettyNetworkServer
- All Implemented Interfaces:
DefaultNetworkComponent,NetworkComponent,NetworkServer,PacketSender,AutoCloseable
@Singleton
public class NettyNetworkServer
extends NettySslServer
implements DefaultNetworkComponent, 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<HostAndPort,io.netty5.util.concurrent.Future<Void>> protected final Collection<NetworkChannel>protected final EventManagerprotected final Callable<NetworkChannelHandler>protected final Executorprotected final PacketListenerRegistryprotected static final io.netty5.channel.WriteBufferWaterMarkprotected final io.netty5.channel.EventLoopGroupFields inherited from class eu.cloudnetservice.driver.network.netty.NettySslServer
sslConfiguration, sslContextFields inherited from interface eu.cloudnetservice.driver.network.DefaultNetworkComponent
LOGGER -
Constructor Summary
ConstructorsConstructorDescriptionNettyNetworkServer(@NonNull EventManager eventManager, @NonNull ComponentInfo componentInfo, @NonNull Callable<NetworkChannelHandler> handlerFactory) Constructs a new netty network server instance.NettyNetworkServer(@NonNull EventManager eventManager, @NonNull ComponentInfo componentInfo, @NonNull Callable<NetworkChannelHandler> handlerFactory, @Nullable SSLConfiguration sslConfiguration) Constructs a new netty network server instance. -
Method Summary
Modifier and TypeMethodDescriptionaddListener(int port) Binds this network server to the given port on any local address (ipv6 form:::/0) if no other listener is already listening to that port.addListener(@NonNull HostAndPort hostAndPort) Binds this network server to the given host and port if no listener is already listening on the given address.channels()Get an immutable collection of all channels which are associated with this component.voidclose()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.voidsendPacketSync(@NonNull Packet... packets) Sends all the given packets to the associated target, waiting for the packet writes to the channel to complete before resuming the current thread.booleanGet if this component has ssl enabled.Methods inherited from class eu.cloudnetservice.driver.network.netty.NettySslServer
initMethods 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
firstChannel
-
Field Details
-
WATER_MARK
protected static final io.netty5.channel.WriteBufferWaterMark WATER_MARK -
bossEventLoopGroup
protected final io.netty5.channel.EventLoopGroup bossEventLoopGroup -
workerEventLoopGroup
protected final io.netty5.channel.EventLoopGroup workerEventLoopGroup -
channels
-
channelFutures
-
packetRegistry
-
eventManager
-
packetDispatcher
-
handlerFactory
-
-
Constructor Details
-
NettyNetworkServer
public NettyNetworkServer(@NonNull @NonNull EventManager eventManager, @NonNull @NonNull ComponentInfo componentInfo, @NonNull @NonNull Callable<NetworkChannelHandler> handlerFactory) Constructs a new netty network server instance. Equivalent tonew NettyNetworkServer(factory, null).- Parameters:
eventManager- the event manager of the current component.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 EventManager eventManager, @NonNull @NonNull ComponentInfo componentInfo, @NonNull @NonNull Callable<NetworkChannelHandler> handlerFactory, @Nullable @Nullable SSLConfiguration sslConfiguration) Constructs a new netty network server instance.- Parameters:
eventManager- the event manager of the current component.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
-
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.
-
addListener
Binds this network server to the given port on any local address (ipv6 form:::/0) if no other listener is already listening to that port.- Specified by:
addListenerin interfaceNetworkServer- Parameters:
port- the port to which the listener should get bound.- Returns:
- a future completed exceptionally if the bind fails, normally if the bind succeeded.
-
addListener
@NonNull public @NonNull eu.cloudnetservice.common.concurrent.Task<Void> addListener(@NonNull @NonNull HostAndPort hostAndPort) Binds this network server to the given host and port if no listener is already listening on the given address.- Specified by:
addListenerin interfaceNetworkServer- Parameters:
hostAndPort- the address to which a listener should get bound.- Returns:
- a future completed exceptionally if the bind fails, normally if the bind succeeded.
-
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.
-
sendPacketSync
Sends all the given packets to the associated target, waiting for the packet writes to the channel to complete before resuming the current thread.- Specified by:
sendPacketSyncin interfacePacketSender- Parameters:
packets- the packets to send.
-
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.
-