Class NettyUtil
java.lang.Object
eu.cloudnetservice.driver.impl.network.netty.NettyUtil
Internal util for the default netty based communication between server and clients, http and websocket.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final Stringprivate static final intprivate static final io.netty5.buffer.BufferAllocatorprivate static final NettyTransportprivate static final io.netty5.handler.ssl.SslProvider -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull io.netty5.channel.ChannelFactory<? extends io.netty5.channel.Channel> Get the channel factory for client channels of the selected netty transport.static @NonNull io.netty5.channel.EventLoopGroupCreates a new boss event loop group based on the selected netty transport.private static @NonNull ThreadFactoryCreates a new thread factory for the netty event loop group but with daemon threads enabled.static @NonNull NetworkTaskSchedulercreatePacketDispatcher(@NonNull eu.cloudnetservice.driver.DriverEnvironment driverEnvironment) Creates a new executor for all incoming packets.static @NonNull io.netty5.channel.EventLoopGroupcreateWorkerEventLoopGroup(@NonNull eu.cloudnetservice.driver.DriverEnvironment driverEnvironment) Creates a new worker event loop group based on the selected netty transport.private static intoverriddenCountOrDefault(int overriddenSetting, int defaultValue) Returns the given overridden count if given (not zero or negative) or returns the given default value.static intreadVarInt(@NonNull io.netty5.buffer.Buffer buffer) Reads a var int from the given buffer.readVarIntOrNull(@NonNull io.netty5.buffer.Buffer buffer) Reads a var int from the given buffer, returns null if there is no Var Int at the current buffer position.static @NonNull io.netty5.buffer.BufferAllocatorGet the selected allocator for buffers that should be used for all buffer allocations.static @NonNull NettyTransportGet the selected netty transport which will be used for client/server channel and event loop group construction.static @NonNull io.netty5.handler.ssl.SslProviderGet the selected ssl provider which will be used in case ssl configurations are enabled on the client or server.static @NonNull io.netty5.channel.ServerChannelFactory<? extends io.netty5.channel.ServerChannel> Get the channel factory for server channels of the selected netty transport.static intvarIntBytes(int value) Gets the number of bytes that writing the given content length as a var int will take in the underlying buffer.static @NonNull io.netty5.buffer.BufferwriteVarInt(@NonNull io.netty5.buffer.Buffer buffer, int value) Writes the given integer value as a var int into the buffer.
-
Field Details
-
PACKET_DISPATCH_THREADS
private static final int PACKET_DISPATCH_THREADS -
NETTY_EVENT_LOOP_THREADS
private static final int NETTY_EVENT_LOOP_THREADS -
SELECTED_SSL_PROVIDER
private static final io.netty5.handler.ssl.SslProvider SELECTED_SSL_PROVIDER -
SELECTED_NETTY_TRANSPORT
-
SELECTED_BUFFER_ALLOCATOR
private static final io.netty5.buffer.BufferAllocator SELECTED_BUFFER_ALLOCATOR -
NETTY_MEMORY_MANAGER_SYS_PROP_NAME
- See Also:
-
-
Constructor Details
-
NettyUtil
private NettyUtil()
-
-
Method Details
-
overriddenCountOrDefault
private static int overriddenCountOrDefault(int overriddenSetting, int defaultValue) Returns the given overridden count if given (not zero or negative) or returns the given default value.- Parameters:
overriddenSetting- the overridden setting, for example from a user input.defaultValue- the default value to use as a fallback, if the overridden value is not valid.- Returns:
- the given overridden setting if valid, the given default value in all other cases.
-
createPacketDispatcher
@NonNull public static @NonNull NetworkTaskScheduler createPacketDispatcher(@NonNull @NonNull eu.cloudnetservice.driver.DriverEnvironment driverEnvironment) Creates a new executor for all incoming packets. The thread size of the returned dispatcher depends either on a user-provided setting or on the given driver environment.- Parameters:
driverEnvironment- the driver environment currently running on.- Returns:
- a newly created executor for dispatching inbound packets.
- Throws:
NullPointerException- if the given driver environment is null.
-
createBossEventLoopGroup
Creates a new boss event loop group based on the selected netty transport. Boss event loops are used to accept new connections, which only requires a single thread.- Returns:
- a newly created boss event loop group.
-
createWorkerEventLoopGroup
@NonNull public static @NonNull io.netty5.channel.EventLoopGroup createWorkerEventLoopGroup(@NonNull @NonNull eu.cloudnetservice.driver.DriverEnvironment driverEnvironment) Creates a new worker event loop group based on the selected netty transport. The thread count that is used by the event loop is either set by the user or depends on the given driver environment.- Parameters:
driverEnvironment- the driver environment currently running on.- Returns:
- a newly created worker event loop group.
- Throws:
NullPointerException- if the given driver environment is null.
-
clientChannelFactory
-
serverChannelFactory
-
writeVarInt
@NonNull public static @NonNull io.netty5.buffer.Buffer writeVarInt(@NonNull @NonNull io.netty5.buffer.Buffer buffer, int value) Writes the given integer value as a var int into the buffer.- Parameters:
buffer- the buffer to write to.value- the value to write into the buffer.- Returns:
- the buffer used to call the method, for chaining.
- Throws:
NullPointerException- if the given byte buf is null.
-
readVarInt
Reads a var int from the given buffer.- Parameters:
buffer- the buffer to read from.- Returns:
- the var int read from the buffer.
- Throws:
io.netty5.handler.codec.DecoderException- if the buf current position has no var int.NullPointerException- if the given buffer to read from is null.
-
readVarIntOrNull
@Nullable public static @Nullable Integer readVarIntOrNull(@NonNull @NonNull io.netty5.buffer.Buffer buffer) Reads a var int from the given buffer, returns null if there is no Var Int at the current buffer position.- Parameters:
buffer- the buffer to read from.- Returns:
- the var int read from the buffer, or null if no var int is at the given position.
- Throws:
NullPointerException- if the given buffer to read from is null.
-
varIntBytes
public static int varIntBytes(int value) Gets the number of bytes that writing the given content length as a var int will take in the underlying buffer.- Parameters:
value- the number to get the amount of bytes for.- Returns:
- the number of bytes writing the given number as a var int will take.
-
selectedNettyTransport
Get the selected netty transport which will be used for client/server channel and event loop group construction.- Returns:
- the selected netty transport.
-
selectedSslProvider
-
selectedBufferAllocator
-
createEventLoopThreadFactory
Creates a new thread factory for the netty event loop group but with daemon threads enabled.- Returns:
- the newly constructed thread factory for event loops.
-