de.esprit.netsuite.rtask

## Class AbstractRemoteTask<S extends ServerContext>

- java.lang.Object
- - de.esprit.common.util.DumpableObject
  - - de.esprit.appsuite.launch.AbstractApplicationObject<C>
    - - de.esprit.appsuite.task.AbstractAsyncExecutable<C>
      - - de.esprit.appsuite.task.AbstractAsyncTask<S>
        - - de.esprit.netsuite.rtask.AbstractServerTask<S>
          - - de.esprit.netsuite.rtask.AbstractRemoteTask<S>

- All Implemented Interfaces:
    ApplicationObject<S>, AsyncExecutable<S>, AsyncTask<S>, CancellableTask, LocalCancellableTask, TaskMonitorSupport, TaskIdHolder, SimpleLogSupport, Dumpable, Executable, RemoteCancellableTask, RemoteTask<S>, ServerObject<S>, java.lang.Runnable
  Direct Known Subclasses:
    AbstractBatchTask, AbstractJournalTask, AgentExecutorTask, CoServerBindTask, RemoteArchiveExtractTask, RemoteArchiveListTask

      public abstract class AbstractRemoteTask<S extends ServerContext>
      extends AbstractServerTask<S>
      implements RemoteTask<S>

  This is an `AsyncTask` which runs on server side and is owned by a user session. You may attach a `RemoteTaskMonitor` if it should send `RemoteTaskEvent`s to the client for synchronization purposes. By default no monitor is attached.
  Author:
    Rainer Buesch

- - ### Field Summary

    - ### Fields inherited from class de.esprit.appsuite.task.AbstractAsyncExecutable

      `childTaskRef, isTestMode, monitorController, resultRef, stateFlag`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractRemoteTask(S serverCtx, LogChannel logCh, RemoteTaskType taskType, SessionId sessionId)`
    `AbstractRemoteTask(S serverCtx, LogChannel logCh, java.lang.String taskName, RemoteTaskType taskType, SessionId sessionId)`
    `AbstractRemoteTask(S serverCtx, RemoteTaskType taskType, SessionId sessionId)`
    `AbstractRemoteTask(S serverCtx, SessionId sessionId)`
    `AbstractRemoteTask(S serverCtx, java.lang.String taskName, RemoteTaskType taskType, SessionId sessionId)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addMonitor(TaskMonitor monitor)` Adds a `TaskMonitor` which is notified about `RunStateFlag` changes
    `void` | `cancel(SessionId killerSessId)` Cancels the running task and stores the `SessionId` of the killer.
    `protected RunStateFlag` | `createRunStateFlag()` Creates the `RunStateFlag` instance of this task.
    `protected RemoteTaskId` | `createTaskId()` Is called at submit time.
    `protected TaskMonitor` | `createTaskMonitor()`
    `SessionId` | `getKillerSessionId()` Returns the `SessionId` of the one who cancelled this task
    `SessionId` | `getOwnerSessionId()` Returns the `SessionId` of the session that owns this task.
    `RemoteRunStateFlag` | `getRunStateFlag()` Returns the current `RunStateFlag`.
    `SessionId` | `getSessionId()` Returns the `SessionId` of the Session that submitted this task
    `RemoteTaskId` | `getTaskId()` Returns an identifier object for this task.
    `void` | `setSessionId(SessionId sessionId)` Allows subtasks to set the sessionId explicitly.
    `RemoteTaskId` | `submit()` Submits this task for execution to the default application thread pool
    `RemoteTaskId` | `submit(java.util.concurrent.ExecutorService pool)` Submits this task for execution to the given thread pool

    - ### Methods inherited from class de.esprit.netsuite.rtask.AbstractServerTask

      `executeSubTask, getServerContext`

    - ### Methods inherited from class de.esprit.appsuite.task.AbstractAsyncTask

      `awaitFinished, awaitFinished, awaitStarted, cancel, deregisterTask, doOnFinish, doOnStart, doOnSuccess, executeAsync, executeChildTask, executeChildTask, getCurrentFuture, getMaxChildTasks, getPriority, getProcessingDuration, getStartTime, getStopWatch, handleFinish, handleStart, handleSuccess, isRegisterForCancel, isRunning, notifyProceeded, registerTask, releaseStart, run, setCurrentFuture, setMaxChildTasks, setPriority, setRegisterForCancel, setReleaseTimeout, submitInternal, toString, wasSucceeded`

    - ### Methods inherited from class de.esprit.appsuite.task.AbstractAsyncExecutable

      `checkCancelled, checkForErrorAndRethrow, clearMonitors, doOnCancel, doOnFailure, execute, executeSubTask, getError, getMaxProgressSteps, getMonitorCount, getMonitors, getName, getProgressStepCount, getResult, getType, handleCancellation, handleFailure, hasError, hasMonitor, isCancellable, registerTaskStateChange, removeMonitor, resetProgress, setCancellable, setLogLevel, setMaxProgressSteps, setMonitor, setName, setName, setResult, setRunStateFlag, setTaskId, setType, shouldFireMonitor, sleepChecked, wasCancelled`

    - ### Methods inherited from class de.esprit.appsuite.launch.AbstractApplicationObject

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

    - ### Methods inherited from class de.esprit.common.util.DumpableObject

      `configureDumpHeadlineLength, configureDumpMaxElementsPrinted, copyDumpStringValues, copyToStringValues, createDumpHeader, toDumpString, toDumpString, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

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

      `awaitFinished, awaitFinished, awaitStarted, executeChildTask, executeChildTask, getError, getProcessingDuration, hasError, isRegisterForCancel, isRunning, releaseStart, setName, setReleaseTimeout`

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

      `checkCancelled, checkForErrorAndRethrow, executeAsync, executeSubTask, getName, getResult, 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

      `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.common.type.Dumpable

      `toDumpString, toDumpString, toString, toString`

    - ### Methods inherited from interface de.esprit.netsuite.server.ServerObject

      `getServerContext`

