Class NettyNetworkClient
- java.lang.Object
-
- de.dytanic.cloudnet.driver.network.netty.NettyNetworkClient
-
- All Implemented Interfaces:
INetworkClient,IPacketSender,java.lang.AutoCloseable
public final class NettyNetworkClient extends java.lang.Object implements INetworkClient
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Collection<INetworkChannel>channelsprotected longconnectedTimeprotected io.netty.channel.EventLoopGroupeventLoopGroupprotected java.util.concurrent.Callable<INetworkChannelHandler>networkChannelHandlerprotected IPacketListenerRegistrypacketRegistryprotected SSLConfigurationsslConfigurationprotected io.netty.handler.ssl.SslContextsslContextprotected de.dytanic.cloudnet.common.concurrent.ITaskSchedulertaskSchedulerprotected booleantaskSchedulerFromConstructor
-
Constructor Summary
Constructors Constructor Description NettyNetworkClient(java.util.concurrent.Callable<INetworkChannelHandler> networkChannelHandler)NettyNetworkClient(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 voidclose()voidcloseChannels()booleanconnect(@NotNull HostAndPort hostAndPort)Open a new connection to the specific host and portjava.util.Collection<INetworkChannel>getChannels()longgetConnectedTime()Gets the time when this client was connected to the server in millisecondsIPacketListenerRegistrygetPacketRegistry()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
-
channels
protected final java.util.Collection<INetworkChannel> channels
-
packetRegistry
protected final IPacketListenerRegistry packetRegistry
-
eventLoopGroup
protected final io.netty.channel.EventLoopGroup eventLoopGroup
-
networkChannelHandler
protected final java.util.concurrent.Callable<INetworkChannelHandler> networkChannelHandler
-
taskScheduler
protected final de.dytanic.cloudnet.common.concurrent.ITaskScheduler taskScheduler
-
taskSchedulerFromConstructor
protected final boolean taskSchedulerFromConstructor
-
sslConfiguration
protected final SSLConfiguration sslConfiguration
-
sslContext
protected io.netty.handler.ssl.SslContext sslContext
-
connectedTime
protected long connectedTime
-
-
Constructor Detail
-
NettyNetworkClient
public NettyNetworkClient(java.util.concurrent.Callable<INetworkChannelHandler> networkChannelHandler)
-
NettyNetworkClient
public NettyNetworkClient(java.util.concurrent.Callable<INetworkChannelHandler> networkChannelHandler, SSLConfiguration sslConfiguration, de.dytanic.cloudnet.common.concurrent.ITaskScheduler taskScheduler)
-
-
Method Detail
-
isSslEnabled
public boolean isSslEnabled()
-
connect
public boolean connect(@NotNull @NotNull HostAndPort hostAndPort)Description copied from interface:INetworkClientOpen a new connection to the specific host and port- Specified by:
connectin interfaceINetworkClient- Parameters:
hostAndPort- the address, that should the client connect to- Returns:
- true if the connection was success or false if the connection was unsuccessful or refused
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
getChannels
public java.util.Collection<INetworkChannel> getChannels()
-
closeChannels
public void closeChannels()
-
getConnectedTime
public long getConnectedTime()
Description copied from interface:INetworkClientGets the time when this client was connected to the server in milliseconds- Specified by:
getConnectedTimein interfaceINetworkClient
-
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()
-
-