Class NettyNetworkServer
- java.lang.Object
-
- de.dytanic.cloudnet.driver.network.netty.NettyNetworkServer
-
- All Implemented Interfaces:
INetworkServer,IPacketSender,java.lang.AutoCloseable
public final class NettyNetworkServer extends java.lang.Object implements INetworkServer
-
-
Field Summary
Fields Modifier and Type Field Description protected io.netty.channel.EventLoopGroupbossEventLoopGroupprotected java.util.Map<java.lang.Integer,de.dytanic.cloudnet.common.collection.Pair<HostAndPort,io.netty.channel.ChannelFuture>>channelFuturesprotected java.util.Collection<INetworkChannel>channelsprotected java.util.concurrent.Callable<INetworkChannelHandler>networkChannelHandlerprotected IPacketListenerRegistrypacketRegistryprotected SSLConfigurationsslConfigurationprotected io.netty.handler.ssl.SslContextsslContextprotected de.dytanic.cloudnet.common.concurrent.ITaskSchedulertaskSchedulerprotected booleantaskSchedulerFromConstructorprotected io.netty.channel.EventLoopGroupworkerEventLoopGroup
-
Constructor Summary
Constructors Constructor Description NettyNetworkServer(java.util.concurrent.Callable<INetworkChannelHandler> networkChannelHandler)NettyNetworkServer(java.util.concurrent.Callable<INetworkChannelHandler> networkChannelHandler, de.dytanic.cloudnet.common.concurrent.ITaskScheduler taskScheduler)NettyNetworkServer(java.util.concurrent.Callable<INetworkChannelHandler> networkChannelHandler, SSLConfiguration sslConfiguration, de.dytanic.cloudnet.common.concurrent.ITaskScheduler taskScheduler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddListener(int port)Binds the server to a specific port with the host alias address "0.0.0.0"booleanaddListener(@NotNull HostAndPort hostAndPort)Binds the server to a specific address that is as parameter definedvoidclose()voidcloseChannels()java.util.Collection<INetworkChannel>getChannels()IPacketListenerRegistrygetPacketRegistry()protected voidinit()booleanisSslEnabled()voidsendPacket(@NotNull IPacket packet)Transport a packet instance into the network to the receiver.voidsendPacket(@NotNull IPacket... packets)Transport packet instances into the network to the receiver.
-
-
-
Field Detail
-
channelFutures
protected final java.util.Map<java.lang.Integer,de.dytanic.cloudnet.common.collection.Pair<HostAndPort,io.netty.channel.ChannelFuture>> channelFutures
-
channels
protected final java.util.Collection<INetworkChannel> channels
-
packetRegistry
protected final IPacketListenerRegistry packetRegistry
-
bossEventLoopGroup
protected final io.netty.channel.EventLoopGroup bossEventLoopGroup
-
workerEventLoopGroup
protected final io.netty.channel.EventLoopGroup workerEventLoopGroup
-
taskScheduler
protected final de.dytanic.cloudnet.common.concurrent.ITaskScheduler taskScheduler
-
taskSchedulerFromConstructor
protected final boolean taskSchedulerFromConstructor
-
networkChannelHandler
protected final java.util.concurrent.Callable<INetworkChannelHandler> networkChannelHandler
-
sslConfiguration
protected final SSLConfiguration sslConfiguration
-
sslContext
protected io.netty.handler.ssl.SslContext sslContext
-
-
Constructor Detail
-
NettyNetworkServer
public NettyNetworkServer(java.util.concurrent.Callable<INetworkChannelHandler> networkChannelHandler)
-
NettyNetworkServer
public NettyNetworkServer(java.util.concurrent.Callable<INetworkChannelHandler> networkChannelHandler, de.dytanic.cloudnet.common.concurrent.ITaskScheduler taskScheduler)
-
NettyNetworkServer
public NettyNetworkServer(java.util.concurrent.Callable<INetworkChannelHandler> networkChannelHandler, SSLConfiguration sslConfiguration, de.dytanic.cloudnet.common.concurrent.ITaskScheduler taskScheduler)
-
-
Method Detail
-
isSslEnabled
public boolean isSslEnabled()
-
addListener
public boolean addListener(int port)
Description copied from interface:INetworkServerBinds the server to a specific port with the host alias address "0.0.0.0"- Specified by:
addListenerin interfaceINetworkServer- Parameters:
port- the port, that the server should bind- Returns:
- true when the binding was successful or false if an error was threw or the port is already bind
-
addListener
public boolean addListener(@NotNull @NotNull HostAndPort hostAndPort)Description copied from interface:INetworkServerBinds the server to a specific address that is as parameter defined- Specified by:
addListenerin interfaceINetworkServer- Parameters:
hostAndPort- the address that should the server bind- Returns:
- true when the binding was successful or false if an error was threw or the port is already bind
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
getChannels
public java.util.Collection<INetworkChannel> getChannels()
-
closeChannels
public void closeChannels()
-
sendPacket
public void sendPacket(@NotNull @NotNull IPacket packet)Description copied from interface:IPacketSenderTransport a packet instance into the network to the receiver. The receiver will handle the packet if he knows the channel and has listeners for the channelThe packet are doesn't allow to be null
- Specified by:
sendPacketin interfaceIPacketSender- Parameters:
packet- the packet, which should transport into the network
-
sendPacket
public void sendPacket(@NotNull @NotNull IPacket... packets)Description copied from interface:IPacketSenderTransport packet instances into the network to the receiver. The receiver will handle the packets if he knows the channel and has listeners for the channelA packet are doesn't allow to be null All elements should be checked that be not null and send after that
- Specified by:
sendPacketin interfaceIPacketSender- Parameters:
packets- the packets, which should transport into the network
-
getPacketRegistry
public IPacketListenerRegistry getPacketRegistry()
-
init
protected void init() throws java.lang.Exception- Throws:
java.lang.Exception
-
-