- - ### Constructor Detail

    - #### AbstractRemoteTask

          public AbstractRemoteTask(S serverCtx,
                            SessionId sessionId)

    - #### AbstractRemoteTask

          public AbstractRemoteTask(S serverCtx,
                            RemoteTaskType taskType,
                            SessionId sessionId)

    - #### AbstractRemoteTask

          public AbstractRemoteTask(S serverCtx,
                            LogChannel logCh,
                            RemoteTaskType taskType,
                            SessionId sessionId)

    - #### AbstractRemoteTask

          public AbstractRemoteTask(S serverCtx,
                            java.lang.String taskName,
                            RemoteTaskType taskType,
                            SessionId sessionId)

    - #### AbstractRemoteTask

          public AbstractRemoteTask(S serverCtx,
                            LogChannel logCh,
                            java.lang.String taskName,
                            RemoteTaskType taskType,
                            SessionId sessionId)

  - ### Method Detail

    - #### addMonitor

          public final void addMonitor(TaskMonitor monitor)

      Description copied from interface: `TaskMonitorSupport`
      Adds a `TaskMonitor` which is notified about `RunStateFlag` changes
      Specified by:
        `addMonitor` in interface `TaskMonitorSupport`
      Overrides:
        `addMonitor` in class `AbstractAsyncExecutable<S extends ServerContext>`

    - #### createTaskMonitor

          protected TaskMonitor createTaskMonitor()

    - #### cancel

          public void cancel(SessionId killerSessId)

      Description copied from interface: `RemoteCancellableTask`
      Cancels the running task and stores the `SessionId` of the killer. Note that this call puts the task in a CANCEL_REQUESTED state. The task itself needs to detect this and perform any action needed for canceling itself - after all it puts itself in the cancelled state and terminates. The method `CancellableTask.wasCancelled()` returns true once a cancel was requested.
      Specified by:
        `cancel` in interface `RemoteCancellableTask`

    - #### createTaskId

          protected RemoteTaskId createTaskId()

      Description copied from class: `AbstractAsyncTask`
      Is called at submit time. Each submit of a task creates a new `TaskId` which is added to the `RunStateFlag`.
      Overrides:
        `createTaskId` in class `AbstractAsyncTask<S extends ServerContext>`

    - #### submit

          public RemoteTaskId submit()
                              throws java.lang.Exception

      Description copied from interface: `AsyncTask`
      Submits this task for execution to the default application thread pool
      Specified by:
        `submit` in interface `AsyncTask<S extends ServerContext>`
      Specified by:
        `submit` in interface `RemoteTask<S extends ServerContext>`
      Overrides:
        `submit` in class `AbstractAsyncTask<S extends ServerContext>`
      Throws:
        `java.lang.Exception` - if the pool is busy

    - #### submit

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

      Description copied from interface: `AsyncTask`
      Submits this task for execution to the given thread pool
      Specified by:
        `submit` in interface `AsyncTask<S extends ServerContext>`
      Specified by:
        `submit` in interface `RemoteTask<S extends ServerContext>`
      Overrides:
        `submit` in class `AbstractAsyncTask<S extends ServerContext>`
      Throws:
        `java.lang.Exception` - if the pool is busy

    - #### createRunStateFlag

          protected final RunStateFlag createRunStateFlag()

      Description copied from class: `AbstractAsyncExecutable`
      Creates the `RunStateFlag` instance of this task. Is only called once at construction time.
      Overrides:
        `createRunStateFlag` in class `AbstractAsyncExecutable<S extends ServerContext>`

    - #### getRunStateFlag

          public RemoteRunStateFlag getRunStateFlag()

      Description copied from interface: `AsyncExecutable`
      Returns the current `RunStateFlag`. Note that there is exactly one `RunStateFlag` per running task. Child-tasks as well as sub-tasks share it with their parents.
      Specified by:
        `getRunStateFlag` in interface `AsyncExecutable<S extends ServerContext>`
      Specified by:
        `getRunStateFlag` in interface `RemoteTask<S extends ServerContext>`
      Overrides:
        `getRunStateFlag` in class `AbstractAsyncExecutable<S extends ServerContext>`

    - #### setSessionId

          public void setSessionId(SessionId sessionId)

      Allows subtasks to set the sessionId explicitly. Is required if task runs in a ScheduledExecutor.

    - #### getOwnerSessionId

          public SessionId getOwnerSessionId()

      Description copied from interface: `RemoteTask`
      Returns the `SessionId` of the session that owns this task. Note the difference to `RemoteTask.getSessionId()`. A task that runs i.e. in a `CoClientContext` might have the `SessionId` of that context. But the real owner-id of the task is the `SessionId` of the user that is logged in on the server!
      Specified by:
        `getOwnerSessionId` in interface `RemoteTask<S extends ServerContext>`
      See Also:
        `RemoteTask.getSessionId()`

    - #### getSessionId

          public SessionId getSessionId()

      Description copied from interface: `RemoteTask`
      Returns the `SessionId` of the Session that submitted this task
      Specified by:
        `getSessionId` in interface `RemoteTask<S extends ServerContext>`
      See Also:
        `RemoteTask.getOwnerSessionId()`

    - #### getKillerSessionId

          public SessionId getKillerSessionId()

      Description copied from interface: `RemoteCancellableTask`
      Returns the `SessionId` of the one who cancelled this task
      Specified by:
        `getKillerSessionId` in interface `RemoteCancellableTask`

    - #### getTaskId

          public RemoteTaskId getTaskId()

      Description copied from interface: `AsyncExecutable`
      Returns an identifier object for this task. Note: The `TaskId` is used to model the task-hierarchy in a `RunStateFlag`. For `AsyncExecutable`s it's always an instance of `PseudoTaskId`.
      Specified by:
        `getTaskId` in interface `AsyncExecutable<S extends ServerContext>`
      Specified by:
        `getTaskId` in interface `TaskIdHolder`
      Specified by:
        `getTaskId` in interface `RemoteTask<S extends ServerContext>`
      Overrides:
        `getTaskId` in class `AbstractAsyncExecutable<S extends ServerContext>`

Copyright © 2014 EsprIT-Systems. All Rights Reserved.