com.sun.grid.jgrid.proxy
Class ComputeProxy

java.lang.Object
  extended bycom.sun.grid.jgrid.proxy.ComputeProxy
All Implemented Interfaces:
java.lang.Runnable

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

This class pretends to be an RMI registry and an RMI server in order to intercept RMI communications and feed them through an instance of the Sun Grid Engine.


Nested Class Summary
private static class ComputeProxy.Lock
          This class is used by ComputeProxyto wait for jobs to complete.
private  class ComputeProxy.StreamException
          This Exception is used to signal that an error occured while reading from the input stream that was not mechanical.
 
Field Summary
private static boolean debug
          Whether debug information should be printed
private static java.rmi.server.ObjID DGC_OID
          The ObjID of the DGC
private static int DGC_OP_CLEAN
          The number of the clean method on the DGCRegistry
private static int DGC_OP_DIRTY
          The number of the dirty method on the DGCRegistry
private static long HASH_COMPUTE
          The method hash for the compute method
private static long HASH_COMPUTEASYNCH
          The method hash for the computeAsynch method
private static long HASH_GETRESULTS
          The method hash for the getResults method
private static long HASH_ISCOMPLETE
          The method hash for the isComplete method
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
private static long nextProcessId
          The next job id to be assigned
private static int port
          The port on which to start the fake server
private static sun.rmi.transport.LiveRef ref
          A reference to this server
private static java.rmi.server.ObjID REGISTRY_OID
          The ObjID for the registry
private static int REGISTRY_OP_BIND
          The number of the bind method on the Registry
private static int REGISTRY_OP_LIST
          The number of the list method on the Registry
private static int REGISTRY_OP_LOOKUP
          The number of the lookup method on the Registry
private static int REGISTRY_OP_REBIND
          The number of the rebind method on the Registry
private static int REGISTRY_OP_UNBIND
          The number of the unbind method on the Registry
private static java.lang.String skeletonCommand
          The command for the grid engine execution engine to run on the execution host
private  java.net.Socket socket
          The Socket over which communications will take place
private static java.lang.String submitCommand
          The command used to submit job to the grid engine queue
private static java.rmi.server.UID uid
          The UID of this server
private static java.lang.String USAGE
          The usage information String
 
Constructor Summary
private ComputeProxy(java.net.Socket socket)
          Creates a new instance of ComputeProxy
 
Method Summary
private static java.lang.String[] createCommandStringArray(java.lang.String[] parts)
           
private  void deleteJob(java.lang.String id)
          This method removes a job from the lockbox and disk.
private  void doHandshake(java.io.DataInputStream in, java.io.DataOutputStream out)
          This method handles the initial JRMP handshake
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
static void main(java.lang.String[] args)
          The main method creates a registry on 1100 for return channel communications and creates a fake registry on 1099 to intercep RMI calls.
private static void prepareLogging()
          This method sets up the Logger object
private  java.lang.Object process(Computable computable, java.lang.String annotation, boolean asynch)
          This method does the actual processing for calls to compute and computeAsynch on ComputeEngine
private static void processArguments(java.lang.String[] args)
          This method processes the command line arguments and sets the appropriate variables
private  void processBindCall(java.io.ObjectInputStream objIn, java.io.DataOutputStream out)
          This method handles calls to the bind method of the Registry
private  void processCall(java.io.ObjectInputStream objIn, java.io.DataOutputStream out, int opNum, long hash)
          This method handles calls to com.sun.grid.jgrid.ComputeEngine methods
private  void processCleanCall(java.io.ObjectInputStream objIn, java.io.DataOutputStream out)
          This method handles calls to the clean method of the DGC
private  void processComputeCall(java.io.ObjectInputStream objIn, java.io.DataOutputStream out, boolean asynch)
          This method handles calls to the compute and computeAsynch methods of ComputeEngine
private  void processConnection(java.io.DataInputStream in, java.io.DataOutputStream out)
          This method handles the connection communication
private  void processDirtyCall(java.io.ObjectInputStream objIn, java.io.DataOutputStream out)
          This method handles calls to the dirty method of the DGC
private  void processException(java.io.DataOutputStream out, java.lang.Exception e)
          This method handles exceptions
private  void processGetResultsCall(java.io.ObjectInputStream objIn, java.io.DataOutputStream out)
          This method handles calls to the getResults method of ComputeEngine
