Package org.apache.camel.support.task
Class ForegroundTask
java.lang.Object
org.apache.camel.support.task.ForegroundTask
- All Implemented Interfaces:
BlockingTask,Task
Runs a task in the foreground, executing for a given number of iteration and sleeping between each of them.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder helper for building new foreground tasksNested classes/interfaces inherited from interface org.apache.camel.support.task.Task
Task.Status -
Method Summary
Modifier and TypeMethodDescriptionprotected booleandoRun(BooleanSupplier supplier) elapsed()How long it took to run the task when the task was completedlongThe current computed delay.longThe current elapsed time.The task failed for some un-expected exceptionlongThe time the first attempt was performed.longThe time the last attempt has been performed.getName()Optional name of the tasklongAn indication about the time the next attempt will be made.Gets the task status.booleanWhether the task has been submitted for running (the state of the task can be waiting for next run etc).intThe current number of iterations (such as when the task is being repeated)booleanrun(org.apache.camel.CamelContext camelContext, BooleanSupplier supplier) Run the task<T> Optional<T> Run a task until it produces a resultMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.camel.support.task.BlockingTask
runMethods inherited from interface org.apache.camel.support.task.Task
getCurrentElapsedTime, getException, getFirstAttemptTime, getLastAttemptTime, getName, getNextAttemptTime, getStatus
-
Method Details
-
run
Description copied from interface:BlockingTaskRun the task- Specified by:
runin 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
-
run
public <T> Optional<T> run(org.apache.camel.CamelContext camelContext, Supplier<T> supplier, Predicate<T> predicate) Run a task until it produces a result- Type Parameters:
T- the type for the result- Parameters:
camelContext- the camel contextsupplier- the supplier of the resultpredicate- a predicate to test if the result is acceptable- Returns:
- An optional with the result
-
isRunning
public boolean isRunning()Description copied from interface:BlockingTaskWhether the task has been submitted for running (the state of the task can be waiting for next run etc).- Specified by:
isRunningin interfaceBlockingTask- Returns:
- true if the run method has been called.
-
elapsed
Description copied from interface:TaskHow long it took to run the task when the task was completed -
iteration
public int iteration()Description copied from interface:TaskThe current number of iterations (such as when the task is being repeated) -
getCurrentDelay
public long getCurrentDelay()Description copied from interface:TaskThe current computed delay.- Specified by:
getCurrentDelayin interfaceTask
-
getName
Description copied from interface:TaskOptional name of the task -
getStatus
Description copied from interface:TaskGets the task status. -
getFirstAttemptTime
public long getFirstAttemptTime()Description copied from interface:TaskThe time the first attempt was performed.- Specified by:
getFirstAttemptTimein interfaceTask
-
getLastAttemptTime
public long getLastAttemptTime()Description copied from interface:TaskThe time the last attempt has been performed.- Specified by:
getLastAttemptTimein interfaceTask
-
getNextAttemptTime
public long getNextAttemptTime()Description copied from interface:TaskAn indication about the time the next attempt will be made.- Specified by:
getNextAttemptTimein interfaceTask
-
getCurrentElapsedTime
public long getCurrentElapsedTime()Description copied from interface:TaskThe current elapsed time.- Specified by:
getCurrentElapsedTimein interfaceTask
-
getException
Description copied from interface:TaskThe task failed for some un-expected exception- Specified by:
getExceptionin interfaceTask
-