Top Description Inners Fields Constructors Methods
io.netty5.util.concurrent

pack-priv final Class Futures

extends Object
Class Inheritance
Imports
io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.util.concurrent.Callable, java.util.function.Function

Combinator operations on futures.

Used for implementing Future#map(Function) and Future#flatMap(Function)

Implementation Note

The operations themselves are implemented as static inner classes instead of lambdas to aid debugging.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final InternalLogger
private static final Futures.PassThrough<?>
private static final Futures.PropagateCancel

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static <
the type of the value.
V
>
void
cascade(final Future<V>
the Future which will be used to listen to for notifying the Promise.
future
,
final Promise<? super V>
the Promise which will be notified
promise
)

Link the Future and Promise such that if the Future completes the Promise will be notified.

public static <V,
The result type of the mapper function, and of the returned future.
R
>
Future<R>

Returns:

A new future instance that will complete with the mapped result of the given future.
flatMap
(Future<V> future, Function<V, Future<R>>
The function that will convert the result of the given future into the result of the returned future.
mapper
)

Creates a new Future that will complete with the result of the given Future flat-mapped through the given mapper function.

public static <V,
The result type of the mapper function, and of the returned future.
R
>
Future<R>

Returns:

A new future instance that will complete with the mapped result of the given future.
map
(Future<V>
The future whose result will flow to the returned future, through the mapping function.
future
,
Function<V, R>
The function that will convert the result of the given future into the result of the returned future.
mapper
)

Creates a new Future that will complete with the result of the given Future mapped through the given mapper function.

pack-priv static <R> FutureContextListener<Promise<R>, Object>
pack-priv static FutureContextListener<Future<?>, Object>
pack-priv static <A, B> void
propagateUncommonCompletion(Future<? extends A> completed, Promise<B> recipient)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loggerback to summary
private static final InternalLogger logger
PASS_THROUGHback to summary
private static final Futures.PassThrough<?> PASS_THROUGH
PROPAGATE_CANCELback to summary
private static final Futures.PropagateCancel PROPAGATE_CANCEL

Constructor Detail

Futuresback to summary
private Futures()

Method Detail

cascadeback to summary
pack-priv static <V> void cascade(final Future<V> future, final Promise<? super V> promise)

Link the Future and Promise such that if the Future completes the Promise will be notified. Cancellation is propagated both ways such that if the Future is cancelled the Promise is cancelled and vice-versa.

Parameters
<V>
the type of the value.
future:Future<V>

the Future which will be used to listen to for notifying the Promise.

promise:Promise<? super V>

the Promise which will be notified

flatMapback to summary
public static <V, R> Future<R> flatMap(Future<V> future, Function<V, Future<R>> mapper)

Creates a new Future that will complete with the result of the given Future flat-mapped through the given mapper function.

The "flat" in "flat-map" means the given mapper function produces a result that itself is a future-of-R, yet this method also returns a future-of-R, rather than a future-of-future-of-R. In other words, if the same mapper function was used with the map(Future, Function) method, you would get back a Future<Future<R>>. These nested futures are "flattened" into a Future<R> by this method.

Effectively, this method behaves similar to this serial code, except asynchronously and with proper exception and cancellation handling:

V x = future.sync().getNow();
Future<R> y = mapper.apply(x);
R result = y.sync().getNow();

If the given future fails, then the returned future will fail as well, with the same exception. Cancellation of either future will cancel the other. If the mapper function throws, the returned future will fail, but the given future will be unaffected.

Parameters
<R>
The result type of the mapper function, and of the returned future.
mapper:Function<V, Future<R>>

The function that will convert the result of the given future into the result of the returned future.

Returns:Future<R>

A new future instance that will complete with the mapped result of the given future.

mapback to summary
public static <V, R> Future<R> map(Future<V> future, Function<V, R> mapper)

Creates a new Future that will complete with the result of the given Future mapped through the given mapper function.

If the given future fails, then the returned future will fail as well, with the same exception. Cancellation of either future will cancel the other. If the mapper function throws, the returned future will fail, but the given future will be unaffected.

Parameters
<R>
The result type of the mapper function, and of the returned future.
future:Future<V>

The future whose result will flow to the returned future, through the mapping function.

mapper:Function<V, R>

The function that will convert the result of the given future into the result of the returned future.

Returns:Future<R>

A new future instance that will complete with the mapped result of the given future.

passThroughback to summary
pack-priv static <R> FutureContextListener<Promise<R>, Object> passThrough()
Annotations
@SuppressWarnings:unchecked
propagateCancelback to summary
pack-priv static FutureContextListener<Future<?>, Object> propagateCancel()
Annotations
@SuppressWarnings:unchecked
propagateUncommonCompletionback to summary
pack-priv static <A, B> void propagateUncommonCompletion(Future<? extends A> completed, Promise<B> recipient)
io.netty5.util.concurrent back to summary

private final Class Futures.CallableMapper<R, T>

extends Object
implements Callable<R>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Callable

Field Summary

Modifier and TypeField and Description
private final Future<T>
private final Function<T, R>

Constructor Summary

