Class NettyUtils
- java.lang.Object
-
- software.amazon.awssdk.http.nio.netty.internal.utils.NettyUtils
-
public final class NettyUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static String
CLOSED_CHANNEL_ERROR_MESSAGE
static io.netty.util.concurrent.SucceededFuture<?>
SUCCEEDED_FUTURE
Completed succeed future.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <SuccessT,PromiseT>
BiConsumer<SuccessT,? super Throwable>asyncPromiseNotifyingBiConsumer(BiConsumer<SuccessT,io.netty.util.concurrent.Promise<PromiseT>> successConsumer, io.netty.util.concurrent.Promise<PromiseT> promise)
Creates aBiConsumer
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 aGenericFutureListener
that will propagate any failures or cancellations to the providedPromise
, or invoke the providedConsumer
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 givenEventExecutor
.static void
doInEventLoop(io.netty.util.concurrent.EventExecutor eventExecutor, Runnable runnable, io.netty.util.concurrent.Promise<?> promise)
Runs a task in the givenEventExecutor
.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>
BiConsumer<SuccessT,? super Throwable>promiseNotifyingBiConsumer(Function<SuccessT,PromiseT> successFunction, io.netty.util.concurrent.Promise<PromiseT> promise)
Creates aBiConsumer
that notifies the promise of any failures either via theThrowable
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 aGenericFutureListener
that will notify the providedPromise
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 aGenericFutureListener
that will propagate any failures or cancellations to the providedPromise
, or invoke the providedRunnable
upon successful operation completion.static void
warnIfNotInEventLoop(io.netty.channel.EventLoop loop)
-
-
-
Field Detail
-
SUCCEEDED_FUTURE
public static final io.netty.util.concurrent.SucceededFuture<?> SUCCEEDED_FUTURE
Completed succeed future.
-
CLOSED_CHANNEL_ERROR_MESSAGE
public static final String CLOSED_CHANNEL_ERROR_MESSAGE
- See Also:
- Constant Field Values
-
-
Method Detail
-
decorateException
public static Throwable decorateException(io.netty.channel.Channel channel, Throwable originalCause)
-
closedChannelMessage
public static String closedChannelMessage(io.netty.channel.Channel channel)
-
promiseNotifyingBiConsumer
public static <SuccessT,PromiseT> BiConsumer<SuccessT,? super Throwable> promiseNotifyingBiConsumer(Function<SuccessT,PromiseT> successFunction, io.netty.util.concurrent.Promise<PromiseT> promise)
Creates aBiConsumer
that notifies the promise of any failures either via theThrowable
passed into the BiConsumer of as a result of running the successFunction.- Type Parameters:
SuccessT
- Success type.PromiseT
- Type being fulfilled by the promise.- Parameters:
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.- Returns:
- BiConsumer that can be used in a
CompletableFuture.whenComplete(BiConsumer)
method.
-
asyncPromiseNotifyingBiConsumer
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)
Creates aBiConsumer
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.- Type Parameters:
SuccessT
- Success type.PromiseT
- Type being fulfilled by the Promise.- Parameters:
successConsumer
- BiConsumer to call if the result is successful. Promise is also passed and must be notified on success.promise
- Promise to notify.- Returns:
- BiConsumer that can be used in a
CompletableFuture.whenComplete(BiConsumer)
method.
-
promiseNotifyingListener
public static <T> io.netty.util.concurrent.GenericFutureListener<io.netty.util.concurrent.Future<T>> promiseNotifyingListener(io.netty.util.concurrent.Promise<T> channelPromise)
Create aGenericFutureListener
that will notify the providedPromise
on success and failure.- Parameters:
channelPromise
- Promise to notify.- Returns:
- GenericFutureListener
-
doInEventLoop
public static io.netty.util.concurrent.Future<?> doInEventLoop(io.netty.util.concurrent.EventExecutor eventExecutor, Runnable runnable)
Runs a task in the givenEventExecutor
. Runs immediately if the current thread is in the eventExecutor.- Parameters:
eventExecutor
- Executor to run task in.runnable
- Task to run.- Returns:
- The
Future
from from the executor.
-
doInEventLoop
public static void doInEventLoop(io.netty.util.concurrent.EventExecutor eventExecutor, Runnable runnable, io.netty.util.concurrent.Promise<?> promise)
Runs a task in the givenEventExecutor
. Runs immediately if the current thread is in the eventExecutor. Notifies the givenPromise
if a failure occurs.- Parameters:
eventExecutor
- Executor to run task in.runnable
- Task to run.promise
- Promise to notify if failure occurs.
-
warnIfNotInEventLoop
public static void warnIfNotInEventLoop(io.netty.channel.EventLoop loop)
-
getOrCreateAttributeKey
public static <T> io.netty.util.AttributeKey<T> getOrCreateAttributeKey(String attr)
- Returns:
- an
AttributeKey
forattr
. This returns an existing instance if it was previously created.
-
newSslHandler
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)
- Returns:
- a new
SslHandler
with ssl engine configured
-
consumeOrPropagate
public static <T> io.netty.util.concurrent.GenericFutureListener<io.netty.util.concurrent.Future<T>> consumeOrPropagate(io.netty.util.concurrent.Promise<?> destination, Consumer<T> onSuccess)
Create aGenericFutureListener
that will propagate any failures or cancellations to the providedPromise
, or invoke the providedConsumer
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 userunOrPropagate(Promise, Runnable)
instead.- Parameters:
destination
- the Promise to notify upon failure or cancellationonSuccess
- the Consumer to invoke upon success
-
runOrPropagate
public static <T> io.netty.util.concurrent.GenericFutureListener<io.netty.util.concurrent.Future<T>> runOrPropagate(io.netty.util.concurrent.Promise<?> destination, Runnable onSuccess)
Create aGenericFutureListener
that will propagate any failures or cancellations to the providedPromise
, or invoke the providedRunnable
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.- Parameters:
destination
- the Promise to notify upon failure or cancellationonSuccess
- the Runnable to invoke upon success
-
runAndLogError
public static void runAndLogError(NettyClientLogger log, String errorMsg, FunctionalUtils.UnsafeRunnable runnable)
-
-