OpenNMS API 1.2.3

org.opennms.netmgt.actiond
Class Executor

java.lang.Object
  extended byorg.opennms.netmgt.actiond.Executor
All Implemented Interfaces:
Fiber, PausableFiber, java.lang.Runnable

final class Executor
extends java.lang.Object
implements java.lang.Runnable, PausableFiber

This class is used as a thread for launching and executing actions as they are discovered by the action daemon. The actions are read from an execution queue and the processes are created by the fiber. Each created process is added to garbage collection list that is periodically polled and culled based upon the status of the process or how long the process is run. If the process has run long than allocated it is terminated during collection.

Author:
Mike Davidson , Brian Weaver ,
Nested Class Summary
private static class Executor.DatedProc
          This class is designed to encapsulated a process and its start time.
private  class Executor.Reaper
          This class encapsules a singular run method that is used to garbage collect expired processes.
 
Field Summary
private  FifoQueue m_execQ
          The input queue of runnable commands.
private  int m_maxProcCount
          The maximum number of outstanding processes.
private  long m_maxWait
          The maximum time that a command can execute.
private  java.lang.String m_name
          The name of this Fiber
private  java.util.List m_processes
          The list of outstanding commands.
private  java.lang.Thread m_reaper
          The process garbage collection thread.
private  java.lang.Runnable m_reaperRun
          The garbage collection instance.
private  int m_status
          The status of this fiber.
private  java.lang.Thread m_worker
          The worker thread that executes the run method.
 
Fields inherited from interface org.opennms.core.fiber.PausableFiber
PAUSE_PENDING, PAUSED, RESUME_PENDING
 
Fields inherited from interface org.opennms.core.fiber.Fiber
RUNNING, START_PENDING, STARTING, STATUS_NAMES, STOP_PENDING, STOPPED
 
Constructor Summary
(package private) Executor(FifoQueue execQ, long maxRunTime, int maxProcesses)
          Constructs a new action daemon execution environment.
 
Method Summary
private static java.lang.String[] getExecArguments(java.lang.String cmd)
           Converts a single command to an array that can be passed to the execsystem call.
 java.lang.String getName()
          Returns the name of this fiber.
 int getStatus()
          Returns the current status of the pausable fiber.
 void pause()
          Pauses a currently running fiber.
 void resume()
          Resumes the fiber if it is paused.
 void run()
          The main worker of the fiber.
 void start()
          Starts the fiber.
 void stop()
          Stops a currently running fiber.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_execQ

private FifoQueue m_execQ
The input queue of runnable commands.


m_processes

private java.util.List m_processes
The list of outstanding commands.


m_maxWait

private long m_maxWait
The maximum time that a command can execute.


m_maxProcCount

private int m_maxProcCount
The maximum number of outstanding processes.


m_reaper

private java.lang.Thread m_reaper
The process garbage collection thread.


m_reaperRun

private java.lang.Runnable m_reaperRun
The garbage collection instance.


m_worker

private java.lang.Thread m_worker
The worker thread that executes the run method.


m_name

private java.lang.String m_name
The name of this Fiber


m_status

private int m_status
The status of this fiber.

Constructor Detail

Executor

Executor(FifoQueue execQ,
         long maxRunTime,
         int maxProcesses)
Constructs a new action daemon execution environment. The constructor takes two arguments that define the source of commands to be executed and the maximum time that a command may run.

Parameters:
execQ - The execution queue
maxRunTime - The maximum runtime of a process.
Method Detail

getExecArguments

private static java.lang.String[] getExecArguments(java.lang.String cmd)

Converts a single command to an array that can be passed to the execsystem call. The element at index zero of the array is the name of the executable to run. Indexs [1..length) are the arguments passed to the executable command.

The input command has is white space trimmed before processing. The basic processing is to split on spaces, except when a double quote or single quote is encountered. Also backspaces(\) should also be handled correctly both in and out of the quotes. Shell escapes with $ are not supported.

Parameters:
cmd - The command to split into an array.
Returns:
The execution array.

run

public void run()
The main worker of the fiber. This method is executed by the encapsualted thread to read commands from the execution queue and to execute those commands. If the thread is interrupted or the status changes to STOP_PENDING then the method will return as quickly as possible.

Specified by:
run in interface java.lang.Runnable

start

public void start()
Starts the fiber. If the fiber has already been run or is currently running then an exception is generated. The status of the fiber is updated to STARTING and will transisition to RUNNING when the fiber finishes initializing and begins processing the encapsulaed queue.

Specified by:
start in interface Fiber
Throws:
java.lang.IllegalStateException - Thrown if the fiber is stopped or has never run.

stop

public void stop()
Stops a currently running fiber. If the fiber has already been stopped then the command is silently ignored. If the fiber was never started then an exception is generated.

Specified by:
stop in interface Fiber
Throws:
java.lang.IllegalStateException - Thrown if the fiber was never started.

pause

public void pause()
Pauses a currently running fiber. If the fiber was not in a running or resuming state then the command is silently discarded. If the fiber is not running or has terminated then an exception is generated.

Specified by:
pause in interface PausableFiber
Throws:
java.lang.IllegalStateException - Thrown if the fiber is stopped or has never run.

resume

public void resume()
Resumes the fiber if it is paused. If the fiber was not in a paused or pause pending state then the request is discarded. If the fiber has not been started or has already stopped then an exception is generated.

Specified by:
resume in interface PausableFiber
Throws:
java.lang.IllegalStateException - Thrown if the fiber is stopped or has never run.

getName

public java.lang.String getName()
Returns the name of this fiber.

Specified by:
getName in interface Fiber
Returns:
The name of the fiber.

getStatus

public int getStatus()
Returns the current status of the pausable fiber.

Specified by:
getStatus in interface Fiber
Returns:
The current status of the fiber.
See Also:
PausableFiber, Fiber

OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.