org.sadun.util.watchdog.mbean
Class ManagedWatchDog

java.lang.Object
  extended byorg.sadun.util.watchdog.mbean.ManagedWatchDog
All Implemented Interfaces:
ManagedWatchDogMBean, javax.management.MBeanRegistration
Direct Known Subclasses:
TestWatchDog

public class ManagedWatchDog
extends java.lang.Object
implements ManagedWatchDogMBean, javax.management.MBeanRegistration

NON COMPLETE YET. An implementation of ManagedWatchDogMBean.

Unlike WatchDog, this implementation is concrete and can be directly instantiated. The specific check action to perform can be specified by declaring the ManagedWatchDogMBean.CheckActionclass name via the setCheckActionClassName(String)method (or the equivalent CheckActionClassName JMX attribute).

However, it is still possible to extend the class and construct a subclass which

Therfore, to create a JMX-instrumented watchdog, a developer can:

Version:
1.0
Author:
Cristiano Sadun

Nested Class Summary
 
Nested classes inherited from class org.sadun.util.watchdog.mbean.ManagedWatchDogMBean
ManagedWatchDogMBean.CheckAction
 
Field Summary
protected  javax.management.ObjectName mbeanName
          The objectname with which this watchdog is registered.
protected  WatchDog watchDog
          The embedded watchdog object.
 
Constructor Summary
ManagedWatchDog()
          Constructor which leaves all definitions to subsequent set calls.
ManagedWatchDog(java.lang.String name, long checkPeriodTime, boolean synchronous, ManagedWatchDogMBean.CheckAction action)
          Create a WatchDog MBean with the given check period, in milliseconds, and the given associated action.
ManagedWatchDog(java.lang.String name, long checkPeriodTime, ManagedWatchDogMBean.CheckAction action)
          Create a WatchDog MBean which wraps an existing concrete WatchDogclass.
ManagedWatchDog(java.lang.String name, ManagedWatchDogMBean.CheckAction action)
          Create a WatchDog MBean with the default check period time.
 
Method Summary
 void addListener(WatchDog.Listener l)
          Add a watchdog listener to the listener set.
 java.lang.String getCheckActionClassName()
          Get the name of the check action class in use.
 java.lang.Object getCheckActionParameter(java.lang.String name)
          Return the value of a parameter in the current check action object.
 long getCheckPeriodTime()
          Return the amount of time the watchdog waits between each check.
 java.lang.String getName()
          Set the name of the watchdog tGread
 boolean isAlive()
          Return true if the watchdog thread is currently running.
 boolean isShuttingDown()
          Return true if a shutdown has been requested.
 boolean isStartBySleeping()
          Return true if the watchdog goes immediatly to sleep on startup
 boolean isSynchronous()
          Return the synchronicity mode (see class comment).
 void postDeregister()
           
 void postRegister(java.lang.Boolean registrationDone)
           
 void preDeregister()
           
 javax.management.ObjectName preRegister(javax.management.MBeanServer server, javax.management.ObjectName name)
           
 void removeListener(WatchDog.Listener l)
          Remove a watchdog listener from the listeners set.
 void setCheckActionClassName(java.lang.String name)
          Set the name of the check action class to use.
 void setCheckActionParameter(java.lang.String name, java.lang.Object value)
          Set a parameter on the current check action object.
 void setCheckPeriodTime(long checkPeriodTime)
          Set the amount of time the watchdog waits between each check.
 void setName(java.lang.String name)
          Set the name of the watchdog thread
 void setStartBySleeping(boolean startBySleeping)
           
 void shutdown()
          Unconditionally requests a shutdown.
 void startup()
          Start the watchdog thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

watchDog

protected WatchDog watchDog
The embedded watchdog object.


mbeanName

protected javax.management.ObjectName mbeanName
The objectname with which this watchdog is registered.

Constructor Detail

ManagedWatchDog

public ManagedWatchDog(java.lang.String name,
                       long checkPeriodTime,
                       ManagedWatchDogMBean.CheckAction action)
Create a WatchDog MBean which wraps an existing concrete WatchDogclass.

Parameters:
name - the name of the WatchDog thread
checkPeriodTime - the amount of time the watchdog waits between each check.
action - the CheckActionto perform

ManagedWatchDog

public ManagedWatchDog(java.lang.String name,
                       long checkPeriodTime,
                       boolean synchronous,
                       ManagedWatchDogMBean.CheckAction action)
Create a WatchDog MBean with the given check period, in milliseconds, and the given associated action.

The watchdog can be created in either synchronous or asynchronous mode.

In the former case, listeners are invoked in the WatchDog thread - and if they block, the WatchDog thread will block; in the latter case, listeners execution is decoupled from the WatchDog thread.

Asynchronous mode requires is heavier and requires more resources.

Parameters:
name - the name of the WatchDog thread
checkPeriodTime - the amount of time the watchdog waits between each check.
synchronous - if true, synchronous mode is selected, else asynchronous.
action - the CheckActionto perform

ManagedWatchDog

public ManagedWatchDog(java.lang.String name,
                       ManagedWatchDogMBean.CheckAction action)
Create a WatchDog MBean with the default check period time.

Parameters:
name - the name of the WatchDog thread asynchronous.
action - the CheckActionto perform

ManagedWatchDog

public ManagedWatchDog()
Constructor which leaves all definitions to subsequent set calls.

Method Detail

postDeregister

public void postDeregister()
Specified by:
postDeregister in interface javax.management.MBeanRegistration

postRegister

public void postRegister(java.lang.Boolean registrationDone)
Specified by:
postRegister in interface javax.management.MBeanRegistration

