diff --git a/doc/modules/ROOT/pages/internals/core.adoc b/doc/modules/ROOT/pages/internals/core.adoc index 5f498c38..36e271ed 100644 --- a/doc/modules/ROOT/pages/internals/core.adoc +++ b/doc/modules/ROOT/pages/internals/core.adoc @@ -16,9 +16,9 @@ NOTE: The `Future` type here is _not_ a `java.util.concurrent.Future`. It comes from {smallrye-fault-tolerance} and it could be described as a very bare-bones variant of `CompletableFuture`, except it's split into `Completer` and `Future`. It is not supposed to be used outside of this project. -The `FaultToleranceContext` is a `Supplier>` that represents the method invocation guarded by this fault tolerance strategy. -The fault tolerance strategy does its work around `ctx.get()`. -It can catch exceptions, invoke `ctx.get()` multiple times, invoke something else, etc. +The `FaultToleranceContext` is similar to a `Callable>`; it represents the method invocation guarded by this fault tolerance strategy. +The fault tolerance strategy does its work around `ctx.call()`. +It can catch exceptions, invoke `ctx.call()` multiple times, invoke something else, etc. As an example, let's consider this strategy, applicable to methods that return a `String`: [source,java] @@ -28,7 +28,7 @@ public class MyStringFallback implements FaultToleranceStrategy { public Future apply(FaultToleranceContext ctx) { Completer completer = Completer.create(); try { - ctx.get().then((value, error) -> { + ctx.call().then((value, error) -> { if (error == null) { completer.complete(value); } else { @@ -81,9 +81,9 @@ public class MyStringFallback implements FaultToleranceStrategy { We see that one strategy delegates to another, passing the `FaultToleranceContext` along. In fact, all the implementations in {smallrye-fault-tolerance} are written like this: they expect to be used in a chain, so they take another `FaultToleranceStrategy` to which they delegate. -But if all strategies have this form, when is `ctx.get()` actually invoked? +But if all strategies have this form, when is `ctx.call()` actually invoked? Good question! -The ultimate `ctx.get()` invocation is done by a special fault tolerance strategy which is called, well, `Invocation`. +The ultimate `ctx.call()` invocation is done by a special fault tolerance strategy which is called, well, `Invocation`. As an example which uses real {microprofile-fault-tolerance} annotations, let's consider this method: @@ -105,7 +105,7 @@ Fallback( Retry( Timeout( Invocation( - // ctx.get() will happen here + // ctx.call() will happen here // that will, in turn, invoke doSomething() ) ) diff --git a/implementation/core/src/main/java/io/smallrye/faulttolerance/core/FaultToleranceContext.java b/implementation/core/src/main/java/io/smallrye/faulttolerance/core/FaultToleranceContext.java index 66e65dc5..1f04cabe 100644 --- a/implementation/core/src/main/java/io/smallrye/faulttolerance/core/FaultToleranceContext.java +++ b/implementation/core/src/main/java/io/smallrye/faulttolerance/core/FaultToleranceContext.java @@ -7,7 +7,7 @@ import java.util.function.Consumer; import java.util.function.Supplier; -public final class FaultToleranceContext implements Supplier> { +public final class FaultToleranceContext { private final Supplier> delegate; private final boolean isAsync; @@ -16,8 +16,7 @@ public FaultToleranceContext(Supplier> delegate, boolean isAsync) { this.isAsync = isAsync; } - @Override - public Future get() { + public Future call() { return delegate.get(); } diff --git a/implementation/core/src/main/java/io/smallrye/faulttolerance/core/Invocation.java b/implementation/core/src/main/java/io/smallrye/faulttolerance/core/Invocation.java index b9c684a4..e723909e 100644 --- a/implementation/core/src/main/java/io/smallrye/faulttolerance/core/Invocation.java +++ b/implementation/core/src/main/java/io/smallrye/faulttolerance/core/Invocation.java @@ -26,7 +26,7 @@ private Invocation() { public Future apply(FaultToleranceContext ctx) { LOG.trace("Guarded method invocation started"); try { - return ctx.get(); + return ctx.call(); } catch (Exception e) { return Future.ofError(e); } finally {