de.esprit.netsuite.server.batch

## Class AbstractServerBatchTask<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>
            - - de.esprit.netsuite.server.batch.AbstractServerBatchTask<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:
    AbstractDatabaseBatchTask, LogCleanupBatchTask, TestBatchTask

      public abstract class AbstractServerBatchTask<S extends ServerContext>
      extends AbstractRemoteTask<S>

  This is the base class for time scheduled server batch Processes. These Processes are configured externally in the `file`. Batch-processes are queued for execution in `ServerBatchTaskExecutor`, a special single-thread-executor that runs only one task at a time. Because the executor may be kept busy by a task for an unpredictable time there is no guarantee about the exact execution start time of the next task scheduled. Tasks that are willing to run just got to wait until the executor is free again. `AbstractServerBatchTask`s send `ServerBatchTaskEvent`s to all clients that have been registered for the `NetMessageType.SERVER_BATCH_TASK_EVENT`.
  Author:
    Rainer Buesch
  See Also:
    `NetMessageType`

- - ### Field Summary

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

      `childTaskRef, isTestMode, monitorController, resultRef, stateFlag`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractServerBatchTask(S serverCtx, ServerBatchTaskConfigEntry cfgEntry)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected TaskMonitor` | `createTaskMonitor()`
    `protected void` | `doOnCancel()` This method is called after having detected cancellation.
    `protected void` | `doOnFinish()` Is called in ANY CASE when the task has finished.
    `protected void` | `doOnStart()` Is called when the task actually has started.
    `boolean` | `equals(java.lang.Object obj)` Two server processes have unique Names.
    `protected java.util.concurrent.ScheduledFuture` | `getCurrentFuture()` Returns the `Future` of this task as returned by the thread-pool.
    `ServerBatchTaskConfigEntry` | `getProcessConfigEntry()`
    `int` | `hashCode()`
    `ResourceLock` | `lockDataSource(java.lang.String dataSourceName)`
    `void` | `notifyProgress(int step, int maxSteps, java.lang.String message)` Convenience method
    `void` | `notifyProgress(java.lang.String message)`
    `void` | `releaseLock(ResourceLock lock)`
    `DataSourceEntry` | `resetToDefaultDataSource()`
    `DataSourceEntry` | `resetToPreviousDataSource()`
    `DataSourceEntry` | `selectDataSource(java.lang.String dataSourceName)`
    `void` | `setConfigEntry(ServerBatchTaskConfigEntry newProcCfg)`
    `RemoteTaskId` | `submitForDirectExecution(SessionId sessionId)` Runs this task immediately in to the `ServerBatchTaskExecutor`.
    `void` | `submitForScheduledExecution()` (re)schedules this task for running periodically.
    `ToString` | `toString(ToString s)` This method allows subclasses to add values to the existing ToString of the superclass.

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

      `addMonitor, cancel, createRunStateFlag, createTaskId, getKillerSessionId, getOwnerSessionId, getRunStateFlag, getSessionId, getTaskId, setSessionId, submit, submit`

    - ### 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, doOnSuccess, executeAsync, executeChildTask, executeChildTask, getMaxChildTasks, getPriority, getProcessingDuration, getStartTime, getStopWatch, handleFinish, handleStart, handleSuccess, isRegisterForCancel, isRunning, notifyProceeded, registerTask, releaseStart, run, setCurrentFuture, setMaxChildTasks, setPriority, setRegisterForCancel, setReleaseTimeout, submitInternal, wasSucceeded`

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

      `checkCancelled, checkForErrorAndRethrow, clearMonitors, 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, finalize, getClass, 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`

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

      `getServerContext`

