com.sun.grid.jgrid.proxy
Class ComputeServer

java.lang.Object
  extended byjava.rmi.server.RemoteObject
      extended byjava.rmi.server.RemoteServer
          extended byjava.rmi.server.UnicastRemoteObject
              extended bycom.sun.grid.jgrid.proxy.ComputeServer
All Implemented Interfaces:
ComputeEngine, java.rmi.Remote, java.io.Serializable

public class ComputeServer
extends java.rmi.server.UnicastRemoteObject
implements ComputeEngine

This class is the central contact point for clients wishing to run jobs on the grid. It offers the ability to run jobs synchonously and asynchronously and to check on the results of jobs.

Since:
0.2.1
See Also:
Serialized Form

Nested Class Summary
private static class ComputeServer.Lock
          This class is used by ComputeServer to wait for jobs to complete.
 
Field Summary
private static int channel_port
          The port for the return data channel RMI registry
private static boolean debug
          Whether debug information should be printed
private static java.lang.String jobPath
          The path to the serialized job files
private static java.util.Map lockbox
          A place to store Lock objects referenced by job id.
private static java.util.logging.Logger log
          The logging mechanism
static java.lang.String LOOKUP_NAME
          The name under which the ComputeServer registers in the RMI registry
private static long nextProcessId
          The next job id to be assigned
private static int server_port
          The port on which to start the fake server
private static java.lang.String skeletonCommand
          The command for the grid engine execution engine to run on the execution host
private static java.lang.String submitCommand
          The command used to submit job to the grid engine queue
private static java.lang.String USAGE
          The usage information String
 
Fields inherited from class java.rmi.server.UnicastRemoteObject
 
Fields inherited from class java.rmi.server.RemoteServer
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
ComputeServer()
          Creates a new instance of ComputeServer
 
Method Summary
 java.io.Serializable compute(Computable computable)
          This method should never be called.
 java.io.Serializable compute(Computable computable, java.lang.String codebase)
          This method submits a job for synchrnous execution.
 java.lang.String computeAsynch(Computable job)
          This method should never be called.
 java.lang.String computeAsynch(Computable computable, java.lang.String codebase)
          This method submits a job for asynchronous execution.
private static java.lang.String[] createCommandStringArray(java.lang.String[] parts)
          Creates a command string array from the given arguments
private  void deleteJob(java.lang.String id)
          This method removes a job from the lockbox and disk.
private static void flushLogs()
          This methods flushes the logs
private static java.lang.String getNextProcessId()
          This method returns the next job id
private static java.lang.Object getResult(java.lang.String processId)
          This method waits for the job to complete and returns the results
 java.io.Serializable getResults(java.lang.String jobId)
          This method retrieves the results of a job that was executed asynchronously.
 boolean isComplete(java.lang.String jobId)
          This method check whether an asynchronous job has finished executing.
static void main(java.lang.String[] args)
          The main method creates a registry on 1100 for return channel communications and creates a registry on 1099 to receive RMI calls.
private static void prepareLogging()
          This method sets up the Logger object
private static void processArguments(java.lang.String[] args)
          This method processes the command line arguments and sets the appropriate variables
private static void setLock(java.lang.String processId)
          This method creates a Lock object for the job and stores it in the lockbox
private  java.lang.Object submitJob(Job job)
          Submits the job to the DRM.
private  void writeJobToDisk(Job job, java.lang.String annotation)
          This method serializes the Job object to disk at the location given by jobPath.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LOOKUP_NAME

public static final java.lang.String LOOKUP_NAME
The name under which the ComputeServer registers in the RMI registry

See Also:
Constant Field Values

USAGE

private static final java.lang.String USAGE
The usage information String

See Also:
Constant Field Values

log

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


lockbox

private static java.util.Map lockbox
A place to store Lock objects referenced by job id. When a job comes in, a Lock is created and placed in the lockbox under the job id. The server thread then waits on that Lock (if synchronous). The ResultChannelImpl notifies the Lock when the ComputeEngineImpl returns a result.

See Also:
ResultChannelImpl, ComputeServer.Lock

nextProcessId

private static long nextProcessId
The next job id to be assigned


jobPath

private static java.lang.String jobPath
The path to the serialized job files


submitCommand

private static java.lang.String submitCommand
The command used to submit job to the grid engine queue


skeletonCommand

private static java.lang.String skeletonCommand
The command for the grid engine execution engine to run on the execution host


server_port

private static int server_port
The port on which to start the fake server


channel_port

private static int channel_port
The port for the return data channel RMI registry


debug

private static boolean debug
Whether debug information should be printed

Constructor Detail

ComputeServer

public ComputeServer()
              throws java.rmi.RemoteException
Creates a new instance of ComputeServer

Throws:
java.rmi.RemoteException - thrown when an RMI error occurs
Method Detail

main

