Class NettyNetworkChannel
java.lang.Object
eu.cloudnetservice.driver.network.DefaultNetworkChannel
eu.cloudnetservice.driver.network.netty.NettyNetworkChannel
- All Implemented Interfaces:
NetworkChannel,PacketSender
@Internal
public final class NettyNetworkChannel
extends DefaultNetworkChannel
implements NetworkChannel
The default netty based implementation of a network channel.
- Since:
- 4.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionNettyNetworkChannel(@NonNull io.netty5.channel.Channel channel, @NonNull PacketListenerRegistry packetRegistry, @NonNull NetworkChannelHandler handler, @NonNull HostAndPort serverAddress, @NonNull HostAndPort clientAddress, boolean clientProvidedChannel) Constructs a new netty network channel instance. -
Method Summary
Modifier and TypeMethodDescriptionbooleanactive()Get if the underlying channel is still active and therefore connected.voidclose()Requests the close of the channel, flushing all outbound i/o requests before.voidsendPacket(@NonNull Packet packet) Sends the given packet to the associated target.voidsendPacket(@NonNull Packet... packets) Sends all the given packets to the associated target.voidsendPacketSync(@NonNull Packet packet) Sends the given packet to the associated target, waiting for the packet write to the channel to complete before resuming the current thread.booleanGet if the underlying channel is currently writeable and will perform writes to the channel immediately.Methods inherited from class eu.cloudnetservice.driver.network.DefaultNetworkChannel
channelId, clientAddress, clientProvidedChannel, handler, packetRegistry, queryPacketManager, sendQueryAsync, serverAddressMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.network.NetworkChannel
channelId, clientAddress, clientProvidedChannel, handler, packetRegistry, queryPacketManager, sendQueryAsync, serverAddress
-
Field Details
-
channel
private final io.netty5.channel.Channel channel
-
-
Constructor Details
-
NettyNetworkChannel
public NettyNetworkChannel(@NonNull @NonNull io.netty5.channel.Channel channel, @NonNull @NonNull PacketListenerRegistry packetRegistry, @NonNull @NonNull NetworkChannelHandler handler, @NonNull @NonNull HostAndPort serverAddress, @NonNull @NonNull HostAndPort clientAddress, boolean clientProvidedChannel) Constructs a new netty network channel instance.- Parameters:
channel- the netty channel to wrap.packetRegistry- the packet registry for this channel.handler- the handler to post events to.serverAddress- the server address to which the client connected.clientAddress- the client address which is assigned to the connection.clientProvidedChannel- true if the channel is handled by a server, false otherwise.- Throws:
NullPointerException- if one of the required constructor paramters is null.
-
-
Method Details
-
sendPacket
Sends all the given packets to the associated target.- Specified by:
sendPacketin interfacePacketSender- Parameters:
packets- the packets to send.
-
sendPacket
Sends the given packet to the associated target.- Specified by:
sendPacketin interfacePacketSender- Parameters:
packet- the packet to send.
-
sendPacketSync
Sends the given packet to the associated target, waiting for the packet write to the channel to complete before resuming the current thread.- Specified by:
sendPacketSyncin interfacePacketSender- Parameters:
packet- the packet to send.
-
writeable
public boolean writeable()Get if the underlying channel is currently writeable and will perform writes to the channel immediately.- Specified by:
writeablein interfaceNetworkChannel- Returns:
- true if the channel can instantly process i/o requests, false otherwise.
-
active
public boolean active()Get if the underlying channel is still active and therefore connected.- Specified by:
activein interfaceNetworkChannel- Returns:
- true if the channel is connected and active, false otherwise.
-
close
public void close()Requests the close of the channel, flushing all outbound i/o requests before. After a channel was closed it cannot be used again.- Specified by:
closein interfaceNetworkChannel
-