- - ### Constructor Detail

    - #### AbstractServerBatchTask

          public AbstractServerBatchTask(S serverCtx,
                                 ServerBatchTaskConfigEntry cfgEntry)

  - ### Method Detail

    - #### createTaskMonitor

          protected TaskMonitor createTaskMonitor()

      Overrides:
        `createTaskMonitor` in class `AbstractRemoteTask<S extends ServerContext>`

    - #### getCurrentFuture

          protected java.util.concurrent.ScheduledFuture getCurrentFuture()

      Description copied from class: `AbstractAsyncTask`
      Returns the `Future` of this task as returned by the thread-pool.
      Overrides:
        `getCurrentFuture` in class `AbstractAsyncTask<S extends ServerContext>`

    - #### getProcessConfigEntry

          public ServerBatchTaskConfigEntry getProcessConfigEntry()

    - #### setConfigEntry

          public void setConfigEntry(ServerBatchTaskConfigEntry newProcCfg)

    - #### selectDataSource

          public DataSourceEntry selectDataSource(java.lang.String dataSourceName)
                                           throws InvalidDataSourceException,
                                                  ResourceLockedException

      Throws:
        `InvalidDataSourceException`
        `ResourceLockedException`

    - #### resetToDefaultDataSource

          public DataSourceEntry resetToDefaultDataSource()
                                                   throws InvalidDataSourceException,
                                                          ResourceLockedException

      Throws:
        `InvalidDataSourceException`
        `ResourceLockedException`

    - #### resetToPreviousDataSource

          public DataSourceEntry resetToPreviousDataSource()
                                                    throws InvalidDataSourceException,
                                                           ResourceLockedException

      Throws:
        `InvalidDataSourceException`
        `ResourceLockedException`

    - #### lockDataSource

          public ResourceLock lockDataSource(java.lang.String dataSourceName)
                                      throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### releaseLock

          public void releaseLock(ResourceLock lock)
                           throws NotLockOwnerException

      Throws:
        `NotLockOwnerException`

    - #### notifyProgress

          public void notifyProgress(int step,
                            int maxSteps,
                            java.lang.String message)

      Convenience method

    - #### notifyProgress

          public void notifyProgress(java.lang.String message)

    - #### doOnStart

          protected void doOnStart()
                            throws java.lang.Exception

      Description copied from class: `AbstractAsyncTask`
      Is called when the task actually has started. Maybe overridden to perform any task preparation. Note that an Exception thrown here will cause the task to fail.
      Overrides:
        `doOnStart` in class `AbstractAsyncTask<S extends ServerContext>`
      Throws:
        `java.lang.Exception`

    - #### doOnCancel

          protected void doOnCancel()

      Description copied from class: `AbstractAsyncExecutable`
      This method is called after having detected cancellation. May be overridden to perform any cleanup. Note that any Exceptions thrown are caught and just logged but do NOT affect the task.
      Overrides:
        `doOnCancel` in class `AbstractAsyncExecutable<S extends ServerContext>`

    - #### doOnFinish

          protected void doOnFinish()

      Description copied from class: `AbstractAsyncTask`
      Is called in ANY CASE when the task has finished. Maybe overridden to perform any task finalization. Note that any Exceptions thrown are caught and just logged but do NOT affect the task.
      Overrides:
        `doOnFinish` in class `AbstractAsyncTask<S extends ServerContext>`

    - #### submitForDirectExecution

          public RemoteTaskId submitForDirectExecution(SessionId sessionId)
                                                throws java.lang.Exception

      Runs this task immediately in to the `ServerBatchTaskExecutor`. Note that this task runs ONLY ONCE and is NOT scheduled for later execution.
      Parameters:
        `sessionId` - the current task owner
      Throws:
        `java.lang.Exception`

    - #### submitForScheduledExecution

          public void submitForScheduledExecution()

      (re)schedules this task for running periodically. The server itself will be the owner of the task.

    - #### equals

          public boolean equals(java.lang.Object obj)

      Two server processes have unique Names. Identifying them by name prevents scheduling them twice!
      Overrides:
        `equals` in class `java.lang.Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `java.lang.Object`

    - #### toString

          public ToString toString(ToString s)

      Description copied from interface: `Dumpable`
      This method allows subclasses to add values to the existing ToString of the superclass. Usually subclasses only need to override this method.
      Specified by:
        `toString` in interface `Dumpable`
      Overrides:
        `toString` in class `AbstractAsyncTask<S extends ServerContext>`

Copyright © 2013 EsprIT-Systems. All Rights Reserved.