Class JdkFutures
- java.lang.Object
-
- org.opendaylight.infrautils.utils.concurrent.JdkFutures
-
public final class JdkFutures extends Object
Utility methods pertaining to the Java 5Future
interface.Use of JDK Future should generally be avoid, but is prevalent in ODL because the Java Bindings (v1) generated code uses them for all RPC return types.
Any new hand written code should never use the old Future interface anymore, but instead use either a Guava
ListenableFuture
, or a Java 8CompletionStage
.- Author:
- Michael Vorburger.ch
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <V> void
addErrorLogging(Future<V> future, org.slf4j.Logger logger, String message)
Deprecated.static <V> void
addErrorLogging(Future<V> future, org.slf4j.Logger logger, String format, Object arg)
Deprecated.static <V> void
addErrorLogging(Future<V> future, org.slf4j.Logger logger, String format, Object... args)
static <V> CompletionStage<V>
toCompletionStage(Future<V> future)
Converts a Java 5Future
to a Java 8CompletionStage
.static <V> com.google.common.util.concurrent.ListenableFuture<V>
toListenableFuture(Future<V> future)
Converts a Java 5Future
to a GuavaListenableFuture
.static <V> com.google.common.util.concurrent.ListenableFuture<V>
toListenableFuture(Future<V> future, Executor executor)
Converts a Java 5Future
to a GuavaListenableFuture
, using your own Executor.
-
-
-
Method Detail
-
toListenableFuture
public static <V> com.google.common.util.concurrent.ListenableFuture<V> toListenableFuture(Future<V> future)
Converts a Java 5Future
to a GuavaListenableFuture
.See also Guava's
JdkFutureAdapters
utility, which is used internally here (with an Executor that would log any possible issues, and which will be metric monitored).
-
toListenableFuture
public static <V> com.google.common.util.concurrent.ListenableFuture<V> toListenableFuture(Future<V> future, Executor executor)
Converts a Java 5Future
to a GuavaListenableFuture
, using your own Executor.It's typically a bad idea to pass a directExector here, because then the
ListenableFuture.addListener(Runnable, Executor)
will become blocking and one might as well just use the Future's blocking get() instead of this.
-
toCompletionStage
public static <V> CompletionStage<V> toCompletionStage(Future<V> future)
Converts a Java 5Future
to a Java 8CompletionStage
.
-
addErrorLogging
@Deprecated public static <V> void addErrorLogging(Future<V> future, org.slf4j.Logger logger, String message)
Deprecated.Adds a callback to a Future which logs any failures.
-
addErrorLogging
@Deprecated public static <V> void addErrorLogging(Future<V> future, org.slf4j.Logger logger, String format, Object arg)
Deprecated.Adds a callback to a Future which logs any failures.
-
addErrorLogging
@Deprecated public static <V> void addErrorLogging(Future<V> future, org.slf4j.Logger logger, String format, Object... args)
Adds a callback to a Future which logs any failures.
-
-