HeartBeat MBean

Michael Gorelik

Revision History
Revision $Revision: 1.1 $$Date: 2002/05/28 09:11:29 $

Introduction

This document introduces concept of heartbeat service and gives an example of its implementation using HeartBeatSource and HeartBeatListener mbeans.

The components of distributed systems often need to know if the modules they communicating with are healthy and if the networking connections between modules are functioning properly. In a management system, for example, the management node might want to know that the agents residing on distributed nodes are up and can communicate with it. If the management node detects that an agent is down or it cannot communicate, it will generate an error event.

The heartbeat mechanism is often used to implement such functionality. This mechanism is implemented in MX4J as two utility MBeans, HeartBeatSource MBean and HeartBeatListener MBean.

HeartBeatSource

HeartBeatSource object registers listener objects and makes remote calls on listeners at regular intervals. If a registered listener cannot be reached after several attempts, listener is removed by the HeartBeatSource object.

HeartBeatListener object supplies the type of connector it prefers when it registers with HeartBeatSource. Currently only RMI connector type is supported.

Example 4.5. The HeartBeatSourceMBean class

		  
/**
 * Interface to be implemented by all modules that want to support
 * heartbeat mechanism.
 */
public interface HeartBeatMBean
{
   /**
    * Adds the specified heartbeat listener to receive heartbeat
    * notifications from this HeartBeatMBean.
    */
   public void addHeartBeatListener(String heartBeatListenerName, Object connectorType, Object listenerAddress);

   /**
    * Removes the specified heartbeat listener so that it no longer receives
    * heartbeat notifications from this HeartBeatMBean.
    */
   public void removeHeartBeatListener(String heartBeatListenerName);
}
                  
         

HeartBeatListener

Example 4.6. The HeartBeatListenerMBean class

		  
/**
 * Callback interface. Heart beat source calls object implementing
 * this interface to send a heart beat.
 */
public interface HeartBeatListenerMBean
{
   public static final String DEFAULT_LISTENER_NAME = "type=heartBeatListener";

   public void processHeartBeat(String heartBeatSource);
}
                  
         

Using Heartbeat MBeans