com.sun.faban.common
Class CommandHandleImpl

java.lang.Object
  extended by com.sun.faban.common.CommandHandleImpl
All Implemented Interfaces:
CommandHandle, Remote

public class CommandHandleImpl
extends Object
implements CommandHandle

Implementation of the remote command handle.

Author:
Akara Sucharitakul

Method Summary
 void destroy()
          Forfully terminates the command.
 int exitValue()
          Obtains the exit value of the command.
 byte[] fetchOutput(int streamId)
          Obtains the stdout or stderr of the command.
 FileTransfer fetchOutput(int streamId, String destFile)
          Obtains the stdout or stderr of the command and put it into file.
 String getCommandString()
          Obtains the command string this command handle represents.
 void waitFor()
          Waits for the command to terminate.
 void waitFor(int timeout)
          Waits for the command to terminate, with a given timeout.
 void waitMatch()
          Waits for the command until it matches a certain string it its output streams.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCommandString

public String getCommandString()
Obtains the command string this command handle represents.

Specified by:
getCommandString in interface CommandHandle
Returns:
The command string executed.

destroy

public void destroy()
Forfully terminates the command.

Specified by:
destroy in interface CommandHandle

waitFor

public void waitFor()
             throws InterruptedException
Waits for the command to terminate.

Specified by:
waitFor in interface CommandHandle
Throws:
InterruptedException - The waiting thread got interrupted

waitFor

public void waitFor(int timeout)
             throws InterruptedException
Waits for the command to terminate, with a given timeout.

Specified by:
waitFor in interface CommandHandle
Parameters:
timeout - The time out
Throws:
InterruptedException - The waiting thread got interrupted.

exitValue

public int exitValue()
Obtains the exit value of the command.

Specified by:
exitValue in interface CommandHandle
Returns:
The exit value of the command

fetchOutput

public byte[] fetchOutput(int streamId)
                   throws IOException
Obtains the stdout or stderr of the command.

Specified by:
fetchOutput in interface CommandHandle
Parameters:
streamId - Command.STDOUT or Command.STDERR
Returns:
The output from stdout or stderr, or null if there is no output
Throws:
IOException - There is an error getting the output

fetchOutput

public FileTransfer fetchOutput(int streamId,
                                String destFile)
                         throws IOException,
                                IllegalStateException
Obtains the stdout or stderr of the command and put it into file.

Specified by:
fetchOutput in interface CommandHandle
Parameters:
streamId - Command.STDOUT or Command.STDERR
destFile - The destination file on the calling system
Returns:
The FileTransfer, if called from remote system, the file is saved
Throws:
IOException - There is an error getting the output
IllegalStateException - The command is not yet terminated or does not record output
RemoteException - A network error occurred

waitMatch

public void waitMatch()
               throws InterruptedException
Waits for the command until it matches a certain string it its output streams.

Throws:
InterruptedException - The wait was interrupted