public static void main(java.lang.String[] args)
The main method creates a registry on 1100 for return channel communications and creates a registry on 1099 to receive RMI calls.

Parameters:
args - the command line arguments

processArguments

private static void processArguments(java.lang.String[] args)
This method processes the command line arguments and sets the appropriate variables

Parameters:
args - The args array from main()

prepareLogging

private static void prepareLogging()
This method sets up the Logger object


flushLogs

private static void flushLogs()
This methods flushes the logs


getNextProcessId

private static java.lang.String getNextProcessId()
This method returns the next job id

Returns:
the next job id

createCommandStringArray

private static java.lang.String[] createCommandStringArray(java.lang.String[] parts)
Creates a command string array from the given arguments

Parameters:
parts - The arguments to reassemble into a command string array
Returns:
the new command string array

compute

public java.io.Serializable compute(Computable computable)
                             throws java.rmi.RemoteException
This method should never be called. It is an artifact of the way the RMI works. In order for this class to be registerable with an RMI registry, it has to implement ComputeEngine, which includes this method. However, the RMI stub and skeleton have been modified to redirect calls to the compute(Computable, String) method instead.

Specified by:
compute in interface ComputeEngine
Parameters:
computable - the job to compute
Returns:
never actually returns
Throws:
java.rmi.RemoteException - thrown when this method is called

compute

public java.io.Serializable compute(Computable computable,
                                    java.lang.String codebase)
                             throws java.rmi.RemoteException,
                                    ComputeException
This method submits a job for synchrnous execution.

Specified by:
compute in interface ComputeEngine
Parameters:
computable - the job to be executed
codebase - an alternate codebase to use for loading the Computable class
Returns:
the result object
Throws:
java.rmi.RemoteException - if an error occurs on the server side
ComputeException - if an error occurs during job execution

computeAsynch

public java.lang.String computeAsynch(Computable job)
                               throws java.rmi.RemoteException
This method should never be called. It is an artifact of the way the RMI works. In order for this class to be registerable with an RMI registry, it has to implement ComputeEngine, which includes this method. However, the RMI stub and skeleton have been modified to redirect calls to the compute(Computable, String) method instead.

Specified by:
computeAsynch in interface ComputeEngine
Parameters:
job - the job to compute
Returns:
never actually returns
Throws:
java.rmi.RemoteException - thrown when this method is called

computeAsynch

public java.lang.String computeAsynch(Computable computable,
                                      java.lang.String codebase)
                               throws java.rmi.RemoteException,
                                      ComputeException
This method submits a job for asynchronous execution. Job status can be checked with the isComplete method and the results can be retrieved by the getResults method.

Specified by:
computeAsynch in interface ComputeEngine
Parameters:
codebase - an alternate codebase to use for loading the Computable class
computable - the job to be executed
Returns:
the result object
Throws:
java.rmi.RemoteException - if an error occurs on the server side
ComputeException - if an error occurs during job execution

getResults

public java.io.Serializable getResults(java.lang.String jobId)
                                throws java.rmi.RemoteException,
                                       ComputeException
This method retrieves the results of a job that was executed asynchronously.

Specified by:
getResults in interface ComputeEngine
Parameters:
jobId - the id of the job
Returns:
the results object
Throws:
java.rmi.RemoteException - if an error occurs on the server side
ComputeException - if an error occurs during job execution

isComplete

public boolean isComplete(java.lang.String jobId)
                   throws java.rmi.RemoteException,
                          ComputeException
This method check whether an asynchronous job has finished executing.

Specified by:
isComplete in interface ComputeEngine
Parameters:
jobId - the id of the job
Returns:
whether the job has finished
Throws:
java.rmi.RemoteException - if an error occurs on the server side
ComputeException - if an error occurs during job execution

submitJob

private java.lang.Object submitJob(Job job)
                            throws java.io.IOException
Submits the job to the DRM.

Parameters:
job - the object to be executed
Returns:
the results of running the job
Throws:
java.io.IOException - thrown if the job cannot be spooled

writeJobToDisk

private void writeJobToDisk(Job job,
                            java.lang.String annotation)
                     throws java.io.IOException
This method serializes the Job object to disk at the location given by jobPath. The job file name is the job id.

Parameters:
job - the job to be serialized
annotation - the location of the client class files
Throws:
java.io.IOException - if an error occurs while writing the job to disk

setLock

private static void setLock(java.lang.String processId)
This method creates a Lock object for the job and stores it in the lockbox

Parameters:
processId - the id of the job for which to create a lock

getResult

private static java.lang.Object getResult(java.lang.String processId)
This method waits for the job to complete and returns the results

Parameters:
processId - the job id
Returns:
results of the job

deleteJob

private void deleteJob(java.lang.String id)
                throws java.io.IOException
This method removes a job from the lockbox and disk.

Parameters:
id - the id of the job to remove
Throws:
java.io.IOException - if an error occurs while removing the job from disk