public interface AsyncExecutable<C extends ApplicationContext> extends ApplicationObject<C>, Executable, CancellableTask, TaskMonitorSupport, SimpleLogSupport
AsyncTask
. Note that this interface does NOT define a cancel() method, because it can
only be cancelled by canceling the AsyncTask
in which it runs.Modifier and Type | Method and Description |
---|---|
void |
checkCancelled()
Throws a
CancellationException when cancellation has been detected. |
void |
checkForErrorAndRethrow(java.lang.Exception e)
Sets the caught Exception into the
RunStateFlag and rethrows it. |
void |
executeAsync()
Contains the code to be executed asynchronously.
|
void |
executeSubTask(AsyncExecutable subTask)
Runs the sub-task synchronously within the same execution thread.
|
java.lang.String |
getName()
Return the task-name which is rendered by the RunStateFlag during run.
|
<R> R |
getResult()
Returns the execution result of this task, if any.
|
RunStateFlag |
getRunStateFlag()
Returns the current
RunStateFlag . |
TaskId |
getTaskId()
Returns an identifier object for this task.
|
TaskType |
getType()
Return the task-type which is rendered by the RunStateFlag during run.
|
void |
handleCancellation()
The implementation calls doOnCancel() in a safe manner, which
is supposed to do any cleanup work.
|
void |
handleFailure(java.lang.Exception error)
The implementation calls doOnFailure(Exception) in a safe manner, which
is supposed to do any cleanup work.
|
boolean |
isCancellable()
Tells whether this task can be cancelled.
|
void |
notifyProceeded(java.lang.Object result,
int step,
int maxSteps,
java.lang.String message)
Notifies progress to an attached
TaskMonitor . |
void |
setCancellable(boolean isCancellable)
Tells whether this task is cancellable - is true by default.
|
void |
setName(java.lang.String name)
Sets the name of this task
|
void |
setResult(java.lang.Object obj)
Stores the execution result of this instance
|
void |
setRunStateFlag(RunStateFlag stateFlag)
Assigns the
RunStateFlag of the executing AsyncTask to this executable. |
void |
sleepChecked(long millis)
Used to delay task execution.
|
getApplicationContext
execute
wasCancelled
addMonitor, clearMonitors, getMonitorCount, getMonitors, hasMonitor, removeMonitor
getLogChannel, isLogDebug, isLogVerbose, logDebug, logDump, logError, logError, logFatal, logInfo, logVerbose, logWarning, setLogChannel
void executeAsync() throws java.lang.Exception
Runnable.run()
for async execution.java.lang.Exception
for synchronous execution
void setRunStateFlag(RunStateFlag stateFlag)
RunStateFlag
of the executing AsyncTask
to this executable.RunStateFlag getRunStateFlag()
RunStateFlag
. Note that there is exactly one
RunStateFlag
per running task. Child-tasks as well as sub-tasks share it with their
parents.void sleepChecked(long millis)
CancellationException
is thrown just in case.void checkCancelled()
CancellationException
when cancellation has been detected.java.lang.String getName()
void setName(java.lang.String name)
TaskType getType()
TaskId getTaskId()
TaskId
is used to model the task-hierarchy in a RunStateFlag
.
For AsyncExecutable
s it's always an instance of PseudoTaskId
.boolean isCancellable()
setCancellable(boolean)
void setCancellable(boolean isCancellable)
<R> R getResult()
setResult(Object)
void setResult(java.lang.Object obj)
getResult()
void handleCancellation()
void handleFailure(java.lang.Exception error)
void checkForErrorAndRethrow(java.lang.Exception e) throws java.lang.Exception
RunStateFlag
and rethrows it.
Note that CancellationException
and InterruptedException
as
well as StopException
are not treated as errors.java.lang.Exception
void notifyProceeded(java.lang.Object result, int step, int maxSteps, java.lang.String message)
TaskMonitor
. This only applies
when the execution is done asynchronously within an AsyncTask
.result
- any intermediate result that may be achieved so farstep
- the count of progress steps (-1 for initializing the progressBar)maxSteps
- the expected maximum number of progress steps (0 if not known)message
- any textual message explaining what the progress isvoid executeSubTask(AsyncExecutable subTask) throws java.lang.Exception
RunStateFlag
with the main-task. During sub-task execution the monitor will receive
CHILD_STARTED CHILD_SUCCEEDED and CHILD_FINISHED notifications. Any PROGRESS notifications in between are
associated to the current sub-task.java.lang.Exception
Copyright © 2014 EsprIT-Systems. All Rights Reserved.