edu.emory.mathcs.util.remote
Class RemoteProcess

java.lang.Object
  extended byedu.emory.mathcs.util.remote.RemoteProcess
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable

public class RemoteProcess
extends java.lang.Object
implements java.io.Externalizable

Serializable handle to a native process running on a remote machine. Communicates via RMI with the process handle at the server side. Since the handle is serializable, it can be sent over RMI (e.g. returned from a remote call). For example:

 RemoteProcess getRemoteProcess() throws RemoteException {
    // locate (or start) nativeProcess
    // ...
    return new RemoteProcess(nativeProcess);
 }
 

Version:
1.0
Author:
Dawid Kurzyniec
See Also:
Serialized Form

Constructor Summary
RemoteProcess()
          for deserialization only
RemoteProcess(java.lang.Process process)
          Constructs a new serializable remote reference to the specified process.
RemoteProcess(RemoteProcessSrv server)
          Constructs a new serializable remote reference to a remote process.
 
Method Summary
 void destroy()
          Destroys the remote process.
 int exitValue()
          Returns the exit value for the remote process.
 java.io.InputStream getErrorStream()
          Gets the remote error stream of the remote process.
 java.io.InputStream getInputStream()
          Gets the remote input stream of the remote process.
 java.io.OutputStream getOutputStream()
          Gets the remote output stream of the remote process.
 void readExternal(java.io.ObjectInput in)
           
 int waitFor()
          Causes the current thread to wait, if necessary, until the remote process has terminated.
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RemoteProcess

public RemoteProcess()
for deserialization only


RemoteProcess

public RemoteProcess(java.lang.Process process)
Constructs a new serializable remote reference to the specified process.

Parameters:
process - the process to create the reference to

RemoteProcess

public RemoteProcess(RemoteProcessSrv server)
Constructs a new serializable remote reference to a remote process. Use this constructor on the client side if the RMI handle to the process has been already created.

Parameters:
server - the RMI handle to the process
Method Detail

destroy

public void destroy()
             throws java.rmi.RemoteException
Destroys the remote process. The process is forcibly terminated.

Throws:
java.rmi.RemoteException - upon a communication failure

exitValue

public int exitValue()
              throws java.rmi.RemoteException
Returns the exit value for the remote process.

Returns:
the exit value of the remote process. By convention, the value 0 indicates normal termination.
Throws:
java.rmi.RemoteException - upon a communication failure
java.lang.IllegalThreadStateException - if the remote process has not yet terminated

waitFor

public int waitFor()
            throws java.rmi.RemoteException,
                   java.lang.InterruptedException
Causes the current thread to wait, if necessary, until the remote process has terminated. This method returns immediately if the remote process has already terminated. If the remote process has not yet terminated, the calling thread will be blocked until it does.

Returns:
the exit value of the process. By convention, 0 indicates normal termination
Throws:
java.rmi.RemoteException - upon a communication failure
java.lang.InterruptedException - if the current thread is interrupted by another thread while it is waiting

getInputStream

public java.io.InputStream getInputStream()
Gets the remote input stream of the remote process. The stream obtains data piped from the standard output stream of the native remote process.

Implementation note: It is a good idea for the input stream to be buffered.

Returns:
the input stream connected to the standard output of the remote process
Throws:
java.rmi.RemoteException - upon a communication failure

getErrorStream

public java.io.InputStream getErrorStream()
Gets the remote error stream of the remote process. The stream obtains data piped from the standard error stream of the native remote process.

Implementation note: It is a good idea for the input stream to be buffered.

Returns:
the input stream connected to the standard error of the remote process
Throws:
java.rmi.RemoteException - upon a communication failure

getOutputStream

public java.io.OutputStream getOutputStream()
Gets the remote output stream of the remote process. Output to the stream is piped into the standard input stream of the native remote process.

Implementation note: It is a good idea for the output stream to be buffered.

Returns:
the output stream connected to the standard input of the remote process.

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException