com.pentec.aserver
Class AServerPlugin

java.lang.Object
  extended by java.lang.Thread
      extended by com.pentec.aserver.AServerPlugin
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
Alive, AServerAgent, Canond, GPSd, InstrumentStatusd, Ittd, NetAdapterHostd, NetworkPlugin, RemoteRS232, Shutdownd, Upgraded, WSd

public abstract class AServerPlugin
extends java.lang.Thread

Base clase for AServer plugin modules

Author:
Pender Technology

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  java.lang.String $InstanceIdentifier
          Instance identification for the plugin - This can be null if the plugin doesn't adhear to the new instance identifier specification.
private  java.lang.String $Name
          Name of the plugin
private  java.lang.String $Version
          Version of the plugin
private static java.util.Hashtable htPlugins
           
protected  boolean isOkToRun
          Flag determining if it's ok to continue running.
private  int iState
          Current state of the plugin
static java.lang.String SIG_INIT_FAILED
           
static java.lang.String SIG_INITIALIZING
           
static java.lang.String SIG_QUITTING
           
static java.lang.String SIG_RUNNING
           
static int STATE_INIT_FAILED
           
static int STATE_INITIALIZING
           
static int STATE_QUITTING
           
static int STATE_RUNNING
           
static int STATE_STARTING
           
static int STATE_WAITING_TO_START
           
protected static java.util.Vector vPlugins
          List of all plugins
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AServerPlugin(java.lang.String $Name, java.lang.String $Version)
          This is a legacy constructor which may be removed in the future in favor of the constructor adding $InstanceIdentifier so multiple instances of the same plugin can be differentiated in the log file.
AServerPlugin(java.lang.String $Name, java.lang.String $Version, java.lang.String $InstanceIdentifier)
           
 
Method Summary
static java.lang.String[] getFullyQualifiedPluginName(int iIndex)
          Get the fully qualified name of a plugin by its index in the list
static int getNumPlugins()
          Get the number of plugins instantiated
 java.lang.String getPluginInstanceIdentifier()
          Get the plugin's instance identifier
 java.lang.String getPluginName()
          Get the plugin's name
 int getPluginState()
          Get the state of the plugin
static int getPluginStateByName(java.lang.String $FullyQualifiedPluginName)
          Get the state of a plugin by its fully qualified name
 java.lang.String getPluginVersion()
          Get the plugin's version
abstract  void run()
          The plugin does its work here
protected  void setPluginInstanceIdentifier(java.lang.String $InstanceIdentifier)
          Set the plugin's instance identifier.
private  void setState(int iState)
          Set the plugin's state
protected  void signalInitFailed(java.lang.String $Reason)
          Signal that initialization for this plugin failed
protected  void signalInitializing()
          Signal that initialization for this plugin in progress
protected  void signalQuitting()
          Signal that this plugin is exitting
protected  void signalRunning()
          Signal that this plugin is up and running (init succeeded)
private  void signalStarting()
          Signal that a new plugin is starting its run.
 void startPlugin()
          Start the plugin
 void stopPlugin()
          Stop the plugin
 java.lang.String toString()
          Return the plugin's name, version, and instance identifier if available.
static void writeLog(AServerPlugin callingPlugin, java.lang.String $Message)
          Allow non-AServerPlugins to write to the log file if they have a reference to an AServerPlugin.
protected  void writeLog(java.lang.String $Message)
          Allow the plugin to write a message to the log file.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

$InstanceIdentifier

private java.lang.String $InstanceIdentifier
Instance identification for the plugin - This can be null if the plugin doesn't adhear to the new instance identifier specification. Null can also be an indication that there is only one of this favor of plugin, or it may simply be adding to the confusion of the whole matter.


$Name

private final java.lang.String $Name
Name of the plugin


$Version

private final java.lang.String $Version
Version of the plugin


htPlugins

private static final java.util.Hashtable htPlugins

isOkToRun

protected boolean isOkToRun
Flag determining if it's ok to continue running. Plugins should routinely monitor this flag.


iState

private int iState
Current state of the plugin


SIG_INIT_FAILED

public static final java.lang.String SIG_INIT_FAILED
See Also:
Constant Field Values

SIG_INITIALIZING

public static final java.lang.String SIG_INITIALIZING
See Also:
Constant Field Values

SIG_QUITTING