AccessConstructor and Description
pack-priv
CallableMapper(Future<T> future, Function<T, R> mapper)

Method Summary

Modifier and TypeMethod and Description
public R
call()

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

futureback to summary
private final Future<T> future
mapperback to summary
private final Function<T, R> mapper

Constructor Detail

CallableMapperback to summary
pack-priv CallableMapper(Future<T> future, Function<T, R> mapper)

Method Detail

callback to summary
public R call() throws Exception

Implements java.util.concurrent.Callable.call.

Doc from java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

Returns:R

computed result

Annotations
@Override
Exceptions
Exception:
if unable to compute a result
io.netty5.util.concurrent back to summary

private final Class Futures.FlatMapper<R, T>

extends Object
implements FutureListener<Object>
Class Inheritance
All Implemented Interfaces
io.netty5.util.concurrent.FutureListener

Field Summary

Modifier and TypeField and Description
private final Function<T, Future<R>>
private final Promise<R>

Constructor Summary

AccessConstructor and Description
pack-priv
FlatMapper(Promise<R> recipient, Function<T, Future<R>> mapper)

Method Summary

Modifier and TypeMethod and Description
public void
operationComplete(Future<?>
the source Future which called this callback
completed
)

Implements io.netty5.util.concurrent.FutureListener.operationComplete.

Invoked when the operation associated with the Future has been completed.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mapperback to summary
private final Function<T, Future<R>> mapper
recipientback to summary
private final Promise<R> recipient

Constructor Detail

FlatMapperback to summary
pack-priv FlatMapper(Promise<R> recipient, Function<T, Future<R>> mapper)

Method Detail

operationCompleteback to summary
public void operationComplete(Future<?> completed) throws Exception

Implements io.netty5.util.concurrent.FutureListener.operationComplete.

Doc from io.netty5.util.concurrent.FutureListener.operationComplete.

Invoked when the operation associated with the Future has been completed.

Parameters
completed:Future<?>

the source Future which called this callback

Annotations
@Override
io.netty5.util.concurrent back to summary

private final Class Futures.Mapper<R, T>

extends Object
implements FutureListener<Object>
Class Inheritance
All Implemented Interfaces
io.netty5.util.concurrent.FutureListener

Field Summary

Modifier and TypeField and Description
private final Function<T, R>
private final Promise<R>

Constructor Summary

AccessConstructor and Description
pack-priv
Mapper(Promise<R> recipient, Function<T, R> mapper)

Method Summary

Modifier and TypeMethod and Description
public void
operationComplete(Future<?>
the source Future which called this callback
completed
)

Implements io.netty5.util.concurrent.FutureListener.operationComplete.

Invoked when the operation associated with the Future has been completed.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mapperback to summary
private final Function<T, R> mapper
recipientback to summary
private final Promise<R> recipient

Constructor Detail

Mapperback to summary
pack-priv Mapper(Promise<R> recipient, Function<T, R> mapper)

Method Detail

operationCompleteback to summary
public void operationComplete(Future<?> completed) throws Exception

Implements io.netty5.util.concurrent.FutureListener.operationComplete.

Doc from io.netty5.util.concurrent.FutureListener.operationComplete.

Invoked when the operation associated with the Future has been completed.

Parameters
completed:Future<?>

the source Future which called this callback

Annotations
@Override
io.netty5.util.concurrent back to summary

private final Class Futures.PassThrough<R>

extends Object
implements FutureContextListener<Promise<R>, Object>
Class Inheritance
All Implemented Interfaces
io.netty5.util.concurrent.FutureContextListener

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
operationComplete(Promise<R> recipient, Future<?>
the source Future which called this callback
completed
)

Implements io.netty5.util.concurrent.FutureContextListener.operationComplete.

Invoked when the operation associated with the Future has been completed.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

PassThroughback to summary
private PassThrough()

Method Detail

operationCompleteback to summary
public void operationComplete(Promise<R> recipient, Future<?> completed) throws Exception

Implements io.netty5.util.concurrent.FutureContextListener.operationComplete.

Doc from io.netty5.util.concurrent.FutureContextListener.operationComplete.

Invoked when the operation associated with the Future has been completed.

Parameters
completed:Future<?>

the source Future which called this callback

Annotations
@Override
io.netty5.util.concurrent back to summary

private final Class Futures.PropagateCancel

extends Object
implements FutureContextListener<Future<Object>, Object>
Class Inheritance
All Implemented Interfaces
io.netty5.util.concurrent.FutureContextListener

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
operationComplete(Future<Object> context, Future<?>
the source Future which called this callback
future
)

Implements io.netty5.util.concurrent.FutureContextListener.operationComplete.

Invoked when the operation associated with the Future has been completed.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

PropagateCancelback to summary
private PropagateCancel()

Method Detail

operationCompleteback to summary
public void operationComplete(Future<Object> context, Future<?> future) throws Exception

Implements io.netty5.util.concurrent.FutureContextListener.operationComplete.

Doc from io.netty5.util.concurrent.FutureContextListener.operationComplete.

Invoked when the operation associated with the Future has been completed.

Parameters
future:Future<?>

the source Future which called this callback

Annotations
@Override