org.globus.exec.monitoring
Class JobStateMonitor

java.lang.Object
  extended byorg.globus.exec.monitoring.JobStateMonitor

public class JobStateMonitor
extends java.lang.Object


Field Summary
private static long CACHE_FLUSH_PERIOD
          Period of time between running the cache flush task.
private  java.util.SortedSet cachedEvents
          Time-sorted soft-state cache of events
private  java.util.TimerTask cacheFlushTask
          Cache flushing task.
private  EventDispatchQueue dispatchQueue
          EventDispatchQueue which will take all events that must be dispatched to avoid blocking in the JobStateMonitor
private  java.util.Date lastEventTimestamp
          Timestamp of the last dispatched event.
private  JobStateChangeListener listener
          JobStateChangeListener which will be notified of job state changes for registered job IDs.
private static org.apache.commons.logging.Log logger
           
private  java.util.HashMap mapping
          Mapping of Job IDs to Object keys
private static int MAX_CACHE_AGE
          Maximum age of the oldest event in the soft-state cache.
private static long RECOVERY_PERIOD
          Period of time between running the recovery update task.
private  JobStateRecoveryListener recoveryListener
          JobStateRecoveryListener which will be notified when the JSM decides that its recovery information should be updated.
private  java.util.TimerTask recoveryTask
          Recovery data update task.
private  SchedulerEventGenerator seg
          Reference to the SEG-monitoring thread.
private static java.util.Timer timer
          Timer to handle all cache flushing and recovery timestamp update tasks.
 
Constructor Summary
private JobStateMonitor()
          Private constructor
 
Method Summary
(package private)  void addEvent(SchedulerEvent e)
           
private  void cacheEvent(SchedulerEvent e)
          Store an event in the JobStateMonitor's cache
private  void flushCache()
           
private  java.util.List getCachedEvents(java.lang.String localId)
          Get all cached events associated with a Job ID.
static JobStateMonitor getInstance(java.io.File globusLocation, java.lang.String userName, java.lang.String schedulerName, JobStateChangeListener listener, JobStateRecoveryListener recoveryListener, boolean segDaemon)
          Construct a new JobStateMonitor.
 JobStateChangeListener getListener()
           
(package private)  ResourceKey getMapping(java.lang.String localId)
          Look up the localId to ResourceKey mapping for a specified id.
(package private)  void initialize(java.io.File globusLocation, java.lang.String userName, java.lang.String schedulerName, JobStateChangeListener listener, JobStateRecoveryListener recoveryListener, SchedulerEventGenerator seg)
          Initializes a new JobStateMonitor.
 void registerJobID(java.lang.String localId, ResourceKey resourceKey)
          Register a mapping from local scheduler job ID to a resource key.
 void start(java.util.Date timestamp)
          Start processing SEG events.
 void stop()
          Stop processing SEG events.
 void unregisterJobID(java.lang.String localId)
          Unregister a local scheduler job ID for event propagation.
private  void updateRecoveryInfo()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static org.apache.commons.logging.Log logger

seg

private SchedulerEventGenerator seg
Reference to the SEG-monitoring thread.


listener

private JobStateChangeListener listener
JobStateChangeListener which will be notified of job state changes for registered job IDs.


dispatchQueue

private EventDispatchQueue dispatchQueue
EventDispatchQueue which will take all events that must be dispatched to avoid blocking in the JobStateMonitor


recoveryListener

private JobStateRecoveryListener recoveryListener
JobStateRecoveryListener which will be notified when the JSM decides that its recovery information should be updated.


mapping

private java.util.HashMap mapping
Mapping of Job IDs to Object keys


cachedEvents

private java.util.SortedSet cachedEvents
Time-sorted soft-state cache of events


MAX_CACHE_AGE

private static final int MAX_CACHE_AGE
Maximum age of the oldest event in the soft-state cache.

See Also:
Constant Field Values

CACHE_FLUSH_PERIOD

private static final long CACHE_FLUSH_PERIOD
Period of time between running the cache flush task.

See Also:
Constant Field Values

RECOVERY_PERIOD

private static final long RECOVERY_PERIOD
Period of time between running the recovery update task.

See Also:
Constant Field Values

timer

private static java.util.Timer timer
Timer to handle all cache flushing and recovery timestamp update tasks.


cacheFlushTask

private java.util.TimerTask cacheFlushTask
Cache flushing task. Every CACHE_FLUSH_PERIOD milliseconds, cache entries older than MAX_CACHE_AGE will be discarded.


recoveryTask

private java.util.TimerTask recoveryTask
Recovery data update task. Every RECOVERY_PERIOD milliseconds, recoveryListener's updateJobMonitorRecoveryTimeStamp() will be called to have it update the persistent state of the JobStateMonitor.


