org.peace_tools.core
Class JobMonitor

java.lang.Object
  extended by org.peace_tools.core.JobMonitor
All Implemented Interfaces:
java.lang.Runnable

public class JobMonitor
extends java.lang.Object
implements java.lang.Runnable

A background thread class to monitor job progress. This is a background thread class that is created to monitor the progress of a Job. A job monitor is created either when a work space is loaded (and it has unfinished jobs pending) or when a new job is added to the work space. This class is not directly instantiable. Instead the create() method must be used to create a monitor thread.


Field Summary
private  Job job
          The job that this monitor is monitoring.
private  java.awt.event.ActionListener listener
          The action listener to be notified when this thread exists with a status of FINISHING or ERROR.
private static java.lang.String PURPOSE_MSG
          A static formatable purpose message that is filled in and used as the purpose for the server session initiated by this job monitor.
private  int recheckDelay
          The delay in milliseconds for which the main thread must sleep before checking back for updates.
private  Server server
          Information regarding the server on which the job (that this monitor is monitoring) is running.
private  ServerSession session
          The session (local/remote) to the server on which the job is running.
 
Constructor Summary
private JobMonitor(Job job, Server server, java.awt.event.ActionListener listener)
          The constructor merely initializes the instance variables to default values.
 
Method Summary
static boolean create(Job job, java.awt.event.ActionListener listener)
          The primary API method to create a job monitor thread.
private  boolean createSession()
          This is a helper method that is periodically invoked to check and create a session to the remote server.
static java.lang.Thread getMonitor(Job job)
          Method to obtain an existing monitor thread for this job.
static void interrupt(Job job)
          Convenience method to interrupt a job monitor thread.
 void run()
           
private  boolean updateJobStatus()
          Helper method to run the jobRunner script on the remote machine and obtain the operational status of the job.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

job

private final Job job
The job that this monitor is monitoring. This value is set in the constructor and is never changed during the life time of this object/thread.


listener

private final java.awt.event.ActionListener listener
The action listener to be notified when this thread exists with a status of FINISHING or ERROR.


server

private final transient Server server
Information regarding the server on which the job (that this monitor is monitoring) is running. This value is set in the constructor and is never changed during the life time of this object/thread.


session

private transient ServerSession session
The session (local/remote) to the server on which the job is running. The session is created when the thread starts up.


recheckDelay

private transient int recheckDelay
The delay in milliseconds for which the main thread must sleep before checking back for updates. This value is halved each time progress is discovered until this value falls to 250 milliseconds. Otherwise the value is doubled until this value reaches 120,000 milliseconds.


PURPOSE_MSG

private static final java.lang.String PURPOSE_MSG
A static formatable purpose message that is filled in and used as the purpose for the server session initiated by this job monitor.

See Also:
Constant Field Values
Constructor Detail

JobMonitor

private JobMonitor(Job job,
                   Server server,
                   java.awt.event.ActionListener listener)
The constructor merely initializes the instance variables to default values. The constructor has been made private to ensure this class is instantiated only via the create method.

Parameters:
job - The job to be monitored by this job monitor.
listener - The action listener to be notified when this thread exits.
server - Information regarding the server on which this job is allegedly running.
Method Detail

create

public static boolean create(Job job,
                             java.awt.event.ActionListener listener)
The primary API method to create a job monitor thread. This method serves as the primary API for creating a Job monitor thread. This method creates an instance of this class as a low priority daemon thread. The thread runs asynchronously periodically monitoring the job progress.

Parameters:
job - Information regarding the job to be monitored.
listener - The action listener to be notified when the job has completed and this thread is about to be exited. The action event posted has the command set to "JobMonitor" and the object is set to the Job that has completed.
Returns:
This method returns true if the thread was started.

interrupt

public static void interrupt(Job job)
Convenience method to interrupt a job monitor thread. This method is a convenience method to interrupt the operations of a job monitoring thread.

Parameters:
job - The job whose monitoring thread is to be interrupted.

getMonitor

public static java.lang.Thread getMonitor(Job job)
Method to obtain an existing monitor thread for this job. This method is a convenience method that can be used to obtain the job monitor associated with a given job.

Parameters:
job - The job whose job monitor thread is to be returned.
Returns:
The job thread (if any) associated with the job. If the job does not have a monitor thread associated with this then this method returns null.

run

public void run()
Specified by:
run in interface java.lang.Runnable

updateJobStatus

private boolean updateJobStatus()
Helper method to run the jobRunner script on the remote machine and obtain the operational status of the job. This method is periodically invoked from the main run() method.

Returns:
This method returns true if the status changed.

createSession

private boolean createSession()
This is a helper method that is periodically invoked to check and create a session to the remote server. This method sets up the instance variable session once a valid connection to the local/remote server is established.

Note: If a valid session could not be established this method will simply sleep for 5 minutes before returning control.

Returns:
This method returns false if the calling outer loop must stop because the user interrupted or canceled the session.