public static final java.lang.String SIG_QUITTING
See Also:
Constant Field Values

SIG_RUNNING

public static final java.lang.String SIG_RUNNING
See Also:
Constant Field Values

STATE_INIT_FAILED

public static final int STATE_INIT_FAILED
See Also:
Constant Field Values

STATE_INITIALIZING

public static final int STATE_INITIALIZING
See Also:
Constant Field Values

STATE_QUITTING

public static final int STATE_QUITTING
See Also:
Constant Field Values

STATE_RUNNING

public static final int STATE_RUNNING
See Also:
Constant Field Values

STATE_STARTING

public static final int STATE_STARTING
See Also:
Constant Field Values

STATE_WAITING_TO_START

public static final int STATE_WAITING_TO_START
See Also:
Constant Field Values

vPlugins

protected static final java.util.Vector vPlugins
List of all plugins

Constructor Detail

AServerPlugin

public AServerPlugin(java.lang.String $Name,
                     java.lang.String $Version)
This is a legacy constructor which may be removed in the future in favor of the constructor adding $InstanceIdentifier so multiple instances of the same plugin can be differentiated in the log file.

Parameters:
$Name - name of the plugin
$Version - version of the plugin

AServerPlugin

public AServerPlugin(java.lang.String $Name,
                     java.lang.String $Version,
                     java.lang.String $InstanceIdentifier)
Parameters:
$Name - name of the plugin
$Version - version of the plugin
$InstanceIdentifier - instance identification of the plugin (may be null)
Method Detail

getFullyQualifiedPluginName

public static java.lang.String[] getFullyQualifiedPluginName(int iIndex)
Get the fully qualified name of a plugin by its index in the list

Parameters:
iIndex - list index
Returns:
[0] - name, [1] - version, [2] - instance

getNumPlugins

public static int getNumPlugins()
Get the number of plugins instantiated

Returns:
number of plugins instantiated

getPluginInstanceIdentifier

public final java.lang.String getPluginInstanceIdentifier()
Get the plugin's instance identifier


getPluginName

public final java.lang.String getPluginName()
Get the plugin's name


getPluginState

public int getPluginState()
Get the state of the plugin

Returns:
state of the plugin

getPluginStateByName

public static int getPluginStateByName(java.lang.String $FullyQualifiedPluginName)
Get the state of a plugin by its fully qualified name

Parameters:
$FullyQualifiedPluginName - fully qualified plugin name
Returns:
state of -1 if the plugin was not found

getPluginVersion

public final java.lang.String getPluginVersion()
Get the plugin's version


run

public abstract void run()
The plugin does its work here

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

setPluginInstanceIdentifier

protected final void setPluginInstanceIdentifier(java.lang.String $InstanceIdentifier)
Set the plugin's instance identifier. This will disappear when the constuctor lacking an instance identifier parameter disappears.


setState

private void setState(int iState)
Set the plugin's state

Parameters:
iState - state of the plugin

signalInitFailed

protected final void signalInitFailed(java.lang.String $Reason)
Signal that initialization for this plugin failed

Parameters:
$Reason - reason for failure

signalInitializing

protected final void signalInitializing()
Signal that initialization for this plugin in progress


signalQuitting

protected final void signalQuitting()
Signal that this plugin is exitting


signalRunning

protected final void signalRunning()
Signal that this plugin is up and running (init succeeded)


signalStarting

private final void signalStarting()
Signal that a new plugin is starting its run. The plugin is unintialized in this state.


startPlugin

public final void startPlugin()
Start the plugin


stopPlugin

public final void stopPlugin()
Stop the plugin


toString

public final java.lang.String toString()
Return the plugin's name, version, and instance identifier if available.

Overrides:
toString in class java.lang.Thread

writeLog

public static final void writeLog(AServerPlugin callingPlugin,
                                  java.lang.String $Message)
Allow non-AServerPlugins to write to the log file if they have a reference to an AServerPlugin. The message will show up as having come from the AServerPlugin passed in. This is particularly useful for children of AServerPlugins who aren't themselves derived from AServerPlugin.

Parameters:
callingPlugin - plugin writing to the log file on the caller's behalf
$Message - message to write to the log file

writeLog

protected final void writeLog(java.lang.String $Message)
Allow the plugin to write a message to the log file.

Parameters:
$Message - message to write to the log file