mapss.dif.util.command
Class ExecutionClient

java.lang.Object
  extended by mapss.dif.util.command.ExecutionClient

public class ExecutionClient
extends java.lang.Object

The ExecutionClient encapsulates the spawning of the target application and target to driver application communication.

Version:
$Id: ExecutionClient.java 362 2007-02-25 21:08:57Z plishker $
Author:
Shahrooz Shahparnia based on a code by Mark Nadelson in the JavaPro magazine. September 2002 issue.

Field Summary
static int ATTACHED
          Type of execution in which the executing command (target application) remains connected to the communication channel and sends/receives data to the ExecutionClient through the created socket.
static int DETACHED
          Type of execution in which the executing command (target application) disconnects from the ExecutionServer, and does not communicate with the ExecutionClient.
 
Constructor Summary
ExecutionClient(int executionType, java.lang.String host, int hostPort, java.lang.String[] args)
          Sets the execution of the target application in either attached or detached mode on a given host.
 
Method Summary
 int available()
          Return the number of bytes available to read from the input stream.
 void close()
          Closes the socket input and output streams.
 java.lang.String read(byte terminator)
          Read a stream of bytes from the input stream until the terminator is encountered.
 int read(byte[] byteBuffer, int length)
          Reads a block of data from the input stream into a given buffer.
 void write(byte[] byteBuffer, byte terminator)
          Writes a buffer to the output stream , terminated with the specified terminator to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTACHED

public static final int ATTACHED
Type of execution in which the executing command (target application) remains connected to the communication channel and sends/receives data to the ExecutionClient through the created socket.

See Also:
Constant Field Values

DETACHED

public static final int DETACHED
Type of execution in which the executing command (target application) disconnects from the ExecutionServer, and does not communicate with the ExecutionClient. Though it executes on the server(host) and creates outputs there.

See Also:
Constant Field Values
Constructor Detail

ExecutionClient

public ExecutionClient(int executionType,
                       java.lang.String host,
                       int hostPort,
                       java.lang.String[] args)
                throws RemoteExecutionException
Sets the execution of the target application in either attached or detached mode on a given host. It starts the communication.

Parameters:
executionType - The type of execution we want to have on the server which is either ATTACHED or DETACHED.
host - The host on which the ExecutionServer is running on.
hostPort - The port number which the ExecutionServer is listening to.
args - The command and parameters of the command that it going to be executed on the host.
Throws:
RemoteExecutionException - If the Client was not able to communicate with the server.
Method Detail

write

public void write(byte[] byteBuffer,
                  byte terminator)
           throws java.io.IOException
Writes a buffer to the output stream , terminated with the specified terminator to the output stream.

Parameters:
byteBuffer - The byte stream to be written.
terminator - The character to put at the end of the stream after writing the buffer to it.
Throws:
java.io.IOException

read

public int read(byte[] byteBuffer,
                int length)
         throws java.io.IOException
Reads a block of data from the input stream into a given buffer.

Parameters:
byteBuffer - The given buffer.
length - The length of the block of data to be read.
Throws:
java.io.IOException

read

public java.lang.String read(byte terminator)
                      throws java.io.IOException
Read a stream of bytes from the input stream until the terminator is encountered.

Parameters:
terminator - The character to use as terminator in the input stream.
Throws:
java.io.IOException

available

public int available()
              throws java.io.IOException
Return the number of bytes available to read from the input stream.

Returns:
Return the number of bytes available to read from the input stream.
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes the socket input and output streams.

Throws:
java.io.IOException - If fails to close the streams.