com.sun.grid.jgrid.server
Class JCEPProtocolModule

java.lang.Object
  extended bycom.sun.grid.jgrid.server.JCEPProtocolModule
All Implemented Interfaces:
JCEP
Direct Known Subclasses:
JCEPVersion10Module

public abstract class JCEPProtocolModule
extends java.lang.Object
implements JCEP

This class defines the interface for classes which which to implement a JCEP service. JCEP stands for JGrid Compute Engine Protocol. It is a simple protocol which allows a client and server to send commands and job information over a socket connection.

Since:
0.2

Field Summary
private static byte CURRENT_VERSION
          The lastest version of the JCEP protocol.
private static java.util.logging.Logger log
          The logging mechanism
private static byte MIN_VERSION
          The minimum version of the JCEP protocol supported by the protocol module factory.
protected static java.util.List moduleList
          The list of JCEPProtocolModules with open client connections.
static java.lang.String SYSTEM_ID
          Used with logMessage() and logError() to indicated that the message comes from the JCEPProtocolModule, not from a Job.
 
Fields inherited from interface com.sun.grid.jgrid.server.JCEP
CANCEL_JOB, CHECKPOINT_JOB, COMMAND_FAILED, HANDSHAKE, JOB_CHECKPOINTED, JOB_STATE_CHANGE, LOG_ERROR, LOG_MESSAGE, PORT, REGISTER, RESUME, SHUTDOWN, SHUTTING_DOWN, STATE_COMPLETED, STATE_FAILED, STATE_RUNNING, STATE_STOPPED, STATE_SUSPENDED, SUBMIT_JOB, SUSPEND, UNREGISTER, VERSION10
 
Constructor Summary
JCEPProtocolModule()
           
 
Method Summary
(package private) abstract  void closeConnection()
          This method shuts down the protocol module.
private static byte doHandshake(java.io.DataInputStream din, java.io.DataOutputStream dout)
          This method confirms that the client is attempting to establish a JCEP communication channel and establishes the version of JCEP to use.
(package private) static JCEPProtocolModule establishConnection(JCEPListener engine, java.net.Socket socket)
          Establishes a connection to the client over the given socket and sets the handler for the connection.
(package private) abstract  void logError(java.lang.String jobId, java.lang.String error)
          Tells the protocol module to notify its client of an error from an executing job.
(package private) abstract  void logMessage(java.lang.String jobId, java.lang.String message)
          Tells the protocol module to notify its client of a message from an executing job.
protected static void notifyAllModules()
          This method is used to propogate a shutdown notice to all open protocol modules.
(package private) abstract  void notifyJobCheckpointed(java.lang.String jobId)
          Tells the protocol module to notify its client that a job has been checkpointed.
(package private) abstract  void notifyJobCompleted(java.lang.String jobId)
          Tells the protocol module to notify its client that a job has completed execution normally.
(package private) abstract  void notifyJobFailed(java.lang.String jobId)
          Tells the protocol module to notify its client that a job has terminated execution abnormally because of an error during execution.
(package private) abstract  void notifyJobResumed(java.lang.String jobId)
          Tells the protocol module to notify its client that a job has been resumed.
(package private) abstract  void notifyJobStarted(java.lang.String jobId)
          Tells the protocol module to notify its client that a job has started execution.
(package private) abstract  void notifyJobStopped(java.lang.String jobId)
          Tells the protocol module to notify its client that a job has terminated execution abnormally by being canceled.
(package private) abstract  void notifyJobSuspended(java.lang.String jobId)
          Tells the protocol module to notify its client that a job has been suspended.
(package private) abstract  void notifyShutdown()
          Tells the protocol module to notify its client that server is shutting down.
(package private) abstract  void startConnection()
          This method tells the protocol module to begin reading messages from the established connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SYSTEM_ID

public static final java.lang.String SYSTEM_ID
Used with logMessage() and logError() to indicated that the message comes from the JCEPProtocolModule, not from a Job.

See Also:
Constant Field Values

CURRENT_VERSION

private static final byte CURRENT_VERSION
The lastest version of the JCEP protocol.

See Also:
Constant Field Values

MIN_VERSION

private static final byte MIN_VERSION
The minimum version of the JCEP protocol supported by the protocol module factory.

See Also:
Constant Field Values

log

private static java.util.logging.Logger log
The logging mechanism


moduleList

protected static java.util.List moduleList
The list of JCEPProtocolModules with open client connections. Used to notify all clients of a server shutdown.

Constructor Detail

JCEPProtocolModule

public JCEPProtocolModule()
Method Detail

establishConnection

static JCEPProtocolModule establishConnection(JCEPListener engine,
                                              java.net.Socket socket)
                                       throws java.io.IOException
Establishes a connection to the client over the given socket and sets the handler for the connection.

