public final class FaultToleranceMethodContextImpl extends Object implements FaultToleranceMethodContext
Method for each individual target Object
(instance of the Class defining the Method) has its corresponding instance of this
FaultToleranceMethodContext.
When the annotated Method is invoked this implementation is bound to that context by
in(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).| Constructor and Description |
|---|
FaultToleranceMethodContextImpl(javax.enterprise.context.control.RequestContextController requestContext,
FaultToleranceRequestTracing requestTracing,
FaultToleranceMetrics metrics,
ExecutorService asyncExecution,
ScheduledExecutorService delayedExecution,
Object target) |
| Modifier and Type | Method and Description |
|---|---|
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. |
BlockingQueue<Thread> |
getConcurrentExecutions(int maxConcurrentThreads)
Get or create the
BlockingQueue for bulkhead. |
FaultToleranceMetrics |
getMetrics(boolean enabled)
Returns the
FaultToleranceMetrics to use. |
AtomicInteger |
getQueuingOrRunningPopulation()
Get the bulkhead thread count.
|
CircuitBreakerState |
getState(int requestVolumeThreshold)
Get or create the
CircuitBreakerState. |
FaultToleranceMethodContextImpl |
in(javax.interceptor.InvocationContext context,
FaultTolerancePolicy policy) |
boolean |
isExpired(long ttl) |
Object |
proceed()
Proceeds execution to the annotated method body.
|
void |
runAsynchronous(CompletableFuture<Object> asyncResult,
Callable<Object> task)
Runs the task asynchronously and completes the given asyncResult with the its outcome.
|
Future<?> |
runDelayed(long delayMillis,
Runnable task)
Runs a given task after a certain waiting time.
|
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,
Object target)
public boolean isExpired(long ttl)
public FaultToleranceMethodContextImpl in(javax.interceptor.InvocationContext context, FaultTolerancePolicy policy)
public Object proceed() throws Exception
FaultToleranceMethodContextproceed in interface FaultToleranceMethodContextException - in case the annotated method threw an Exception.public FaultToleranceMetrics getMetrics(boolean enabled)
FaultToleranceMethodContextFaultToleranceMetrics to use.getMetrics in interface FaultToleranceMethodContextenabled - true, if metrics are enabled for the method, else falseFaultToleranceMetrics to use, FaultToleranceMetrics.DISABLED when not enabled.public CircuitBreakerState getState(int requestVolumeThreshold)
FaultToleranceMethodContextCircuitBreakerState.getState in interface FaultToleranceMethodContextrequestVolumeThreshold - when negative no state is created if it does not already existpublic BlockingQueue<Thread> getConcurrentExecutions(int maxConcurrentThreads)
FaultToleranceMethodContextBlockingQueue for bulkhead.getConcurrentExecutions in interface FaultToleranceMethodContextmaxConcurrentThreads - when negative no queue is created if it does not already existpublic 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(CompletableFuture<Object> asyncResult, Callable<Object> task) throws RejectedExecutionException
FaultToleranceMethodContextrunAsynchronous 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 © 2020. All rights reserved.