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
FieldsModifier and TypeFieldDescriptionprivate final io.netty5.channel.Channelprivate final EventManager -
Constructor Summary
ConstructorsConstructorDescriptionNettyNetworkChannel(@NonNull io.netty5.channel.Channel channel, @NonNull EventManager eventManager, @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.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 the underlying channel is currently writeable and will perform writes to the channel immediately.writePacket(@NonNull Packet packet, boolean flushAfter) Writes the given packet into the channel, calling the packet send event beforehand and not writing when the event gets cancelled by a module/plugin.Methods inherited from class eu.cloudnetservice.driver.network.DefaultNetworkChannel
channelId, clientAddress, clientProvidedChannel, handler, packetRegistry, queryPacketManager, sendQuery, 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, sendQuery, sendQueryAsync, serverAddress
-
Field Details
-
channel
private final io.netty5.channel.Channel channel -
eventManager
-
-
Constructor Details
-
NettyNetworkChannel
public NettyNetworkChannel(@NonNull @NonNull io.netty5.channel.Channel channel, @NonNull @NonNull EventManager eventManager, @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.eventManager- the event manager for the current component.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.
-
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.
-
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
-
writePacket
@Nullable private @Nullable io.netty5.util.concurrent.Future<Void> writePacket(@NonNull @NonNull Packet packet, boolean flushAfter) Writes the given packet into the channel, calling the packet send event beforehand and not writing when the event gets cancelled by a module/plugin.- Parameters:
packet- the packet to write if the send operation is not cancelled.flushAfter- if the send queue should be flushed directly after the write process.- Returns:
- the future completed once the write operation (and flush) of the channel succeeded, null if cancelled.
- Throws:
NullPointerException- if the given packet is null.
-