Overview | Package | Class | Use | Tree | Deprecated | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.developmentontheedge.jobcontrol
Class AbstractJobControl

    java.lang.Object
      com.developmentontheedge.jobcontrol.AbstractJobControl

All Implemented Interfaces:
  JobControl, java.lang.Runnable

Direct Known Subclasses:
  ClassJobControl, FunctionJobControl

public abstract class AbstractJobControl
extends java.lang.Object
implements JobControl

AbstractJobControl is default implementation of JobControl interface. AbstractJobControl provides base functionality of all methods of JobControl

Version:
  1.0
Author:
  DevelopmentOnTheEdge

Field Summary
`protected org.apache.log4j.Category` | `cat` The `log4j.Category` to print logs.
`protected boolean` | `isTerminated`
`protected int` | `preparedness`
`protected int` | `runStatus` deferred current status of job control
`protected java.util.Date` | `startedDate`
`protected int` | `status` Current status of JobControl

Fields inherited from interface com.developmentontheedge.jobcontrol.JobControl
`COMPLETED, CREATED, PAUSED, RUNNING, TERMINATED_BY_ERROR, TERMINATED_BY_REQUEST`

Constructor Summary
`AbstractJobControl(org.apache.log4j.Category cat)` Constructs JobControl with specified Category
`AbstractJobControl(org.apache.log4j.Category cat, JobControlListener listener)` Constructs JobControl with specified Category and JobControlListener

Method Summary
`void` | `addListener(JobControlListener listener)` Adds JobControlListener object
`void` | `begin()` Derived classes should call this method when they want to start controlled process
`protected void` | `begin(java.lang.String msg)` Derived classes should call this method when they want to start controlled process with any message
`void` | `checkStatus()` Tests status of job control.
`protected abstract void` | `doRun()` This method should implement derived classess for real controlled process running
`void` | `end()` Sets state defined by runStatus variable.
`protected void` | `end(java.lang.String msg)` Sets state defined by runStatus variable.
`protected void` | `exceptionOccured(JobControlException ex)` Sets variable runStatus to the current status of job control Call this method when changing of state is needed
`protected void` | `fireJobPaused()` Notifies all listeners that job is paused.
`protected void` | `fireJobResumed()` Notifies all listeners that job is resumed
`protected void` | `fireJobStarted(java.lang.String msg)` Notifies all listeners that job is started.
`protected void` | `fireJobTerminated(java.lang.String msg)` Notifies all listeners that job is terminated.
`void` | `fireValueChanged()` Notifies all listeners that value returned by `getPreparedness()` is changed
`static java.lang.String` | `format(long time)` Converts time to the string
`static java.lang.String` | `format(long time, java.lang.String format)` Converts time to the specified format string
`long` | `getCreatedTime()` Returns JobControl created time.
`long` | `getElapsedTime()` Returns elapsed time of Job
`long` | `getEndedTime()` Returns Job finished time
`int` | `getPreparedness()` Returns preparedness of Job in percent
`long` | `getRemainedTime()` Returns estimated remained time
`long` | `getStartedTime()` Returns Job start time
`int` | `getStatus()` Returns status of Job
`java.lang.String` | `getTextStatus()` Returns string representation of Job status
`protected boolean` | `isStatusTerminated()` Returns whether status is terminated
`void` | `pause()` Sets status of job control to the `JobControl.PAUSED` state
`protected void` | `reset()` Sets status of job in `JobControl.CREATED` state
`protected void` | `resetFlags()` Sets isTerminated,isPaused variables to false
`void` | `resultsAreReady()`
`void` | `resume()` Sets status of job control to the `JobControl.RUNNING` state
`void` | `run()` Starts the job control process
`protected void` | `setCompleted()` Sets `JobControl.COMPLETED` state of job status
`void` | `setPreparedness(int percent)` Sets value of job Preparednes
`protected void` | `setTerminated(int status)` Sets status of JobControl
`void` | `terminate()` Sets status of job control to the `JobControl.TERMINATED_BY_REQUEST` state

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### cat

    protected org.apache.log4j.Category cat

  The `log4j.Category` to print logs.

### startedDate

    protected java.util.Date startedDate

### status

    protected int status

  Current status of JobControl

### runStatus

    protected int runStatus

  deferred current status of job control

### preparedness

    protected int preparedness

### isTerminated

    protected boolean isTerminated

Constructor Detail

### AbstractJobControl

    public AbstractJobControl(org.apache.log4j.Category cat)

  Constructs JobControl with specified Category

Parameters:
  `cat` - log Category of log4j package

### AbstractJobControl

    public AbstractJobControl(org.apache.log4j.Category cat,
                              JobControlListener listener)

  Constructs JobControl with specified Category and JobControlListener

Parameters:
  `cat` - log Category of log4j package
  `listener` - specified JobControlListener

Method Detail

### doRun

    protected abstract void doRun()
                           throws JobControlException

  This method should implement derived classess for real controlled process running

  Throws:
    `JobControlException` - If the process wants to stop the task,or error is occured.

### begin

    public void begin()

  Derived classes should call this method when they want to start controlled process

### begin

    protected void begin(java.lang.String msg)

  Derived classes should call this method when they want to start controlled process with any message

  Parameters:
    `msg` - is used for listeners notification

### exceptionOccured

    protected void exceptionOccured(JobControlException ex)

  Sets variable runStatus to the current status of job control Call this method when changing of state is needed

  Parameters:
    `ex` - JobControlException sended exception