Parameters:
engine - The JCEPListener to use for sending command requests from the client
socket - The socket on which to connect to the client
Returns:
A JCEPProtocolModule object that encapsulates the client communications for the JCEPHandler
Throws:
java.io.IOException - Thrown then the connection cannot be established

doHandshake

private static byte doHandshake(java.io.DataInputStream din,
                                java.io.DataOutputStream dout)
                         throws java.io.IOException
This method confirms that the client is attempting to establish a JCEP communication channel and establishes the version of JCEP to use.

Parameters:
din - Input stream from the socket
dout - Output stream to the socket
Returns:
Returns the JCEP version code to be used
Throws:
java.io.IOException - Thrown is there's an error during the handshake process

notifyAllModules

protected static void notifyAllModules()
This method is used to propogate a shutdown notice to all open protocol modules.


startConnection

abstract void startConnection()
                       throws java.io.IOException
This method tells the protocol module to begin reading messages from the established connection.

Throws:
java.io.IOException - Thrown if there's an error starting up the connection

closeConnection

abstract void closeConnection()
                       throws java.io.IOException
This method shuts down the protocol module. It causes the protocol module to stop reading and closes the input and output streams.

Throws:
java.io.IOException - Thrown is there's an error closing the input or output streams

logMessage

abstract void logMessage(java.lang.String jobId,
                         java.lang.String message)
                  throws java.io.IOException
Tells the protocol module to notify its client of a message from an executing job. Used by the JCEPHandler.

Parameters:
jobId - The id of the job from which the message originated
message - The text of the message
Throws:
java.io.IOException - Thrown if there's an error sending the message to the client
See Also:
JCEPHandler

logError

abstract void logError(java.lang.String jobId,
                       java.lang.String error)
                throws java.io.IOException
Tells the protocol module to notify its client of an error from an executing job. Used by the JCEPHandler.

Parameters:
error - The text of the error message
jobId - The id of the job from which the error originated
Throws:
java.io.IOException - Thrown if there's an error sending the error message to the client
See Also:
JCEPHandler

notifyJobStarted

abstract void notifyJobStarted(java.lang.String jobId)
                        throws java.io.IOException
Tells the protocol module to notify its client that a job has started execution. Used by the JCEPHandler.

Parameters:
jobId - The id of the job which started
Throws:
java.io.IOException - Thrown if there's an error sending the message to the client
See Also:
JCEPHandler

notifyJobCompleted

abstract void notifyJobCompleted(java.lang.String jobId)
                          throws java.io.IOException
Tells the protocol module to notify its client that a job has completed execution normally. Used by the JCEPHandler.

Parameters:
jobId - The id of the job which completed execution
Throws:
java.io.IOException - Thrown if there's an error sending the message to the client
See Also:
JCEPHandler

notifyJobCheckpointed

abstract void notifyJobCheckpointed(java.lang.String jobId)
                             throws java.io.IOException
Tells the protocol module to notify its client that a job has been checkpointed. Used by the JCEPHandler.

Parameters:
jobId - The id of the job which was checkpointed
Throws:
java.io.IOException - Thrown if there's an error sending the message to the client
See Also:
JCEPHandler

notifyJobStopped

abstract void notifyJobStopped(java.lang.String jobId)
                        throws java.io.IOException
Tells the protocol module to notify its client that a job has terminated execution abnormally by being canceled. Used by the JCEPHandler.

Parameters:
jobId - The id of the job which has stopped execution
Throws:
java.io.IOException - Thrown if there's an error sending the message to the client
See Also:
JCEPHandler

notifyJobFailed

abstract void notifyJobFailed(java.lang.String jobId)
                       throws java.io.IOException
Tells the protocol module to notify its client that a job has terminated execution abnormally because of an error during execution. Used by the JCEPHandler.

Parameters:
jobId - The id of the job which has stopped execution
Throws:
java.io.IOException - Thrown if there's an error sending the message to the client
See Also:
JCEPHandler

notifyJobSuspended

abstract void notifyJobSuspended(java.lang.String jobId)
                          throws java.io.IOException
Tells the protocol module to notify its client that a job has been suspended. Used by the JCEPHandler.

Parameters:
jobId - The id of the job which has stopped suspended execution
Throws:
java.io.IOException - Thrown if there's an error sending the message to the client
See Also:
JCEPHandler

notifyJobResumed

abstract void notifyJobResumed(java.lang.String jobId)
                        throws java.io.IOException
Tells the protocol module to notify its client that a job has been resumed. Used by the JCEPHandler.

Parameters:
jobId - The id of the job which has resumed execution
Throws:
java.io.IOException - Thrown if there's an error sending the message to the client
See Also:
JCEPHandler

notifyShutdown

abstract void notifyShutdown()
                      throws java.io.IOException
Tells the protocol module to notify its client that server is shutting down. Used by the JCEPHandler.

Throws:
java.io.IOException - Thrown if there's an error sending the message to the client
See Also:
JCEPHandler