use of fish.payara.microprofile.faulttolerance.FaultToleranceService in project Payara by payara.
the class FallbackPolicy method fallback.
/**
* Performs the fallback operation defined by the @Fallback annotation.
* @param invocationContext The failing invocation context
* @return The result of the executed fallback method
* @throws Exception If the fallback method itself fails.
*/
public Object fallback(InvocationContext invocationContext) throws Exception {
Object fallbackInvocationContext = null;
FaultToleranceService faultToleranceService = Globals.getDefaultBaseServiceLocator().getService(FaultToleranceService.class);
InvocationManager invocationManager = Globals.getDefaultBaseServiceLocator().getService(InvocationManager.class);
faultToleranceService.startFaultToleranceSpan(new RequestTraceSpan("executeFallbackMethod"), invocationManager, invocationContext);
try {
if (fallbackMethod != null && !fallbackMethod.isEmpty()) {
logger.log(Level.FINE, "Using fallback method: {0}", fallbackMethod);
fallbackInvocationContext = invocationContext.getMethod().getDeclaringClass().getDeclaredMethod(fallbackMethod, invocationContext.getMethod().getParameterTypes()).invoke(invocationContext.getTarget(), invocationContext.getParameters());
} else {
logger.log(Level.FINE, "Using fallback class: {0}", fallbackClass.getName());
ExecutionContext executionContext = new FaultToleranceExecutionContext(invocationContext.getMethod(), invocationContext.getParameters());
fallbackInvocationContext = fallbackClass.getDeclaredMethod(FALLBACK_HANDLER_METHOD_NAME, ExecutionContext.class).invoke(CDI.current().select(fallbackClass).get(), executionContext);
}
} finally {
faultToleranceService.endFaultToleranceSpan();
}
return fallbackInvocationContext;
}
Aggregations