### isStatusTerminated

    protected boolean isStatusTerminated()

  Returns whether status is terminated

  Returns:
    true if current status is one of
    - `JobControl.CREATED`
    - `JobControl.COMPLETED`
    - `JobControl.TERMINATED_BY_REQUEST`
    - `JobControl.TERMINATED_BY_ERROR`

### end

    public void end()

  Sets state defined by runStatus variable. Notifies all listeners about state changing

### end

    protected void end(java.lang.String msg)

  Sets state defined by runStatus variable. Notifies all listeners about state changing using specified message

  Parameters:
    `msg` - specified message

### run

    public void run()

  Starts the job control process

  Specified by:
    `run` in interface `java.lang.Runnable`

### pause

    public void pause()

  Sets status of job control to the `JobControl.PAUSED` state

  Specified by:
    `pause` in interface `JobControl`

### resume

    public void resume()

  Sets status of job control to the `JobControl.RUNNING` state

  Specified by:
    `resume` in interface `JobControl`

### terminate

    public void terminate()

  Sets status of job control to the `JobControl.TERMINATED_BY_REQUEST` state

  Specified by:
    `terminate` in interface `JobControl`

### getStatus

    public int getStatus()

  Description copied from interface: `JobControl`
  Returns status of Job

  Specified by:
    `getStatus` in interface `JobControl`
  Returns:
    one of following values:
    - `JobControl.CREATED`
    - `JobControl.RUNNING`
    - `JobControl.PAUSED`
    - `JobControl.COMPLETED`
    - `JobControl.TERMINATED_BY_REQUEST`
    - `JobControl.TERMINATED_BY_ERROR`

### getTextStatus

    public java.lang.String getTextStatus()

  Description copied from interface: `JobControl`
  Returns string representation of Job status

  Specified by:
    `getTextStatus` in interface `JobControl`

### getPreparedness

    public int getPreparedness()

  Description copied from interface: `JobControl`
  Returns preparedness of Job in percent

  Specified by:
    `getPreparedness` in interface `JobControl`
  Returns:
    percent value

### getCreatedTime

    public long getCreatedTime()

  Description copied from interface: `JobControl`
  Returns JobControl created time.

  Specified by:
    `getCreatedTime` in interface `JobControl`
  Returns:
    unix format time

### getStartedTime

    public long getStartedTime()

  Description copied from interface: `JobControl`
  Returns Job start time

  Specified by:
    `getStartedTime` in interface `JobControl`
  Returns:
    unix format time

### getEndedTime

    public long getEndedTime()

  Description copied from interface: `JobControl`
  Returns Job finished time

  Specified by:
    `getEndedTime` in interface `JobControl`
  Returns:
    unix format time

### getElapsedTime

    public long getElapsedTime()

  Description copied from interface: `JobControl`
  Returns elapsed time of Job

  Specified by:
    `getElapsedTime` in interface `JobControl`
  Returns:
    unix format time

### getRemainedTime

    public long getRemainedTime()

  Description copied from interface: `JobControl`
  Returns estimated remained time

  Specified by:
    `getRemainedTime` in interface `JobControl`
  Returns:
    unix format time

### addListener

    public void addListener(JobControlListener listener)

  Description copied from interface: `JobControl`
  Adds JobControlListener object

  Specified by:
    `addListener` in interface `JobControl`
  Parameters:
    `listener` - added listener

### fireJobStarted

    protected void fireJobStarted(java.lang.String msg)

  Notifies all listeners that job is started.

  Parameters:
    `msg` - notified message

### fireJobPaused

    protected void fireJobPaused()

  Notifies all listeners that job is paused.

### fireJobResumed

    protected void fireJobResumed()

  Notifies all listeners that job is resumed

### fireValueChanged

    public void fireValueChanged()

  Notifies all listeners that value returned by `getPreparedness()` is changed

### fireJobTerminated

    protected void fireJobTerminated(java.lang.String msg)

  Notifies all listeners that job is terminated.

  Parameters:
    `msg` - notified message

### setTerminated

    protected void setTerminated(int status)

  Sets status of JobControl

  Parameters:
    `status` - terminated status
    `JobControl.TERMINATED_BY_ERROR`,
    `JobControl.TERMINATED_BY_REQUEST`

### setPreparedness

    public void setPreparedness(int percent)

  Sets value of job Preparednes

  Parameters:
    `percent` - percent of job Preparedness

### resultsAreReady

    public void resultsAreReady()

### setCompleted

    protected void setCompleted()

  Sets `JobControl.COMPLETED` state of job status

### reset

    protected void reset()

  Sets status of job in `JobControl.CREATED` state

### resetFlags

    protected void resetFlags()

  Sets isTerminated,isPaused variables to false

### checkStatus

    public void checkStatus()
                     throws JobControlException

  Tests status of job control. If controlled process is terminated throws JobControlException with status TERMINATED_BY_REQUEST Waits of resuming action, if isPaused variable is set.

  Throws:
    `JobControlException`

### format

    public static java.lang.String format(long time)

  Converts time to the string

  Parameters:
    `time` - Unix time
  Returns:
    converted string

### format

    public static java.lang.String format(long time,
                                          java.lang.String format)

  Converts time to the specified format string

  Parameters:
    `time` - Unix time
    `format` - convert format
  Returns:
    converted string
  See Also:
    `SimpleDateFormat`
  To do:
    low function should standart formatter

Overview | Package | Class | Use | Tree | Deprecated | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2003 Biosof.Ru. All Rights Reserved.