public final class FaultToleranceMethodContextImpl extends Object implements FaultToleranceMethodContext
Method on a specific Class has a
corresponding instance of this FaultToleranceMethodContext. Multiple instances of that class share a context
(since MP FT 3.0).
When the annotated Method is invoked this implementation is bound to that context by
boundTo(InvocationContext, FaultTolerancePolicy) with a fresh instance of this class. It shares all the state
with other invocations for the same method except the InvocationContext and the FaultTolerancePolicy
which 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).FaultToleranceMethodContext.AsyncFuture| Constructor and Description |
|---|
FaultToleranceMethodContextImpl(javax.enterprise.context.control.RequestContextController requestContext,
FaultToleranceRequestTracing requestTracing,
FaultToleranceMetrics metrics,
ExecutorService asyncExecution,
ScheduledExecutorService delayedExecution,
String appName) |
| Modifier and Type | Method and Description |
|---|---|
FaultToleranceMethodContext |
boundTo(javax.interceptor.InvocationContext context,
FaultTolerancePolicy policy) |
void |
delay(long delayMillis)
Delays the current thread by the given duration.
|
void |
endTrace()
Ends the innermost trace.
|
Object |
fallbackHandle(Class<? extends org.eclipse.microprofile.faulttolerance.FallbackHandler<?>> fallbackClass,
Throwable ex)
|
Object |
fallbackInvoke(Method fallbackMethod)
Invokes the given fallback
Method in the given context. |
String |
getAppName() |
BlockingQueue<Thread> |
getConcurrentExecutions()
Get or create the
BlockingQueue for bulkhead. |
FaultToleranceMetrics |
getMetrics()
Returns the
FaultToleranceMetrics to use. |
AtomicInteger |
getQueuingOrRunningPopulation()
Get the bulkhead thread count.
|
CircuitBreakerState |
getState()
Get or create the
CircuitBreakerState. |
Object |
proceed()
Proceeds execution to the annotated method body.
|
void |
runAsynchronous(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.
|
String |
toString() |
void |
trace(String method)
Starts tracing the given context named with the given method label.
|
public FaultToleranceMethodContextImpl(javax.enterprise.context.control.RequestContextController requestContext,
FaultToleranceRequestTracing requestTracing,
FaultToleranceMetrics metrics,
ExecutorService asyncExecution,
ScheduledExecutorService delayedExecution,
String appName)
public String getAppName()
public FaultToleranceMethodContext boundTo(javax.interceptor.InvocationContext context, FaultTolerancePolicy policy)
boundTo in interface FaultToleranceMethodContextpublic Object proceed() throws Exception
FaultToleranceMethodContextproceed in interface FaultToleranceMethodContextException - in case the annotated method threw an Exception.public FaultToleranceMetrics getMetrics()
FaultToleranceMethodContextFaultToleranceMetrics to use.getMetrics in interface FaultToleranceMethodContextFaultToleranceMetrics to use, FaultToleranceMetrics.DISABLED when not enabled.public CircuitBreakerState getState()
FaultToleranceMethodContextCircuitBreakerState.getState in interface FaultToleranceMethodContextpublic BlockingQueue<Thread> getConcurrentExecutions()
FaultToleranceMethodContextBlockingQueue for bulkhead.getConcurrentExecutions in interface FaultToleranceMethodContextpublic AtomicInteger getQueuingOrRunningPopulation()
FaultToleranceMethodContextgetQueuingOrRunningPopulation in interface FaultToleranceMethodContextpublic void delay(long delayMillis)
throws InterruptedException
FaultToleranceMethodContextdelay in interface FaultToleranceMethodContextdelayMillis - the time to sleep in millisecondsInterruptedException - In case waiting is interruptedpublic void runAsynchronous(FaultToleranceMethodContext.AsyncFuture asyncResult, Callable<Object> task) throws RejectedExecutionException
runAsynchronous in interface FaultToleranceMethodContextasyncResult - a not yet completed CompletableFuture that should receive the result of the operation
when it is executedtask - an operation that must compute a value of type Future or CompletionStage.RejectedExecutionException - In case the task could not be accepted for execution. Usually due to too many
work in progress.public Future<?> runDelayed(long delayMillis, Runnable task) throws Exception
FaultToleranceMethodContextrunDelayed in interface FaultToleranceMethodContextdelayMillis - time to wait in milliseconds before running the given tasktask - operation to runExceptionpublic Object fallbackHandle(Class<? extends org.eclipse.microprofile.faulttolerance.FallbackHandler<?>> fallbackClass, Throwable ex) throws Exception
FaultToleranceMethodContextFallbackHandler Class defined in the given context to handle
the given Exception.fallbackHandle in interface FaultToleranceMethodContextfallbackClass - the type of FallbackHandler to resolve or instantiate and useex - the Exception thrown by the FT processing to handle by the FallbackHandlerFallbackHandlerException - in case resolving, instantiating or invoking the handler method failspublic Object fallbackInvoke(Method fallbackMethod) throws Exception
FaultToleranceMethodContextMethod in the given context.fallbackInvoke in interface FaultToleranceMethodContextfallbackMethod - the Method to invokeException - in case invoking the method fails or the invoked method threw an Exceptionpublic void trace(String method)
FaultToleranceMethodContexttrace in interface FaultToleranceMethodContextmethod - the label to use for the tracepublic void endTrace()
FaultToleranceMethodContextendTrace in interface FaultToleranceMethodContextCopyright © 2021. All rights reserved.