public final class NettyUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
CLOSED_CHANNEL_ERROR_MESSAGE |
static io.netty.util.concurrent.SucceededFuture<?> |
SUCCEEDED_FUTURE
Completed succeed future.
|
| Modifier and Type | Method and Description |
|---|---|
static <SuccessT,PromiseT> |
asyncPromiseNotifyingBiConsumer(BiConsumer<SuccessT,io.netty.util.concurrent.Promise<PromiseT>> successConsumer,
io.netty.util.concurrent.Promise<PromiseT> promise)
Creates a
BiConsumer that notifies the promise of any failures either via the throwable passed into the BiConsumer
or as a result of running the successConsumer. |
static String |
closedChannelMessage(io.netty.channel.Channel channel) |
static <T> io.netty.util.concurrent.GenericFutureListener<io.netty.util.concurrent.Future<T>> |
consumeOrPropagate(io.netty.util.concurrent.Promise<?> destination,
Consumer<T> onSuccess)
Create a
GenericFutureListener that will propagate any failures or cancellations to the provided Promise,
or invoke the provided Consumer with the result of a successful operation completion. |
static Throwable |
decorateException(io.netty.channel.Channel channel,
Throwable originalCause) |
static io.netty.util.concurrent.Future<?> |
doInEventLoop(io.netty.util.concurrent.EventExecutor eventExecutor,
Runnable runnable)
Runs a task in the given
EventExecutor. |
static void |
doInEventLoop(io.netty.util.concurrent.EventExecutor eventExecutor,
Runnable runnable,
io.netty.util.concurrent.Promise<?> promise)
Runs a task in the given
EventExecutor. |
static <T> io.netty.util.AttributeKey<T> |
getOrCreateAttributeKey(String attr) |
static io.netty.handler.ssl.SslHandler |
newSslHandler(io.netty.handler.ssl.SslContext sslContext,
io.netty.buffer.ByteBufAllocator alloc,
String peerHost,
int peerPort,
Duration handshakeTimeout) |
static <SuccessT,PromiseT> |
promiseNotifyingBiConsumer(Function<SuccessT,PromiseT> successFunction,
io.netty.util.concurrent.Promise<PromiseT> promise)
Creates a
BiConsumer that notifies the promise of any failures either via the Throwable passed into the
BiConsumer of as a result of running the successFunction. |
static <T> io.netty.util.concurrent.GenericFutureListener<io.netty.util.concurrent.Future<T>> |
promiseNotifyingListener(io.netty.util.concurrent.Promise<T> channelPromise)
Create a
GenericFutureListener that will notify the provided Promise on success and failure. |
static void |
runAndLogError(NettyClientLogger log,
String errorMsg,
FunctionalUtils.UnsafeRunnable runnable) |
static <T> io.netty.util.concurrent.GenericFutureListener<io.netty.util.concurrent.Future<T>> |
runOrPropagate(io.netty.util.concurrent.Promise<?> destination,
Runnable onSuccess)
Create a
GenericFutureListener that will propagate any failures or cancellations to the provided Promise,
or invoke the provided Runnable upon successful operation completion. |
static void |
warnIfNotInEventLoop(io.netty.channel.EventLoop loop) |
public static final io.netty.util.concurrent.SucceededFuture<?> SUCCEEDED_FUTURE
public static final String CLOSED_CHANNEL_ERROR_MESSAGE
public static Throwable decorateException(io.netty.channel.Channel channel, Throwable originalCause)
public static String closedChannelMessage(io.netty.channel.Channel channel)
public static <SuccessT,PromiseT> BiConsumer<SuccessT,? super Throwable> promiseNotifyingBiConsumer(Function<SuccessT,PromiseT> successFunction, io.netty.util.concurrent.Promise<PromiseT> promise)
BiConsumer that notifies the promise of any failures either via the Throwable passed into the
BiConsumer of as a result of running the successFunction.SuccessT - Success type.PromiseT - Type being fulfilled by the promise.successFunction - Function called to process the successful result and map it into the result to notify the promise
with.promise - Promise to notify of success or failure.CompletableFuture.whenComplete(BiConsumer) method.public static <SuccessT,PromiseT> BiConsumer<SuccessT,? super Throwable> asyncPromiseNotifyingBiConsumer(BiConsumer<SuccessT,io.netty.util.concurrent.Promise<PromiseT>> successConsumer, io.netty.util.concurrent.Promise<PromiseT> promise)
BiConsumer that notifies the promise of any failures either via the throwable passed into the BiConsumer
or as a result of running the successConsumer. This assumes that the successConsumer will notify the promise when it
completes successfully.SuccessT - Success type.PromiseT - Type being fulfilled by the Promise.successConsumer - BiConsumer to call if the result is successful. Promise is also passed and must be notified on
success.promise - Promise to notify.CompletableFuture.whenComplete(BiConsumer) method.public static <T> io.netty.util.concurrent.GenericFutureListener<io.netty.util.concurrent.Future<T>> promiseNotifyingListener(io.netty.util.concurrent.Promise<T> channelPromise)
GenericFutureListener that will notify the provided Promise on success and failure.channelPromise - Promise to notify.public static io.netty.util.concurrent.Future<?> doInEventLoop(io.netty.util.concurrent.EventExecutor eventExecutor,
Runnable runnable)
EventExecutor. Runs immediately if the current thread is in the
eventExecutor.eventExecutor - Executor to run task in.runnable - Task to run.Future from from the executor.public static void doInEventLoop(io.netty.util.concurrent.EventExecutor eventExecutor,
Runnable runnable,
io.netty.util.concurrent.Promise<?> promise)
EventExecutor. Runs immediately if the current thread is in the
eventExecutor. Notifies the given Promise if a failure occurs.eventExecutor - Executor to run task in.runnable - Task to run.promise - Promise to notify if failure occurs.public static void warnIfNotInEventLoop(io.netty.channel.EventLoop loop)
public static <T> io.netty.util.AttributeKey<T> getOrCreateAttributeKey(String attr)
AttributeKey for attr. This returns an existing instance if it was previously created.public static io.netty.handler.ssl.SslHandler newSslHandler(io.netty.handler.ssl.SslContext sslContext,
io.netty.buffer.ByteBufAllocator alloc,
String peerHost,
int peerPort,
Duration handshakeTimeout)
SslHandler with ssl engine configuredpublic static <T> io.netty.util.concurrent.GenericFutureListener<io.netty.util.concurrent.Future<T>> consumeOrPropagate(io.netty.util.concurrent.Promise<?> destination,
Consumer<T> onSuccess)
GenericFutureListener that will propagate any failures or cancellations to the provided Promise,
or invoke the provided Consumer with the result of a successful operation completion. This is useful for chaining
together multiple futures that may depend upon each other but that may not have the same return type.
Note that if you do not need the value returned by a successful completion (or if it returns Void) you may use
runOrPropagate(Promise, Runnable) instead.
destination - the Promise to notify upon failure or cancellationonSuccess - the Consumer to invoke upon successpublic static <T> io.netty.util.concurrent.GenericFutureListener<io.netty.util.concurrent.Future<T>> runOrPropagate(io.netty.util.concurrent.Promise<?> destination,
Runnable onSuccess)
GenericFutureListener that will propagate any failures or cancellations to the provided Promise,
or invoke the provided Runnable upon successful operation completion. This is useful for chaining together multiple
futures that may depend upon each other but that may not have the same return type.destination - the Promise to notify upon failure or cancellationonSuccess - the Runnable to invoke upon successpublic static void runAndLogError(NettyClientLogger log, String errorMsg, FunctionalUtils.UnsafeRunnable runnable)
Copyright © 2023. All rights reserved.