Class FaultToleranceMethodContextImpl
- java.lang.Object
-
- fish.payara.microprofile.faulttolerance.service.FaultToleranceMethodContextImpl
-
- All Implemented Interfaces:
FaultToleranceMethodContext
public final class FaultToleranceMethodContextImpl extends Object implements FaultToleranceMethodContext
The execution context for a FT annotated method. Each specificMethodon a specificClasshas a corresponding instance of thisFaultToleranceMethodContext. Multiple instances of that class share a context (since MP FT 3.0). When the annotatedMethodis invoked this implementation is bound to that context byboundTo(InvocationContext, FaultTolerancePolicy)with a fresh instance of this class. It shares all the state with other invocations for the same method except theInvocationContextand theFaultTolerancePolicywhich are specific for each invocation. This way the full FT invocation state for each method invocation is determined at the beginning of applying FT semantics and cannot change during execution (except for those counters and queues that are meant to track the shared state changes of course).- Author:
- Jan Bernitt
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface fish.payara.microprofile.faulttolerance.FaultToleranceMethodContext
FaultToleranceMethodContext.AsyncFuture
-
-
Constructor Summary
Constructors Constructor Description FaultToleranceMethodContextImpl(jakarta.enterprise.context.control.RequestContextController requestContext, FaultToleranceRequestTracing requestTracing, FaultToleranceMetrics metrics, ExecutorService asyncExecution, ScheduledExecutorService delayedExecution, String appName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FaultToleranceMethodContextboundTo(jakarta.interceptor.InvocationContext context, FaultTolerancePolicy policy)voiddelay(long delayMillis)Delays the current thread by the given duration.voidendTrace()Ends the innermost trace.ObjectfallbackHandle(Class<? extends org.eclipse.microprofile.faulttolerance.FallbackHandler<?>> fallbackClass, Throwable ex)ObjectfallbackInvoke(Method fallbackMethod)Invokes the given fallbackMethodin the given context.StringgetAppName()BlockingQueue<Thread>getConcurrentExecutions()Get or create theBlockingQueuefor bulkhead.FaultToleranceMetricsgetMetrics()Returns theFaultToleranceMetricsto use.AtomicIntegergetQueuingOrRunningPopulation()Get the bulkhead thread count.CircuitBreakerStategetState()Get or create theCircuitBreakerState.Objectproceed()Proceeds execution to the annotated method body.voidrunAsynchronous(FaultToleranceMethodContext.AsyncFuture asyncResult, Callable<Object> task)OBS! Unit tests implement a stub context with a simplified version of this implementation that needs to be updated properly whenever this method is changed in order to have comparable behaviour in tests.Future<?>runDelayed(long delayMillis, Runnable task)Runs a given task after a certain waiting time.StringtoString()voidtrace(String method)Starts tracing the given context named with the given method label.
-
-
-
Constructor Detail
-
FaultToleranceMethodContextImpl
public FaultToleranceMethodContextImpl(jakarta.enterprise.context.control.RequestContextController requestContext, FaultToleranceRequestTracing requestTracing, FaultToleranceMetrics metrics, ExecutorService asyncExecution, ScheduledExecutorService delayedExecution, String appName)
-
-
Method Detail
-
getAppName
public String getAppName()
-
boundTo
public FaultToleranceMethodContext boundTo(jakarta.interceptor.InvocationContext context, FaultTolerancePolicy policy)
- Specified by:
boundToin interfaceFaultToleranceMethodContext
-
proceed
public Object proceed() throws Exception
Description copied from interface:FaultToleranceMethodContextProceeds execution to the annotated method body.- Specified by:
proceedin interfaceFaultToleranceMethodContext- Returns:
- result returned by the annotated method
- Throws:
Exception- in case the annotated method threw anException.
-
getMetrics
public FaultToleranceMetrics getMetrics()
Description copied from interface:FaultToleranceMethodContextReturns theFaultToleranceMetricsto use.- Specified by:
getMetricsin interfaceFaultToleranceMethodContext- Returns:
- the
FaultToleranceMetricsto use,FaultToleranceMetrics.DISABLEDwhen not enabled.
-
getState
public CircuitBreakerState getState()
Description copied from interface:FaultToleranceMethodContextGet or create theCircuitBreakerState.- Specified by:
getStatein interfaceFaultToleranceMethodContext- Returns:
- the created or existing state, or null if non existed and requestVolumeThreshold was null
-
getConcurrentExecutions
public BlockingQueue<Thread> getConcurrentExecutions()
Description copied from interface:FaultToleranceMethodContextGet or create theBlockingQueuefor bulkhead.- Specified by:
getConcurrentExecutionsin interfaceFaultToleranceMethodContext- Returns:
- the created or existing queue, or null if non existed and requestVolumeThreshold was null
-
getQueuingOrRunningPopulation
public AtomicInteger getQueuingOrRunningPopulation()
Description copied from interface:FaultToleranceMethodContextGet the bulkhead thread count.- Specified by:
getQueuingOrRunningPopulationin interfaceFaultToleranceMethodContext- Returns:
- This are number of threads that are either waiting or running in the bulkhead.
-
delay
public void delay(long delayMillis) throws InterruptedExceptionDescription copied from interface:FaultToleranceMethodContextDelays the current thread by the given duration. The delay is traced.- Specified by:
delayin interfaceFaultToleranceMethodContext- Parameters:
delayMillis- the time to sleep in milliseconds- Throws:
InterruptedException- In case waiting is interrupted
-
runAsynchronous
public void runAsynchronous(FaultToleranceMethodContext.AsyncFuture asyncResult, Callable<Object> task) throws RejectedExecutionException
OBS! Unit tests implement a stub context with a simplified version of this implementation that needs to be updated properly whenever this method is changed in order to have comparable behaviour in tests.- Specified by:
runAsynchronousin interfaceFaultToleranceMethodContext- Parameters:
asyncResult- a not yet completedCompletableFuturethat should receive the result of the operation when it is executedtask- an operation that must compute a value of typeFutureorCompletionStage.- Throws:
RejectedExecutionException- In case the task could not be accepted for execution. Usually due to too many work in progress.
-
runDelayed
public Future<?> runDelayed(long delayMillis, Runnable task) throws Exception
Description copied from interface:FaultToleranceMethodContextRuns a given task after a certain waiting time.- Specified by:
runDelayedin interfaceFaultToleranceMethodContext- Parameters:
delayMillis- time to wait in milliseconds before running the given tasktask- operation to run- Returns:
- A future that can be cancelled if the operation should no longer be run
- Throws:
Exception
-
fallbackHandle
public Object fallbackHandle(Class<? extends org.eclipse.microprofile.faulttolerance.FallbackHandler<?>> fallbackClass, Throwable ex) throws Exception
Description copied from interface:FaultToleranceMethodContextInvokes the instance of the givenFallbackHandlerClassdefined in the given context to handle the givenException.- Specified by:
fallbackHandlein interfaceFaultToleranceMethodContext- Parameters:
fallbackClass- the type ofFallbackHandlerto resolve or instantiate and useex- theExceptionthrown by the FT processing to handle by theFallbackHandler- Returns:
- the result returned by the invoked
FallbackHandler - Throws:
Exception- in case resolving, instantiating or invoking the handler method fails
-
fallbackInvoke
public Object fallbackInvoke(Method fallbackMethod) throws Exception
Description copied from interface:FaultToleranceMethodContextInvokes the given fallbackMethodin the given context.- Specified by:
fallbackInvokein interfaceFaultToleranceMethodContext- Parameters:
fallbackMethod- theMethodto invoke- Returns:
- the result returned by the invoked fallback method
- Throws:
Exception- in case invoking the method fails or the invoked method threw anException
-
trace
public void trace(String method)
Description copied from interface:FaultToleranceMethodContextStarts tracing the given context named with the given method label.- Specified by:
tracein interfaceFaultToleranceMethodContext- Parameters:
method- the label to use for the trace
-
endTrace
public void endTrace()
Description copied from interface:FaultToleranceMethodContextEnds the innermost trace.- Specified by:
endTracein interfaceFaultToleranceMethodContext
-
-