preDeregister

public void preDeregister()
                   throws java.lang.Exception
Specified by:
preDeregister in interface javax.management.MBeanRegistration
Throws:
java.lang.Exception

preRegister

public javax.management.ObjectName preRegister(javax.management.MBeanServer server,
                                               javax.management.ObjectName name)
                                        throws java.lang.Exception
Specified by:
preRegister in interface javax.management.MBeanRegistration
Throws:
java.lang.Exception

addListener

public void addListener(WatchDog.Listener l)
Description copied from interface: ManagedWatchDogMBean
Add a watchdog listener to the listener set.

Specified by:
addListener in interface ManagedWatchDogMBean
Parameters:
l - the listener to add

getCheckPeriodTime

public long getCheckPeriodTime()
Description copied from interface: ManagedWatchDogMBean
Return the amount of time the watchdog waits between each check.

Specified by:
getCheckPeriodTime in interface ManagedWatchDogMBean
Returns:
the amount of time the watchdog waits between each check.

getName

public java.lang.String getName()
Description copied from interface: ManagedWatchDogMBean
Set the name of the watchdog tGread

Specified by:
getName in interface ManagedWatchDogMBean
Returns:
the name of the watchdog thread

isAlive

public boolean isAlive()
Description copied from interface: ManagedWatchDogMBean
Return true if the watchdog thread is currently running.

Specified by:
isAlive in interface ManagedWatchDogMBean
Returns:
true if the watchdog thread is currently running.

isShuttingDown

public boolean isShuttingDown()
Description copied from interface: ManagedWatchDogMBean
Return true if a shutdown has been requested.

Specified by:
isShuttingDown in interface ManagedWatchDogMBean
Returns:
true if a shutdown has been requested

isStartBySleeping

public boolean isStartBySleeping()
Description copied from interface: ManagedWatchDogMBean
Return true if the watchdog goes immediatly to sleep on startup

Specified by:
isStartBySleeping in interface ManagedWatchDogMBean
Returns:
true if the watchdog goes immediatly to sleep on startup

isSynchronous

public boolean isSynchronous()
Description copied from interface: ManagedWatchDogMBean
Return the synchronicity mode (see class comment).

Specified by:
isSynchronous in interface ManagedWatchDogMBean
Returns:
the synchronicity mode (see class comment).

removeListener

public void removeListener(WatchDog.Listener l)
Description copied from interface: ManagedWatchDogMBean
Remove a watchdog listener from the listeners set.

Specified by:
removeListener in interface ManagedWatchDogMBean
Parameters:
l - the listener to remove

setCheckPeriodTime

public void setCheckPeriodTime(long checkPeriodTime)
Description copied from interface: ManagedWatchDogMBean
Set the amount of time the watchdog waits between each check.

Specified by:
setCheckPeriodTime in interface ManagedWatchDogMBean
Parameters:
checkPeriodTime - the amount of time the watchdog waits between each check.

setName

public void setName(java.lang.String name)
Description copied from interface: ManagedWatchDogMBean
Set the name of the watchdog thread

Specified by:
setName in interface ManagedWatchDogMBean
Parameters:
name - the name of the watchdog thread

setStartBySleeping

public void setStartBySleeping(boolean startBySleeping)
Specified by:
setStartBySleeping in interface ManagedWatchDogMBean
Parameters:
startBySleeping - The startBySleeping to set.

shutdown

public void shutdown()
Description copied from interface: ManagedWatchDogMBean
Unconditionally requests a shutdown. The runnable will complete its last atomic operation, and gracefully exit the run() method.

Specified by:
shutdown in interface ManagedWatchDogMBean

startup

public void startup()
Description copied from interface: ManagedWatchDogMBean
Start the watchdog thread.

Specified by:
startup in interface ManagedWatchDogMBean

getCheckActionClassName

public java.lang.String getCheckActionClassName()
Description copied from interface: ManagedWatchDogMBean
Get the name of the check action class in use.

Specified by:
getCheckActionClassName in interface ManagedWatchDogMBean
Returns:
the name of the check action class in use.

setCheckActionClassName

public void setCheckActionClassName(java.lang.String name)
                             throws javax.management.MBeanException
Description copied from interface: ManagedWatchDogMBean
Set the name of the check action class to use.

The class must have a public default constructor.

This method attempts to create an instance of the class, and a corresponding WatchDog object. An MBeanException is raised in case of problem doing so.

This method can be called only once.

Specified by:
setCheckActionClassName in interface ManagedWatchDogMBean
Parameters:
name - the name of the check action class to use.
Throws:
javax.management.MBeanException

getCheckActionParameter

public java.lang.Object getCheckActionParameter(java.lang.String name)
                                         throws javax.management.MBeanException
Description copied from interface: ManagedWatchDogMBean
Return the value of a parameter in the current check action object. The CheckActionClassName attribute must be set to a valid, constructable class before this method is invoked.

Specified by:
getCheckActionParameter in interface ManagedWatchDogMBean
Parameters:
name - the name of the check action parameter.
Returns:
the parameter value
Throws:
javax.management.MBeanException

setCheckActionParameter

public void setCheckActionParameter(java.lang.String name,
                                    java.lang.Object value)
                             throws javax.management.MBeanException
Description copied from interface: ManagedWatchDogMBean
Set a parameter on the current check action object. The CheckActionClassName attribute must be set to a valid, constructable class before this method is invoked.

Specified by:
setCheckActionParameter in interface ManagedWatchDogMBean
Parameters:
name - the name of the check action parameter.
value - the value to set
Throws:
javax.management.MBeanException