org.safs.jvmagent
Class SEMEventMonitor

java.lang.Object
  extended by org.safs.jvmagent.SEMEventMonitor
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
ShutdownEventMonitor

public class SEMEventMonitor
extends java.lang.Object
implements java.lang.Runnable

Monitors the STAF SEM service for a specific event and executes an action upon receiving the event trigger. The monitor will only perform this function if isTriggerEnabled returns true during initialization.

This superclass is a full implementation. Subclasses will generally override the setEventCriteria, isTriggerEnabled, and performAction functions to provide different capabilities.

This type of mechanism is needed because one of the intended applications of subclasses is to be injected in each JVM via the Java Extensions mechanism often used for assistive technologies. While the object will be injected into every JVM, we only want the object to respond and act in specific JVM instances, not all JVM instances.

This superclass will list all the key=value pairs in the JVM System.properties when it detects the 'ShowProperties' event. The enabling item for our trigger is the existence of a 'SEMEventMonitor' System.property in the JVM. JVMs not containing this property will not respond to the trigger and the monitor will go dormant.

Thus, the JVM must be launched with the following option for this monitor to be enabled:

An example STAF command that can trigger this event is:


Nested Class Summary
protected  class SEMEventMonitor.STAFMonitor
          Polls for the existence of STAF every few seconds until found.
 
Field Summary
protected  java.lang.String _event
          The STAF SEM event trigger that will be monitored.
protected  long _msdelay
          The milliseconds to wait between checks for STAF and the SEM event.
protected  java.lang.String _process
          The process name that will be registered with STAF
protected  boolean _shutdown
          set true to cause this class to go dormant and die.
protected  STAFHelper _staf
          The STAFHelper we use to talk with STAF.
protected  SEMEventMonitor.STAFMonitor _stafmon
          The helper STAFMonitor thread that monitors STAF.
protected  java.lang.String _system
          The JVM System.property used to enable the trigger (for this implementation).
protected  java.lang.Thread _thismon
          The Thread created by this Runnable instance when monitoring the SEM event.
static java.lang.String DEFAULT_EVENT
          'ShowProperties'
static java.lang.String DEFAULT_PROPERTY
          'SEMEventMonitor'
 
Constructor Summary
SEMEventMonitor()
          Construct a monitor for the event that will be designated during a constructor call to function setEventName.
 
Method Summary
protected  void finalize()
          Allow ourselves to disconnect from STAF.
protected  void initialize()
          Subclasses should not normally ever need to override this.
protected  boolean isTriggerEnabled()
          Subclasses override to provide their own enabling algorithm for the performAction function.
static void main(java.lang.String[] args)
          For test\debug purposes must launch test JVM with -DSEMEventMonitor=true
protected  void performAction()
          Default action is to list all System.getProperty values in the org.safs.Log Subclasses will likely want to override this.
protected  void resetTrigger()
          RESET the SEM Event trigger we are monitoring.
 void run()
          This is the Runnable thread that will monitor the trigger SEM event.
protected  void setEventCriteria()
          Subclasses override to designate a unique event to monitor.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_EVENT

public static final java.lang.String DEFAULT_EVENT
'ShowProperties'

See Also:
Constant Field Values

DEFAULT_PROPERTY

public static final java.lang.String DEFAULT_PROPERTY
'SEMEventMonitor'

See Also:
Constant Field Values

_process

protected java.lang.String _process
The process name that will be registered with STAF


_event

protected java.lang.String _event
The STAF SEM event trigger that will be monitored.


_system

protected java.lang.String _system
The JVM System.property used to enable the trigger (for this implementation).


_staf

protected STAFHelper _staf
The STAFHelper we use to talk with STAF.


_shutdown

protected boolean _shutdown
set true to cause this class to go dormant and die.


_msdelay

protected long _msdelay
The milliseconds to wait between checks for STAF and the SEM event.


_stafmon

protected SEMEventMonitor.STAFMonitor _stafmon
The helper STAFMonitor thread that monitors STAF.


_thismon

protected java.lang.Thread _thismon
The Thread created by this Runnable instance when monitoring the SEM event.

Constructor Detail

SEMEventMonitor

public SEMEventMonitor()
Construct a monitor for the event that will be designated during a constructor call to function setEventName. initialize() is then called after setEventCriteria().

Method Detail

setEventCriteria

protected void setEventCriteria()
Subclasses override to designate a unique event to monitor. This function will be called during object construction. The default setting to monitor is DEFAULT_EVENT.

This default implementation also sets the key name in System.properties that enables the trigger. This key name is stored in the local _system field. The default setting here is DEFAULT_PROPERTY.


isTriggerEnabled

protected boolean isTriggerEnabled()
Subclasses override to provide their own enabling algorithm for the performAction function. This method is called during initialize() AFTER the call to setEventCriteria(). This function should evaluate whatever it needs to evaluate to determine that the particular class instance should be allowed to perform its function.

This superclass implementation checks to see if the System.property stored in the _system field is defined in this JVM. The routine will only return true if this JVM has that System.property. This _system field can be set in the setEventCriteria() method if subclasses wish to use this particular isTriggerEnabled() implementation.

Returns:
true if the expected System.property is set in this JVM. Subclasses may provide alternate implementations.

initialize

protected void initialize()
Subclasses should not normally ever need to override this. This function first calls isTriggerEnabled to verify the operating environment and\or JVM is the one we want to act upon. If the result of this call is 'false' then STAF registration will not be attempted and the class instance will essentially go dormant and die.

If isTriggerEnabled returns 'true' then will will register a new STAFMonitor to make the connection with STAF and we will begin monitoring for our special event in a our own run() method as a new Runnable thread.

The process name used to register with STAF is:


resetTrigger

protected void resetTrigger()
RESET the SEM Event trigger we are monitoring. This is an optional call often performed in the performAction() function.


performAction

protected void performAction()
Default action is to list all System.getProperty values in the org.safs.Log Subclasses will likely want to override this.


run

public void run()
This is the Runnable thread that will monitor the trigger SEM event. The initialize() function will launch this new Thread if isTriggerEnabled() was true and we successfully registered with STAF.

Subclasses should not have to override this. The default implementation does NOT reset the trigger event, however, so subclasses wishing to react to multiple occurrences of the trigger will need to reset the event in their performAction function.

Specified by:
run in interface java.lang.Runnable

finalize

protected void finalize()
                 throws java.lang.Exception
Allow ourselves to disconnect from STAF.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)
For test\debug purposes must launch test JVM with -DSEMEventMonitor=true