com.sun.grid.jgrid
Class Job

java.lang.Object
  extended bycom.sun.grid.jgrid.Job
All Implemented Interfaces:
java.lang.Runnable, java.io.Serializable

public class Job
extends java.lang.Object
implements java.lang.Runnable, java.io.Serializable

This class represents a job to be executed by the compute engine.

See Also:
Serialized Form

Field Summary
private  java.lang.String annotation
          The URL from whence the Computable implementation was loaded
private  boolean asynch
          Whether this job is to be executed asynchronously or not
static int COMPLETE
          The job has completed normally
private  java.lang.Thread computeThread
          The thread under which this Job runs.
static int ERROR
          The Job was stopped due to an error during execution
private  java.lang.String filename
          The absolute filename where the serialized Job is written
private  Computable job
          The object to process
private  java.lang.String jobId
          The id of this job
private  Logger log
          The logging mechanism for jobs
static int NOT_STARTED
          The Job has not been started
private  java.io.Serializable results
          The results returned from the executing Computable
static int RUNNING
          The Job is currently running
private  int state
          The current state of the Job, as represented by NOT_STARTED, RUNNING, STOPPED, COMPLETE, and ERROR
static int STOPPED
          The Job has been stopped before completing
static int STOPPING
          The Job iss being stopped before completing
static int SUSPENDED
          The Job has been suspended
static int SUSPENDING
          The Job is being suspended
 
Constructor Summary
Job(java.lang.String jobId, Computable job)
          Creates a new instance of Job
Job(java.lang.String jobId, Computable job, boolean asynch)
          Creates a new instance of Job
 
Method Summary
 void cancel()
          Notifies this job that it should cancel execution.
 void checkpoint()
          Notifies this job that it should save its state for an upcoming checkpoint.
 boolean completed()
          Checks whether or not this job has completed execution normally.
 java.lang.String getAnnotation()
          Gets the URL from which the Computable implementation was downloaded.
 java.lang.String getFilename()
          Get the path to the serialized Job file
 Computable getJob()
          Returns the object to process
 java.lang.String getJobId()
          Returns the id of this job
 Logger getLogger()
          Returns the logging mechanism to eb used by the Computable for reporting errors and logging messages.
 java.io.Serializable getResult()
          Get the result object returned by the Computable upon successful completion.
 int getState()
          Returns the current state of the Job.
 void interrupt()
          Interrupts the Job thread.
 boolean isAsynch()
          Returns whether or not this job should be executed asynchronously
 void resume()
          Notifies this job that it should resume execution.
 void run()
          This method causes the job to be executed.
 void setAnnotation(java.lang.String annotation)
          Sets the URL from which the Computable implementation was downloaded.
 void setFilename(java.lang.String filename)
          Sets the location for the serialized Job file
 void setLogger(Logger log)
          Sets the logging mechanism to be used by this job
 void suspend()
          Notifies this job that it should suspend execution.
private  void writeJobToDisk()
          Serializes the Job to the location given by filename.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOT_STARTED

public static final int NOT_STARTED
The Job has not been started

See Also:
Constant Field Values

RUNNING

public static final int RUNNING
The Job is currently running

See Also:
Constant Field Values

SUSPENDED

public static final int SUSPENDED
The Job has been suspended

See Also:
Constant Field Values

STOPPED

public static final int STOPPED
The Job has been stopped before completing

See Also:
Constant Field Values

COMPLETE

public static final int COMPLETE
The job has completed normally

See Also:
Constant Field Values

ERROR

public static final int ERROR
The Job was stopped due to an error during execution

See Also:
Constant Field Values

SUSPENDING

public static final int SUSPENDING
The Job is being suspended

See Also:
Constant Field Values

STOPPING

public static final int STOPPING
The Job iss being stopped before completing

See Also:
Constant Field Values

results

private java.io.Serializable results
The results returned from the executing Computable


computeThread

private transient java.lang.Thread computeThread
The thread under which this Job runs. Used to interrupt the executing Computable for checkpoint and cancelation.


filename

private java.lang.String filename
The absolute filename where the serialized Job is written


