org.opennms.bb.dp.actiond.components
Class ActionExec

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--org.opennms.bb.dp.actiond.components.ActionExec
All Implemented Interfaces:
Runnable

public class ActionExec
extends Thread

Each ActionExec thread is responsible for starting a command through a call to the Runtime.Exec() method and waiting for it to complete. When the command completes result and exit/failure values are set which may be retrieved via the getcmdxxx() methods. On Win32 environments, at attempt is made to convert common numeric Win32 API error codes into meaningful failure text.

Version:
$Revision: 1.2 $
Author:
Mike, OpenNMS.org

Field Summary
static int CMD_EXIT_VALUE_UNKNOWN
           
static int CMD_RESULT_FAIL
           
static int CMD_RESULT_SUCCESS
           
static int CMD_RESULT_UNKNOWN
           
private  ActionLauncher m_actionLauncher
          Reference to the parent object which started this thread.
private  int m_cmdExecutionResult
          Value which indicates the result of the Runtime.exec() call to start the command.
private  int m_cmdExitValue
          If m_cmdExecutionResult is set to CMD_RESULT_SUCCESS, then this variable will contain the exit code of the process as returned by Process.exitValue() call.
private  String m_cmdFailureText
          If m_cmdExecutionResult is set to CMD_RESULT_FAIL then this String will contain the reason for the failure.
private  String m_command
          Command to be executed.
private static String m_osName
          Operating system identifier string.
private static int WIN32_ERROR_ACCESS_DENIED
           
private static int WIN32_ERROR_BAD_EXE_FORMAT
           
private static int WIN32_ERROR_FILE_NOT_FOUND
           
private static int WIN32_ERROR_PATH_NOT_FOUND
           
private static String WIN32_TEXT_ACCESS_DENIED
           
private static String WIN32_TEXT_BAD_EXE_FORMAT
           
private static String WIN32_TEXT_FILE_NOT_FOUND
           
private static String WIN32_TEXT_PATH_NOT_FOUND
           
 
Fields inherited from class java.lang.Thread
contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ
 
Constructor Summary
ActionExec(String command, ActionLauncher actionLauncher)
          Constructs the ActionExec thread
 
Method Summary
(package private) static void ()
           
 int getCmdExitValue()
          Get the command exit value.
 String getCmdFailureText()
          Get the command failure text.
 int getCmdResult()
          Get the command execution result code which indicates the success or failure of starting an external process/command.
 void run()
          Does the work of actually starting a separate process to execute the command.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, exit, getContextClassLoader, getName, getPriority, getThreadGroup, init, interrupt, interrupt0, interrupted, isAlive, isDaemon, isInterrupted, isInterrupted, join, join, join, nextThreadNum, registerNatives, resume, resume0, setContextClassLoader, setDaemon, setName, setPriority, setPriority0, sleep, sleep, start, stop, stop, stop0, suspend, suspend0, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CMD_RESULT_UNKNOWN

public static final int CMD_RESULT_UNKNOWN

CMD_RESULT_SUCCESS

public static final int CMD_RESULT_SUCCESS

CMD_RESULT_FAIL

public static final int CMD_RESULT_FAIL

CMD_EXIT_VALUE_UNKNOWN

public static final int CMD_EXIT_VALUE_UNKNOWN

WIN32_ERROR_FILE_NOT_FOUND

private static final int WIN32_ERROR_FILE_NOT_FOUND

WIN32_ERROR_PATH_NOT_FOUND

private static final int WIN32_ERROR_PATH_NOT_FOUND

WIN32_ERROR_ACCESS_DENIED

private static final int WIN32_ERROR_ACCESS_DENIED

WIN32_ERROR_BAD_EXE_FORMAT

private static final int WIN32_ERROR_BAD_EXE_FORMAT

WIN32_TEXT_FILE_NOT_FOUND

private static final String WIN32_TEXT_FILE_NOT_FOUND

WIN32_TEXT_PATH_NOT_FOUND

private static final String WIN32_TEXT_PATH_NOT_FOUND

WIN32_TEXT_ACCESS_DENIED

private static final String WIN32_TEXT_ACCESS_DENIED

WIN32_TEXT_BAD_EXE_FORMAT

private static final String WIN32_TEXT_BAD_EXE_FORMAT

m_cmdExecutionResult

private int m_cmdExecutionResult
Value which indicates the result of the Runtime.exec() call to start the command. One of the following values: CMD_RESULT_UNKNOWN, CMD_RESULT_FAIL or CMD_RESULT_SUCCESS

m_cmdExitValue

private int m_cmdExitValue
If m_cmdExecutionResult is set to CMD_RESULT_SUCCESS, then this variable will contain the exit code of the process as returned by Process.exitValue() call.

m_cmdFailureText

private String m_cmdFailureText
If m_cmdExecutionResult is set to CMD_RESULT_FAIL then this String will contain the reason for the failure.

m_command

private String m_command
Command to be executed.

m_actionLauncher

private ActionLauncher m_actionLauncher
Reference to the parent object which started this thread. This object will be notified (via Thread.notify()) when the command has finished and all result/exit codes have been set.

m_osName

private static String m_osName
Operating system identifier string. Used to determine how to parse operating system dependent IOException error message generated during call to Runtime.Exec() to start command.
Constructor Detail

ActionExec

public ActionExec(String command,
                  ActionLauncher actionLauncher)
Constructs the ActionExec thread
Parameters:
command - Command string to be executed
actionLauncher - ActionLauncher object to be notified when command completes
Method Detail

static void ()

run

public void run()
Does the work of actually starting a separate process to execute the command.
Overrides:
run in class Thread

getCmdResult

public int getCmdResult()
Get the command execution result code which indicates the success or failure of starting an external process/command. It does not indicate success or failure of the command itself.

getCmdExitValue

public int getCmdExitValue()
Get the command exit value. Returns the command exit value. If the command was successfully started and run then this value will be set to the exit value of the process/command as returned by Process.exitValue(). This value can then be used to determine if the command ran successfully or not.

getCmdFailureText

public String getCmdFailureText()
Get the command failure text. Returns the command failure text string. This value will only be non-null if m_cmdExecutionResult is set to CMD_RESULT_FAIL.