Package org.apache.camel.support.task
Class BackgroundTask
java.lang.Object
org.apache.camel.support.task.BackgroundTask
- All Implemented Interfaces:
BlockingTask
,Task
A sleepless blocking task that runs in a thread in the background (using a scheduled thread pool). The execution is
processed until the task budget is either completed, or exhausted. All background tasks are constrained by a time
budget.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A builder helper for building new background tasksNested classes/interfaces inherited from interface org.apache.camel.support.task.Task
Task.Status
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
doRun
(BooleanSupplier supplier) elapsed()
How long it took to run the task when the task was completedlong
The current computed delay.long
The current elapsed time.The task failed for some un-expected exceptionlong
The time the first attempt was performed.long
The time the last attempt has been performed.getName()
Optional name of the tasklong
An indication about the time the next attempt will be made.Gets the task status.boolean
Whether the task has been submitted for running (the state of the task can be waiting for next run etc).int
The current number of iterations (such as when the task is being repeated)boolean
run
(org.apache.camel.CamelContext camelContext, BooleanSupplier supplier) Run the taskFuture
<?> schedule
(org.apache.camel.CamelContext camelContext, BooleanSupplier supplier) Schedules the task to be runMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.camel.support.task.BlockingTask
run
Methods inherited from interface org.apache.camel.support.task.Task
getCurrentElapsedTime, getException, getFirstAttemptTime, getLastAttemptTime, getName, getNextAttemptTime, getStatus
-
Method Details
-
schedule
Schedules the task to be run- Parameters:
camelContext
- the camel contextsupplier
- the task as a boolean supplier. The result is used to check if the task has completed or not. The supplier must return true if the execution has completed or false otherwise.- Returns:
- a future for the task
-
run
Description copied from interface:BlockingTask
Run the task- Specified by:
run
in interfaceBlockingTask
- Parameters:
camelContext
- the camel contextsupplier
- the task as a boolean supplier. The result is used to check if the task has completed or not. The supplier must return true if the execution has completed or false otherwise.- Returns:
- true if the task has completed successfully or false if: 1) the budget is exhausted or 2) the task was interrupted.
-
doRun
-
isRunning
public boolean isRunning()Description copied from interface:BlockingTask
Whether the task has been submitted for running (the state of the task can be waiting for next run etc).- Specified by:
isRunning
in interfaceBlockingTask
- Returns:
- true if the run method has been called.
-
elapsed
Description copied from interface:Task
How long it took to run the task when the task was completed -
iteration
public int iteration()Description copied from interface:Task
The current number of iterations (such as when the task is being repeated) -
getCurrentDelay
public long getCurrentDelay()Description copied from interface:Task
The current computed delay.- Specified by:
getCurrentDelay
in interfaceTask
-
getName
Description copied from interface:Task
Optional name of the task -
getStatus
Description copied from interface:Task
Gets the task status. -
getFirstAttemptTime
public long getFirstAttemptTime()Description copied from interface:Task
The time the first attempt was performed.- Specified by:
getFirstAttemptTime
in interfaceTask
-
getLastAttemptTime
public long getLastAttemptTime()Description copied from interface:Task
The time the last attempt has been performed.- Specified by:
getLastAttemptTime
in interfaceTask
-
getNextAttemptTime
public long getNextAttemptTime()Description copied from interface:Task
An indication about the time the next attempt will be made.- Specified by:
getNextAttemptTime
in interfaceTask
-
getCurrentElapsedTime
public long getCurrentElapsedTime()Description copied from interface:Task
The current elapsed time.- Specified by:
getCurrentElapsedTime
in interfaceTask
-
getException
Description copied from interface:Task
The task failed for some un-expected exception- Specified by:
getException
in interfaceTask
-