Class NettyUtils
java.lang.Object
software.amazon.awssdk.http.nio.netty.internal.utils.NettyUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final io.netty.util.concurrent.SucceededFuture<?> Completed succeed future. -
Method Summary
Modifier and TypeMethodDescriptionstatic <SuccessT,PromiseT>
BiConsumer<SuccessT, ? super Throwable> asyncPromiseNotifyingBiConsumer(BiConsumer<SuccessT, io.netty.util.concurrent.Promise<PromiseT>> successConsumer, io.netty.util.concurrent.Promise<PromiseT> promise) Creates aBiConsumerthat notifies the promise of any failures either via the throwable passed into the BiConsumer or as a result of running the successConsumer.static StringclosedChannelMessage(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 aGenericFutureListenerthat will propagate any failures or cancellations to the providedPromise, or invoke the providedConsumerwith the result of a successful operation completion.static ThrowabledecorateException(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 voiddoInEventLoop(io.netty.util.concurrent.EventExecutor eventExecutor, Runnable runnable, io.netty.util.concurrent.Promise<?> promise) Runs a task in the givenEventExecutor.static Stringstatic <T> io.netty.util.AttributeKey<T> static booleanisAlpnSupported(io.netty.handler.ssl.SslProvider sslProvider) static io.netty.handler.ssl.SslHandlernewSslHandler(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 aBiConsumerthat notifies the promise of any failures either via theThrowablepassed 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 aGenericFutureListenerthat will notify the providedPromiseon success and failure.static voidrunAndLogError(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 aGenericFutureListenerthat will propagate any failures or cancellations to the providedPromise, or invoke the providedRunnableupon successful operation completion.static voidvalidateAlpnSupported(io.netty.handler.ssl.SslProvider sslProvider) static voidwarnIfNotInEventLoop(io.netty.channel.EventLoop loop)
-
Field Details
-
SUCCEEDED_FUTURE
public static final io.netty.util.concurrent.SucceededFuture<?> SUCCEEDED_FUTURECompleted succeed future. -
CLOSED_CHANNEL_ERROR_MESSAGE
- See Also:
-
-
Method Details
-
decorateException
-
closedChannelMessage
-
promiseNotifyingBiConsumer
public static <SuccessT,PromiseT> BiConsumer<SuccessT,? super Throwable> promiseNotifyingBiConsumer(Function<SuccessT, PromiseT> successFunction, io.netty.util.concurrent.Promise<PromiseT> promise) Creates aBiConsumerthat notifies the promise of any failures either via theThrowablepassed 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 aBiConsumerthat 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 aGenericFutureListenerthat will notify the providedPromiseon 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
Futurefrom 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 givenPromiseif 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
- Returns:
- an
AttributeKeyforattr. This returns an existing instance if it was previously created.
-
newSslHandler
-
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 aGenericFutureListenerthat will propagate any failures or cancellations to the providedPromise, or invoke the providedConsumerwith 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 aGenericFutureListenerthat will propagate any failures or cancellations to the providedPromise, or invoke the providedRunnableupon 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) -
isAlpnSupported
public static boolean isAlpnSupported(io.netty.handler.ssl.SslProvider sslProvider) -
getJavaVersion
-
validateAlpnSupported
public static void validateAlpnSupported(io.netty.handler.ssl.SslProvider sslProvider)
-