jobId

private java.lang.String jobId
The id of this job


job

private Computable job
The object to process


asynch

private boolean asynch
Whether this job is to be executed asynchronously or not


log

private transient Logger log
The logging mechanism for jobs


state

private int state
The current state of the Job, as represented by NOT_STARTED, RUNNING, STOPPED, COMPLETE, and ERROR


annotation

private transient java.lang.String annotation
The URL from whence the Computable implementation was loaded

Constructor Detail

Job

public Job(java.lang.String jobId,
           Computable job)
Creates a new instance of Job

Parameters:
jobId - the id of this job
job - the object to process

Job

public Job(java.lang.String jobId,
           Computable job,
           boolean asynch)
Creates a new instance of Job

Parameters:
jobId - the id of this job
job - the object to process
asynch - whether this job should be executed asynchronously
Method Detail

getJobId

public java.lang.String getJobId()
Returns the id of this job

Returns:
this job's id

getJob

public Computable getJob()
Returns the object to process

Returns:
the object to process

isAsynch

public boolean isAsynch()
Returns whether or not this job should be executed asynchronously

Returns:
whether this job should be executed asynchronously

getLogger

public Logger getLogger()
Returns the logging mechanism to eb used by the Computable for reporting errors and logging messages.

Returns:
The Logger object for this Job

setLogger

public void setLogger(Logger log)
Sets the logging mechanism to be used by this job

Parameters:
log - The Logger to be used by this Job

run

public void run()
This method causes the job to be executed.

Specified by:
run in interface java.lang.Runnable

cancel

public void cancel()
            throws NotInterruptableException
Notifies this job that it should cancel execution. This method calls Computable.cancel() and sets the state to STOPPED.

Throws:
NotInterruptableException - Thrown if the Computable does not implement interruption for cancelation.

checkpoint

public void checkpoint()
                throws NotInterruptableException
Notifies this job that it should save its state for an upcoming checkpoint. This method calls Computable.checkpoint() and then serializes this Job to the location determined by filename.

Throws:
NotInterruptableException - Thrown if the Computable does not implement interruption for checkpointing.

suspend

public void suspend()
             throws NotInterruptableException
Notifies this job that it should suspend execution. This method calls Computable.suspend() and sets the state to SUSPENDED.

Throws:
NotInterruptableException - Thrown if the Computable does not implement interruption for suspension.

resume

public void resume()
Notifies this job that it should resume execution. This method calls Computable.resume() and sets the state to RUNNING.


completed

public boolean completed()
Checks whether or not this job has completed execution normally. Functionally equivalent to getState() == COMPLETE.

Returns:
Whether the job completed execution normally

getState

public int getState()
Returns the current state of the Job. The possible values may be:

Returns:
A code indicating the current state of the Job

getResult

public java.io.Serializable getResult()
Get the result object returned by the Computable upon successful completion.

Returns:
The result object returned by the Computable upon successful completion. If the Computable has not completed, or did not complete sucessfully, null is returned.

setFilename

public void setFilename(java.lang.String filename)
Sets the location for the serialized Job file

Parameters:
filename - The absolute path to the serialized Job

getFilename

public java.lang.String getFilename()
Get the path to the serialized Job file

Returns:
The absolute path to the serialized Job

setAnnotation

public void setAnnotation(java.lang.String annotation)
Sets the URL from which the Computable implementation was downloaded.

Parameters:
annotation - The URL from which the Computable implementation was downloaded

getAnnotation

public java.lang.String getAnnotation()
Gets the URL from which the Computable implementation was downloaded.

Returns:
The URL from which the Computable implementation was downloaded

interrupt

public void interrupt()
Interrupts the Job thread. Used by the Computable during cancel(), checkpoint(), suspend(), and resume() operations. Extreme care should be taken with this method as it is possible to interrupt the thread during communications with the native peer, leaving the peer in an unstable state.


writeJobToDisk

private void writeJobToDisk()
                     throws java.io.IOException
Serializes the Job to the location given by filename.

Throws:
java.io.IOException - Thrown is there's an error writing the Job to disk