lastEventTimestamp

private java.util.Date lastEventTimestamp
Timestamp of the last dispatched event. This timestamp is used as the safe-recovery timestamp when the soft-state event cache is empty, but some events have been dispatched to their JobStateChangeListener or discarded from the soft-state cache by the cacheFlushTask.

Constructor Detail

JobStateMonitor

private JobStateMonitor()
Private constructor

Method Detail

getInstance

public static JobStateMonitor getInstance(java.io.File globusLocation,
                                          java.lang.String userName,
                                          java.lang.String schedulerName,
                                          JobStateChangeListener listener,
                                          JobStateRecoveryListener recoveryListener,
                                          boolean segDaemon)
Construct a new JobStateMonitor. The new JobStateMonitor will not begin the Scheduler Event Generator automatically. Services which create a JobStateMonitor may register any number of job ID mappings before calling start() to start the SEG.

Parameters:
globusLocation - Path to the Globus Toolkit installation.
userName - User name that the SEG should run as (via sudo(8)). (Currently ignored).
schedulerName - Name of the scheduler SEG module to use.
listener - Reference to the JobStateChangeListener which will be notified when notifications relating to Job ID which has a mapping registered to it.
recoveryListener - Reference to a JobStateRecoveryListener which will be notified periodically when the JobStateMonitor wants to update its recovery checkpoint timestamp.
segDaemon - Indicates whether to make the SEG a daemon thread or not

initialize

void initialize(java.io.File globusLocation,
                java.lang.String userName,
                java.lang.String schedulerName,
                JobStateChangeListener listener,
                JobStateRecoveryListener recoveryListener,
                SchedulerEventGenerator seg)
Initializes a new JobStateMonitor.

Parameters:
globusLocation - Path to the Globus Toolkit installation.
userName - User name that the SEG should run as (via sudo(8)). (Currently ignored).
schedulerName - Name of the scheduler SEG module to use.
listener - Reference to the JobStateChangeListener which will be notified when notifications relating to Job ID which has a mapping registered to it.
recoveryListener - Reference to a JobStateRecoveryListener which will be notified periodically when the JobStateMonitor wants to update its recovery checkpoint timestamp.
seg - SchedulerEventGenerator corresponding to that JobStateMonitor

registerJobID

public void registerJobID(java.lang.String localId,
                          ResourceKey resourceKey)
                   throws AlreadyRegisteredException
Register a mapping from local scheduler job ID to a resource key. Once this method has been called for a particular local job identifier, the JobStateChangeListener associated with the JobStatemonitor may receive notifications until the unregisterJobIDMap method has been called.

Parameters:
localId - Local job identifier. This is presumably generated by the scheduler when the job is created.
resourceKey - Resource key associated with the job. This object will be passed to the JobStateChangeListener's jobStateChange method.
Throws:
AlreadyRegisteredException

start

public void start(java.util.Date timestamp)
           throws java.lang.IllegalThreadStateException
Start processing SEG events. Starts the SEG thread processing events from the scheduler, as well as some background tasks to flush cache of old job events and to update the persistent timestamp used for restarting the JobStateMonitor.

Parameters:
timestamp - Date from which to start processing events. If null, then the SEG will process events generated from the time the function is called.
Throws:
java.lang.IllegalThreadStateException - This method has already been called.

stop

public void stop()
          throws java.io.IOException
Stop processing SEG events. Blocks the current thread until the SEG has terminated. No furthur SEG events will be issued after method returns until the start() method is called again.

Throws:
java.io.IOException

flushCache

private void flushCache()

updateRecoveryInfo

private void updateRecoveryInfo()

getCachedEvents

private java.util.List getCachedEvents(java.lang.String localId)
Get all cached events associated with a Job ID.

Parameters:
localId - Job identifier to look up.
Returns:
Returns a list of SchedulerEvents associated with the Job ID.

unregisterJobID

public void unregisterJobID(java.lang.String localId)
                     throws NotRegisteredException
Unregister a local scheduler job ID for event propagation. Once this method has been called for a particular local job identifier, the JobStateChangeListener associated with the JobStatemonitor will no longer receive notifications about this job.

Parameters:
localId - Local job identifier.
Throws:
NotRegisteredException

cacheEvent

private void cacheEvent(SchedulerEvent e)
Store an event in the JobStateMonitor's cache


getMapping

ResourceKey getMapping(java.lang.String localId)
Look up the localId to ResourceKey mapping for a specified id.


addEvent

void addEvent(SchedulerEvent e)

getListener

public JobStateChangeListener getListener()