de.esprit.appsuite.task

## Interface AsyncTask<C extends ApplicationContext>

- All Superinterfaces:
    ApplicationObject<C>, AsyncExecutable<C>, CancellableTask, Dumpable, Executable, LocalCancellableTask, java.lang.Runnable, SimpleLogSupport, TaskIdHolder, TaskMonitorSupport
  All Known Subinterfaces:
    JournalTask<S>, RemoteTask<S>, RemoteTaskEventReceiver<C>, WorkflowTask<C>
  All Known Implementing Classes:
    AbstractAsciiDownloadTask, AbstractAsciiParserWFT, AbstractAsyncTask, AbstractBatchTask, AbstractBinaryDownloadTask, AbstractClientEDT, AbstractClientTask, AbstractClientWFT, AbstractClientWorkflow, AbstractDatabaseBatchTask, AbstractDataParserWFT, AbstractDownloadTask, AbstractEventDrivenWFT, AbstractFileStreamWFT, AbstractJavaCommandWFT, AbstractJournalOsProcessTask, AbstractJournalTask, AbstractOsProcessTask, AbstractOsProcessWFT, AbstractRemoteOsProcessTask, AbstractRemoteTask, AbstractServerTask, AbstractStreamParserWFT, AbstractSwingTask, AbstractTaskOptionDialogWFT, AbstractTaskOptionWFT, AbstractTimerTask, AbstractWFT, AbstractWorkflow, AbstractZipArchiverWFT, AgentExecutorTask, AgentWatchDogTask, AppLaunchTask, AppLaunchTask.MyNativeProcessTask, ArchiveConfigDialogWFT, ArchiveExtractTask, ArchiveExtractWFT, ArchiveExtractWorkflow, ArchiveListTask, ArchiveListWFT, ArchiveListWorkflow, AsciiParserTask, CheckWorkingDirectoryWFT, CleanupWorkingDirectoryWFT, ClientCommandTask, CoClientReconnectorTask, CoServerBindTask, CreateZipArchiveWFT, CreateZipArchiveWorkflow, DataParserTask, DBLoadTask, ExecutorTask, FileDownloadWFT, FileDownloadWorkflow, FileNameInputWFT, FileTransferClientTask, FileTransferTask, FileTransferWFT, FileUploadWFT, FileUploadWorkflow, GuiReconnectorTask, InputFileChooserWFT, JavaCommandTask, LogCleanupBatchTask, MessageReceiveTask, OutputFileChooserWFT, ProgressWindowExecutorTask, RemoteArchiveExtractEDT, RemoteArchiveExtractTask, RemoteArchiveExtractWFT, RemoteArchiveExtractWorkflow, RemoteArchiveListEDT, RemoteArchiveListTask, RemoteArchiveListWFT, RemoteArchiveListWorkflow, RemoteJavaCommandTask, RequestServiceTask, StdinReaderTask, SwingExecutorTask, TaskCollection, TestBatchTask, TransferServiceTask, WatchDogTask, ZipArchiverTask

      public interface AsyncTask<C extends ApplicationContext>
      extends AsyncExecutable<C>, java.lang.Runnable, LocalCancellableTask, TaskIdHolder, Dumpable, SimpleLogSupport

  This interface defines an asynchronous task that may run in any `ExecutorService`.
  Author:
    Rainer Buesch

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `<R> R` | `awaitFinished()` Waits non-interruptibly until the task has finished.
    `<R> R` | `awaitFinished(long timeout, java.util.concurrent.TimeUnit unit)` Waits until the task has finished but runs in a TimeoutException if it did not finish within the expected time.
    `void` | `awaitStarted()` Waits until the task has actually started running.
    `void` | `executeChildTask(AsyncTask childTask)` Runs the child-task in the default executor of the `ApplicationContext`.
    `void` | `executeChildTask(AsyncTask childTask, java.util.concurrent.ExecutorService pool)` Runs the child-task asynchronously as a task on it's own.
    `java.lang.Exception` | `getError()` Returns the execution error of this task which is only available if the task failed.
    `long` | `getProcessingDuration()` Tells how long the task has been running since STARTED
    `boolean` | `hasError()` Tells whether the task failed and contains an execution error
    `boolean` | `isRegisterForCancel()` Tells whether this task should be registered for cancel within the `TaskManager`.
    `boolean` | `isRunning()` Returns true from the time on the task has been submitted until it has finished.
    `void` | `releaseStart()` Releases the task for execution after submission.
    `void` | `setName(NlsKey trKey, java.lang.Object... args)` Set name of task by translation.
    `void` | `setReleaseTimeout(long releaseTimeoutMillis)` Defines a timeout for waiting on the release gate after having started.
    `TaskId` | `submit()` Submits this task for execution to the default application thread pool
    `TaskId` | `submit(java.util.concurrent.ExecutorService pool)` Submits this task for execution to the given thread pool

    - ### Methods inherited from interface de.esprit.appsuite.task.AsyncExecutable

      `checkCancelled, checkForErrorAndRethrow, executeAsync, executeSubTask, getName, getResult, getRunStateFlag, getTaskId, getType, handleCancellation, handleFailure, isCancellable, notifyProceeded, setCancellable, setName, setResult, setRunStateFlag, sleepChecked`

    - ### Methods inherited from interface de.esprit.appsuite.launch.ApplicationObject

      `getApplicationContext`

    - ### Methods inherited from interface de.esprit.common.type.Executable

      `execute`

    - ### Methods inherited from interface de.esprit.appsuite.task.monitor.TaskMonitorSupport

      `addMonitor, clearMonitors, getMonitorCount, getMonitors, hasMonitor, removeMonitor`

    - ### Methods inherited from interface de.esprit.common.log.SimpleLogSupport

      `getLogChannel, isLogDebug, isLogVerbose, logDebug, logDump, logError, logError, logFatal, logInfo, logVerbose, logWarning, setLogChannel`

    - ### Methods inherited from interface java.lang.Runnable

      `run`

    - ### Methods inherited from interface de.esprit.appsuite.task.LocalCancellableTask

      `cancel`

    - ### Methods inherited from interface de.esprit.appsuite.task.CancellableTask

      `wasCancelled`

    - ### Methods inherited from interface de.esprit.appsuite.task.TaskIdHolder

      `getTaskId`

    - ### Methods inherited from interface de.esprit.common.type.Dumpable

      `toDumpString, toDumpString, toString, toString`

