Skip to content

Commit

Permalink
rename interceptionContext to invocationContext on remaining places
Browse files Browse the repository at this point in the history
Previously, when SmallRye Fault Tolerance's `InvocationContext` was
renamed to `FaultToleranceContext`, some of the `interceptionContext`
variables were renamed to `invocationContext` (now that there's no
ambiguity). This commit finishes that rename.
  • Loading branch information
Ladicek committed Nov 22, 2024
1 parent 6d9a7e1 commit 7952f55
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@
import org.eclipse.microprofile.faulttolerance.ExecutionContext;

final class ExecutionContextImpl implements ExecutionContext {
private final InvocationContext interceptionContext;
private final InvocationContext invocationContext;
private final Throwable failure;

ExecutionContextImpl(InvocationContext interceptionContext, Throwable failure) {
this.interceptionContext = interceptionContext;
ExecutionContextImpl(InvocationContext invocationContext, Throwable failure) {
this.invocationContext = invocationContext;
this.failure = failure;
}

@Override
public Method getMethod() {
return interceptionContext.getMethod();
return invocationContext.getMethod();
}

@Override
public Object[] getParameters() {
return interceptionContext.getParameters();
return invocationContext.getParameters();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,22 @@ public FaultToleranceInterceptor(
}

@AroundInvoke
public Object intercept(InvocationContext interceptionContext) throws Throwable {
Method method = interceptionContext.getMethod();
public Object intercept(InvocationContext invocationContext) throws Throwable {
Method method = invocationContext.getMethod();
Class<?> beanClass = interceptedBean != null ? interceptedBean.getBeanClass() : method.getDeclaringClass();
InterceptionPoint point = new InterceptionPoint(beanClass, interceptionContext.getMethod());
InterceptionPoint point = new InterceptionPoint(beanClass, invocationContext.getMethod());
FaultToleranceOperation operation = operationProvider.get(beanClass, method);

if (operation.hasApplyFaultTolerance()) {
return applyFaultToleranceFlow(operation, interceptionContext);
return applyFaultToleranceFlow(operation, invocationContext);
} else if (operation.hasApplyGuard()) {
return applyGuardFlow(operation, interceptionContext, point);
return applyGuardFlow(operation, invocationContext, point);
} else if (specCompatibility.isOperationTrulyAsynchronous(operation)) {
return asyncFlow(operation, interceptionContext, point);
return asyncFlow(operation, invocationContext, point);
} else if (specCompatibility.isOperationPseudoAsynchronous(operation)) {
return futureFlow(operation, interceptionContext, point);
return futureFlow(operation, invocationContext, point);
} else {
return syncFlow(operation, interceptionContext, point);
return syncFlow(operation, invocationContext, point);
}
}

Expand All @@ -211,7 +211,7 @@ public Object intercept(InvocationContext interceptionContext) throws Throwable
//
// in synchronous scenario, V = T
// in asynchronous scenario, T is an async type that eventually produces V
private <V, T> T applyFaultToleranceFlow(FaultToleranceOperation operation, InvocationContext interceptionContext)
private <V, T> T applyFaultToleranceFlow(FaultToleranceOperation operation, InvocationContext invocationContext)
throws Exception {
String identifier = operation.getApplyFaultTolerance().value();
Instance<FaultTolerance<?>> instance = configuredFaultTolerance.select(Identifier.Literal.of(identifier));
Expand All @@ -233,7 +233,7 @@ private <V, T> T applyFaultToleranceFlow(FaultToleranceOperation operation, Invo
AsyncSupport<?, ?> fromConfigured = asyncType == null ? null : AsyncSupportRegistry.get(new Class[0], asyncType);

if (forOperation == null && fromConfigured == null) {
return (T) lazyFaultTolerance.call(interceptionContext::proceed, meteredOperationName);
return (T) lazyFaultTolerance.call(invocationContext::proceed, meteredOperationName);
} else if (forOperation == null) {
throw new FaultToleranceException("Configured fault tolerance '" + identifier
+ "' expects the operation to " + fromConfigured.mustDescription()
Expand All @@ -247,7 +247,7 @@ private <V, T> T applyFaultToleranceFlow(FaultToleranceOperation operation, Invo
+ "' expects the operation to " + fromConfigured.mustDescription()
+ ", but it " + forOperation.doesDescription() + ": " + operation);
} else {
return (T) lazyFaultTolerance.call(interceptionContext::proceed, meteredOperationName);
return (T) lazyFaultTolerance.call(invocationContext::proceed, meteredOperationName);
}
}

Expand All @@ -256,7 +256,7 @@ private <V, T> T applyFaultToleranceFlow(FaultToleranceOperation operation, Invo
//
// in synchronous scenario, V = T
// in asynchronous scenario, T is an async type that eventually produces V
private <V, T> T applyGuardFlow(FaultToleranceOperation operation, InvocationContext interceptionContext,
private <V, T> T applyGuardFlow(FaultToleranceOperation operation, InvocationContext invocationContext,
InterceptionPoint point) throws Exception {
String identifier = operation.getApplyGuard().value();
Instance<Guard> guardInstance = configuredGuard.select(Identifier.Literal.of(identifier));
Expand Down Expand Up @@ -287,7 +287,7 @@ private <V, T> T applyGuardFlow(FaultToleranceOperation operation, InvocationCon
MeteredOperationName meteredOperationName = new MeteredOperationName(operation.getName());

Consumer<FaultToleranceContext<?>> contextModifier = ctx -> {
ctx.set(InvocationContext.class, interceptionContext);
ctx.set(InvocationContext.class, invocationContext);

if (fallbackFunction != null) {
ctx.set(FallbackFunction.class, fallbackFunction);
Expand All @@ -309,7 +309,7 @@ private <V, T> T applyGuardFlow(FaultToleranceOperation operation, InvocationCon
}
GuardImpl guardImpl = ((LazyGuard) guard).instance();

return guardImpl.guard(() -> (T) interceptionContext.proceed(), operation.getReturnType(), contextModifier);
return guardImpl.guard(() -> (T) invocationContext.proceed(), operation.getReturnType(), contextModifier);
} else /* typedGuardInstance.isResolvable() */ {
TypedGuard<T> guard = typedGuardInstance.get();
if (!(guard instanceof LazyTypedGuard)) {
Expand All @@ -318,7 +318,7 @@ private <V, T> T applyGuardFlow(FaultToleranceOperation operation, InvocationCon
}
TypedGuardImpl<V, T> guardImpl = ((LazyTypedGuard<V, T>) guard).instance();

return guardImpl.guard(() -> (T) interceptionContext.proceed(), contextModifier);
return guardImpl.guard(() -> (T) invocationContext.proceed(), contextModifier);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public final class BeforeRetryMethod {
}

public Invoker<?> createInvoker(FailureContext ctx) throws ReflectiveOperationException {
InvocationContext interceptionContext = ctx.context.get(InvocationContext.class);
Object[] arguments = interceptionContext.getParameters();
InvocationContext invocationContext = ctx.context.get(InvocationContext.class);
Object[] arguments = invocationContext.getParameters();
if (arguments == null) {
arguments = EMPTY_ARRAY;
}

return method.isDefault()
? new SpecialMethodInvoker<>(method, interceptionContext.getTarget(), arguments)
: new NormalMethodInvoker<>(method, interceptionContext.getTarget(), arguments);
? new SpecialMethodInvoker<>(method, invocationContext.getTarget(), arguments)
: new NormalMethodInvoker<>(method, invocationContext.getTarget(), arguments);
}

// ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ private FallbackMethod(Method method, int exceptionParameterPosition) {
// ---

public <T> Invoker<T> createInvoker(FailureContext ctx) throws ReflectiveOperationException {
InvocationContext interceptionContext = ctx.context.get(InvocationContext.class);
Object[] arguments = interceptionContext.getParameters();
InvocationContext invocationContext = ctx.context.get(InvocationContext.class);
Object[] arguments = invocationContext.getParameters();
if (arguments == null) {
arguments = EMPTY_ARRAY;
}
arguments = adjustArguments(arguments, ctx.failure);

return method.isDefault()
? new SpecialMethodInvoker<>(method, interceptionContext.getTarget(), arguments)
: new NormalMethodInvoker<>(method, interceptionContext.getTarget(), arguments);
? new SpecialMethodInvoker<>(method, invocationContext.getTarget(), arguments)
: new NormalMethodInvoker<>(method, invocationContext.getTarget(), arguments);
}

private Object[] adjustArguments(Object[] arguments, Throwable exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@
import io.smallrye.faulttolerance.core.invocation.Invoker;

public class InterceptionInvoker<V> implements Invoker<V> {
private final InvocationContext interceptionContext;
private final InvocationContext invocationContext;

public InterceptionInvoker(InvocationContext interceptionContext) {
this.interceptionContext = interceptionContext;
public InterceptionInvoker(InvocationContext invocationContext) {
this.invocationContext = invocationContext;
}

@Override
public int parametersCount() {
return interceptionContext.getParameters().length;
return invocationContext.getParameters().length;
}

@Override
public <T> T getArgument(int index, Class<T> parameterType) {
return parameterType.cast(interceptionContext.getParameters()[index]);
return parameterType.cast(invocationContext.getParameters()[index]);
}

@Override
public <T> T replaceArgument(int index, Class<T> parameterType, Function<T, T> transformation) {
Object[] arguments = interceptionContext.getParameters();
Object[] arguments = invocationContext.getParameters();
T oldArg = parameterType.cast(arguments[index]);
T newArg = transformation.apply(oldArg);
arguments[index] = newArg;
interceptionContext.setParameters(arguments);
invocationContext.setParameters(arguments);
return oldArg;
}

@Override
public V proceed() throws Exception {
return (V) interceptionContext.proceed();
return (V) invocationContext.proceed();
}
}

0 comments on commit 7952f55

Please sign in to comment.