private  void processIsCompleteCall(java.io.ObjectInputStream objIn, java.io.DataOutputStream out)
          This method handles calls to the isComplete method of ComputeEngine
private  void processListCall(java.io.ObjectInputStream objIn, java.io.DataOutputStream out)
          This method handles calls to the list method of the Registry
private  void processLookupCall(java.io.ObjectInputStream objIn, java.io.DataOutputStream out)
          This method handles calls to the lookup method of the Registry
private  void processRebindCall(java.io.ObjectInputStream objIn, java.io.DataOutputStream out)
          This method handles calls to the rebind method of the Registry
private  void processUnbindCall(java.io.ObjectInputStream objIn, java.io.DataOutputStream out)
          This method handles calls to the unbind method of the Registry
 void run()
          This method begins the communications process
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)
           
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.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USAGE

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

See Also:
Constant Field Values

REGISTRY_OID

private static final java.rmi.server.ObjID REGISTRY_OID
The ObjID for the registry


REGISTRY_OP_BIND

private static final int REGISTRY_OP_BIND
The number of the bind method on the Registry

See Also:
Constant Field Values

REGISTRY_OP_LIST

private static final int REGISTRY_OP_LIST
The number of the list method on the Registry

See Also:
Constant Field Values

REGISTRY_OP_LOOKUP

private static final int REGISTRY_OP_LOOKUP
The number of the lookup method on the Registry

See Also:
Constant Field Values

REGISTRY_OP_REBIND

private static final int REGISTRY_OP_REBIND
The number of the rebind method on the Registry

See Also:
Constant Field Values

REGISTRY_OP_UNBIND

private static final int REGISTRY_OP_UNBIND
The number of the unbind method on the Registry

See Also:
Constant Field Values

DGC_OID

private static final java.rmi.server.ObjID DGC_OID
The ObjID of the DGC


DGC_OP_CLEAN

private static final int DGC_OP_CLEAN
The number of the clean method on the DGCRegistry

See Also:
Constant Field Values

DGC_OP_DIRTY

private static final int DGC_OP_DIRTY
The number of the dirty method on the DGCRegistry

See Also:
Constant Field Values

HASH_COMPUTE

private static final long HASH_COMPUTE
The method hash for the compute method

See Also:
Constant Field Values

HASH_COMPUTEASYNCH

private static final long HASH_COMPUTEASYNCH
The method hash for the computeAsynch method

See Also:
Constant Field Values

HASH_GETRESULTS

private static final long HASH_GETRESULTS
The method hash for the getResults method

See Also:
Constant Field Values

HASH_ISCOMPLETE

private static final long HASH_ISCOMPLETE
The method hash for the isComplete method

See Also:
Constant Field Values

uid

private static final java.rmi.server.UID uid
The UID of this server


ref

private static final sun.rmi.transport.LiveRef ref
A reference to this server


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, ComputeProxy.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


port

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


debug

private static boolean debug
Whether debug information should be printed


socket

private java.net.Socket socket
The Socket over which communications will take place

Constructor Detail

ComputeProxy

private ComputeProxy(java.net.Socket socket)
Creates a new instance of ComputeProxy

Parameters:
socket - The Socket over which communications will take place
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 fake registry on 1099 to intercep 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


run

public void run()
This method begins the communications process

Specified by:
run in interface java.lang.Runnable

doHandshake

private void doHandshake(java.io.DataInputStream in,
                         java.io.DataOutputStream out)
                  throws java.io.IOException
This method handles the initial JRMP handshake

Parameters:
in - the input stream
out - the outputstream
Throws:
java.io.IOException - if an error occurs during communications

processConnection

private void processConnection(java.io.DataInputStream in,
                               java.io.DataOutputStream out)
                        throws java.io.IOException
This method handles the connection communication

Parameters:
in - the input stream
out - the output stream
Throws:
java.io.IOException - if an error occurs during communications

processBindCall

private void processBindCall(java.io.ObjectInputStream objIn,
                             java.io.DataOutputStream out)
                      throws java.io.IOException
This method handles calls to the bind method of the Registry

Parameters:
objIn - the input stream
out - the output stream
Throws:
java.io.IOException - if an error occurs during communications

processListCall

