com.ibm.websphere.samples.asynchbeans.wstrader.applet
Class ServerMonitor

java.lang.Object
  extended by java.lang.Thread
      extended by com.ibm.websphere.samples.asynchbeans.wstrader.applet.ServerMonitor
All Implemented Interfaces:
NotificationBroadcaster, java.lang.Runnable

public class ServerMonitor
extends java.lang.Thread
implements NotificationBroadcaster

A ServerMonitor is a singleton object (one per JVM) that monitors the status of a server. It is very similar to the Asynch Beans SubsystemMonitor and Alarm interfaces. It publishes events based on the frequency of heartbeats that are received from the ping() method. The monitor is started when a listener is registered with the addNotificationListener() method and is destroyed when the last listener is removed with the removeNotificationListener() method.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
 void addNotificationListener(NotificationListener listener)
          Register a listener to this broadcaster.
 void cancel()
          Cancel this monitor.
static ServerMonitor create(int interval_ms, int staleBeats, int deadBeats)
          Create a new singleton ServerMonitor or get the currently created on if one already exists
 void fireCurState()
          Fire an event with our current status.
 boolean getCancelled()
          Find out if the thread has been requested to end.
static ServerMonitor getSelf()
          Get the singleton ServerMonitor
 int getStatus()
          Returns the status.
 boolean isDebug()
          Returns the isDebug.
 void ping()
          Reset the state of the monitor to Alive and fire a fresh event if the current state is stale or dead.
 void removeNotificationListener(NotificationListener listener)
          Remove the specified listener from this broadcaster.
 void run()
          Each x milliseconds (heartbeat interval), decrement the number of beats it will take to become stale or dead.
 void setIsDebug(boolean isDebug)
          Sets the isDebug.
 void setStatus(int status)
          Sets the status.
 
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, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public static ServerMonitor create(int interval_ms,
                                   int staleBeats,
                                   int deadBeats)
Create a new singleton ServerMonitor or get the currently created on if one already exists


getSelf

public static ServerMonitor getSelf()
Get the singleton ServerMonitor


ping

public void ping()
Reset the state of the monitor to Alive and fire a fresh event if the current state is stale or dead.


run

public void run()
Each x milliseconds (heartbeat interval), decrement the number of beats it will take to become stale or dead. Once this threshold is reached, change our status and fire the event.

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

addNotificationListener

public void addNotificationListener(NotificationListener listener)
Description copied from interface: NotificationBroadcaster
Register a listener to this broadcaster.

Specified by:
addNotificationListener in interface NotificationBroadcaster
See Also:
NotificationBroadcaster.addNotificationListener(NotificationListener)

removeNotificationListener

public void removeNotificationListener(NotificationListener listener)
Description copied from interface: NotificationBroadcaster
Remove the specified listener from this broadcaster.

Specified by:
removeNotificationListener in interface NotificationBroadcaster
See Also:
NotificationBroadcaster.removeNotificationListener(NotificationListener)

fireCurState

public void fireCurState()
Fire an event with our current status.


cancel

public void cancel()
Cancel this monitor.


getCancelled

public boolean getCancelled()
Find out if the thread has been requested to end.


getStatus

public int getStatus()
Returns the status.

Returns:
int

setStatus

public void setStatus(int status)
Sets the status.

Parameters:
status - The status to set

isDebug

public boolean isDebug()
Returns the isDebug.

Returns:
boolean

setIsDebug

public void setIsDebug(boolean isDebug)
Sets the isDebug.

Parameters:
isDebug - The isDebug to set