public class BackoffRunnableRetrier<T> extends Object implements RunnableRetrier<T>, FastRecoveryObserver
Runnables in a separate thread until they complete successfully. An execution is considered
successful when it does not end with an Exception.
Under the hood, this object uses the BackoffScheduler's engine, in FastRecovery mode. This means that backoff
will be applied to those task who raise an Exception. The first execution that finishes without an error, will mean
that it ended successfully and will not be rescheduled again. BackoffConfiguration can be set to each instance of this.
BackoffRunnableRetrier handles one queue per instance of key (of type T). Subsequent queued Runnables for a key will not be executed until its current scheduled task reaches the Stable state. NOTE: if for a
certain key, running task never halts, the remaining queued tasks will starve.
To minimize runtime resource consumption, BackoffScheduler will be disposed if there are no further tasks to process.
It will be recreated as soon as a Runnable is scheduled.| Modifier and Type | Class and Description |
|---|---|
static class |
BackoffRunnableRetrier.Builder<T> |
| Modifier and Type | Method and Description |
|---|---|
static SchedulingConfiguration |
delayInitialScheduling(int initialDelay) |
void |
dispose() |
FastRecoveryObserver |
fastRecoveryAbort(BackoffRunnable backoffRunnable)
Notifies the fast recovery
BackoffRunnable is now with Error. |
FastRecoveryObserver |
fastRecoveryStable(BackoffRunnable backoffRunnable,
FastRecoveryConfiguration configuration)
Notifies the fast recovery
BackoffRunnable is now Stable. |
FastRecoveryObserver |
fastRecoveryUnstable(BackoffRunnable runnable,
FastRecoveryConfiguration configuration)
Notifies the fast recovery
BackoffRunnable is still Unstable. |
boolean |
hasQueuedRunnables(T key)
Return whether there are task pending to execute for an specific key.
|
boolean |
isIdle(T key)
Return whether the retrier is idle or there are tasks running or pending for execution for a specific key.
|
RunnableRetrier<T> |
scheduleRetry(T key,
Runnable runnable)
Schedules a task to be executed until successful.
|
static SchedulingConfiguration |
zeroDelayOnScheduling() |
public RunnableRetrier<T> scheduleRetry(T key, Runnable runnable)
Runnable already running for that key, task will be immediately scheduled as a
BackoffRunnable. Otherwise, it will be queued for later processing.scheduleRetry in interface RunnableRetrier<T>key - Runnable's key.runnable - task to schedule.public boolean hasQueuedRunnables(T key)
RunnableRetrierhasQueuedRunnables in interface RunnableRetrier<T>key - pending task's key.public boolean isIdle(T key)
key - pending task's key.public FastRecoveryObserver fastRecoveryUnstable(BackoffRunnable runnable, FastRecoveryConfiguration configuration)
BackoffRunnable is still Unstable.
While BackoffRunnable remains Unstable, this object won't do anything. The BackoffScheduler will
automatically reschedule the task.fastRecoveryUnstable in interface FastRecoveryObserverrunnable - the Unstable BackoffRunnable.configuration - the suggested delay and frequency if rescheduled along with its observers.public FastRecoveryObserver fastRecoveryStable(BackoffRunnable backoffRunnable, FastRecoveryConfiguration configuration)
BackoffRunnable is now Stable.
When BackoffRunnable returns to Stable state, the BackoffScheduler will remove the
FastRecovery task. This object then, must schedule the next queued Runnable for that key, or dispose the
scheduler if it was the last one.fastRecoveryStable in interface FastRecoveryObserverbackoffRunnable - the Stable BackoffRunnable.configuration - the suggested delay and frequency if rescheduled along with its observers.public FastRecoveryObserver fastRecoveryAbort(BackoffRunnable backoffRunnable)
BackoffRunnable is now with Error.
When BackoffRunnable goes to Error state, the BackoffScheduler will remove the FastRecovery
task and log the error. This object then, must schedule the next queued Runnable for that key, or dispose the
scheduler if it was the last one.fastRecoveryAbort in interface FastRecoveryObserverbackoffRunnable - the BackoffRunnable with Error.public void dispose()
dispose in interface org.mule.runtime.api.lifecycle.Disposablepublic static SchedulingConfiguration delayInitialScheduling(int initialDelay)
public static SchedulingConfiguration zeroDelayOnScheduling()
Copyright © 2014–2021 MuleSoft, Inc.. All rights reserved.