private void processListCall(java.io.ObjectInputStream objIn,
                             java.io.DataOutputStream out)
                      throws java.io.IOException
This method handles calls to the list method of the Registry

Parameters:
objIn - the input stream
out - the output stream
Throws:
java.io.IOException - if an error occurs during communications

processLookupCall

private void processLookupCall(java.io.ObjectInputStream objIn,
                               java.io.DataOutputStream out)
                        throws java.io.IOException
This method handles calls to the lookup method of the Registry

Parameters:
objIn - the input stream
out - the output stream
Throws:
java.io.IOException - if an error occurs during communications

processRebindCall

private void processRebindCall(java.io.ObjectInputStream objIn,
                               java.io.DataOutputStream out)
                        throws java.io.IOException
This method handles calls to the rebind method of the Registry

Parameters:
objIn - the input stream
out - the output stream
Throws:
java.io.IOException - if an error occurs during communications

processUnbindCall

private void processUnbindCall(java.io.ObjectInputStream objIn,
                               java.io.DataOutputStream out)
                        throws java.io.IOException
This method handles calls to the unbind method of the Registry

Parameters:
objIn - the input stream
out - the output stream
Throws:
java.io.IOException - if an error occurs during communications

processCleanCall

private void processCleanCall(java.io.ObjectInputStream objIn,
                              java.io.DataOutputStream out)
                       throws java.io.IOException
This method handles calls to the clean method of the DGC

Parameters:
objIn - the input stream
out - the output stream
Throws:
java.io.IOException - if an error occurs during communications

processDirtyCall

private void processDirtyCall(java.io.ObjectInputStream objIn,
                              java.io.DataOutputStream out)
                       throws java.io.IOException
This method handles calls to the dirty method of the DGC

Parameters:
objIn - the input stream
out - the output stream
Throws:
java.io.IOException - if an error occurs during communications

processCall

private void processCall(java.io.ObjectInputStream objIn,
                         java.io.DataOutputStream out,
                         int opNum,
                         long hash)
                  throws java.io.IOException
This method handles calls to com.sun.grid.jgrid.ComputeEngine methods

Parameters:
opNum - The number of the method called - will always be -1
hash - The hash of the method called
objIn - the input stream
out - the output stream
Throws:
java.io.IOException - if an error occurs during communications

processComputeCall

private void processComputeCall(java.io.ObjectInputStream objIn,
                                java.io.DataOutputStream out,
                                boolean asynch)
                         throws java.io.IOException
This method handles calls to the compute and computeAsynch methods of ComputeEngine

Parameters:
asynch - whether this call should be asynchronous
objIn - the input stream
out - the output stream
Throws:
java.io.IOException - if an error occurs during communications

processGetResultsCall

private void processGetResultsCall(java.io.ObjectInputStream objIn,
                                   java.io.DataOutputStream out)
                            throws java.io.IOException
This method handles calls to the getResults method of ComputeEngine

Parameters:
objIn - the input stream
out - the output stream
Throws:
java.io.IOException - if an error occurs during communications

processIsCompleteCall

private void processIsCompleteCall(java.io.ObjectInputStream objIn,
                                   java.io.DataOutputStream out)
                            throws java.io.IOException
This method handles calls to the isComplete method of ComputeEngine

Parameters:
objIn - the input stream
out - the output stream
Throws:
java.io.IOException - if an error occurs during communications

processException

private void processException(java.io.DataOutputStream out,
                              java.lang.Exception e)
                       throws java.io.IOException
This method handles exceptions

Parameters:
e - the exception encountered
out - the output stream
Throws:
java.io.IOException - if an error occurs during communications

process

private java.lang.Object process(Computable computable,
                                 java.lang.String annotation,
                                 boolean asynch)
                          throws java.io.IOException
This method does the actual processing for calls to compute and computeAsynch on ComputeEngine

Parameters:
computable - the job to process
annotation - the source for the client class files
asynch - whether this job should be executed asynchronously
Returns:
the result of the job is synchronous or null if asycnhronous
Throws:
java.io.IOException - if an error occurs during communications

getNextProcessId

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

Returns:
the next job id

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

submitJob

private java.lang.Object submitJob(Job job)
                            throws java.io.IOException
Throws:
java.io.IOException

createCommandStringArray

private static java.lang.String[] createCommandStringArray(java.lang.String[] parts)