- - ### Method Detail

    - #### setName

          void setName(NlsKey trKey,
                     java.lang.Object... args)

      Set name of task by translation.

    - #### awaitStarted

          void awaitStarted()
                            throws java.lang.InterruptedException

      Waits until the task has actually started running.
      Throws:
        `java.lang.InterruptedException`

    - #### awaitFinished

          <R> R awaitFinished()

      Waits non-interruptibly until the task has finished. Returns the result of this task, if any. If the task is cancelled, waiting is interrupted and a null is returned.
      Returns:
        the result of this task, if any or null if the task was cancelled.
      Throws:
        `java.lang.InterruptedException`

    - #### awaitFinished

          <R> R awaitFinished(long timeout,
                            java.util.concurrent.TimeUnit unit)
                          throws java.lang.InterruptedException,
                                 java.util.concurrent.TimeoutException

      Waits until the task has finished but runs in a TimeoutException if it did not finish within the expected time. When the task runs into a timeout it is automatically cancelled.
      Returns:
        the result of this task, if any or null if the task was cancelled or is timed out.
      Throws:
        `java.lang.InterruptedException`
        `java.util.concurrent.TimeoutException`
      See Also:
        `awaitFinished()`

    - #### getError

          java.lang.Exception getError()

      Returns the execution error of this task which is only available if the task failed.

    - #### hasError

          boolean hasError()

      Tells whether the task failed and contains an execution error

    - #### getProcessingDuration

          long getProcessingDuration()

      Tells how long the task has been running since STARTED

    - #### isRegisterForCancel

          boolean isRegisterForCancel()

      Tells whether this task should be registered for cancel within the `TaskManager`. If it is not registered, then it won't be cancellable any more.

    - #### setReleaseTimeout

          void setReleaseTimeout(long releaseTimeoutMillis)

      Defines a timeout for waiting on the release gate after having started. If set to a positive value, then the task would wait on the release gate until the timeout is exceeded or `releaseStart()` is being called explicitly. This allows for getting the `TaskId` on submit but having more control about the actual start time of the task. By default the task does not wait on the release gate.
      See Also:
        `releaseStart()`

    - #### releaseStart

          void releaseStart()

      Releases the task for execution after submission.
      See Also:
        `setReleaseTimeout(long)`

    - #### executeChildTask

          void executeChildTask(AsyncTask childTask)
                                throws java.lang.Exception

      Runs the child-task in the default executor of the `ApplicationContext`.
      Throws:
        `java.lang.Exception`
      See Also:
        `executeChildTask(AsyncTask, ExecutorService)`

    - #### executeChildTask

          void executeChildTask(AsyncTask childTask,
                              java.util.concurrent.ExecutorService pool)
                                throws java.lang.Exception

      Runs the child-task asynchronously as a task on it's own. The main-task blocks until the child-task has completed. The child-task shares the `RunStateFlag` with the main-task. As the child-task runs in a different execution thread it has got it's own `TaskId` which is added to the main-TaskId. canceling the main-task in fact cancels the child-task too. During child-task execution the monitor will receive CHILD_STARTED, CHILD_SUCCEEDED and CHILD_FINISHED notifications. Any PROGRESS notifications in between are associated to the current child-task.
      Throws:
        `java.lang.Exception`

    - #### isRunning

          boolean isRunning()

      Returns true from the time on the task has been submitted until it has finished. Thus it reflects the time frame where we have got a valid TaskId.

    - #### submit

          TaskId submit(java.util.concurrent.ExecutorService pool)
                        throws java.lang.Exception

      Submits this task for execution to the given thread pool
      Throws:
        `java.lang.Exception` - if the pool is busy

    - #### submit

          TaskId submit()
                        throws java.lang.Exception

      Submits this task for execution to the default application thread pool
      Throws:
        `java.lang.Exception` - if the pool is busy

Copyright © 2014 EsprIT-Systems. All Rights Reserved.