next up previous contents
Next: Advanced Concepts Up: Building Blocks Previous: DistributedTree   Contents

NotificationBus

This class provides notification sending and handling capability. Also, it allows an application programmer to maintain a local cache which is replicated by all instances. NotificationBus also sits on top of a channel, however it creates its channel itself, so the application programmers do not have to provide their own channel. Notification consumers can subscribe to receive notifications by calling setConsumer() and implementing interface NotificationBus.Consumer:

  public interface Consumer {
      void          handleNotification(Serializable n);
      Serializable  getCache();
      void          memberJoined(Address mbr);
      void          memberLeft(Address mbr);
  }

Method handleNotification() is called whenever a notification is received from the channel. A notification is any object that is serializable. Method getCache() is called when someone wants to retrieve our state; the state can be returned as a serializable object. The memberJoined() and memberLeft() callbacks are invoked whenever a member joins or leaves (or crashes).

The most important methods of NotificationBus are:

  public class NotificationBus {
       public void setConsumer(Consumer c);
       public void start() throws Exception;
       public void stop();
       public void sendNotification(Serializable n);
       public Serializable getCacheFromCoordinator(long timeout, int max_tries);
       public Serializable getCacheFromMember(Address mbr, long timeout, int max_tries);
  }

Method setConsumer() allows a consumer to register itself for notifications.

The start() and stop() methods start and stop the NotificationBus.

Method sendNotification() sends the serializable object given as argument to all members of the group, invoking their handleNotification() methods on reception.

Methods getCacheFromCoordinator() and getCacheFromMember() provide functionality to fetch the group state from the coordinator (first member in membership list) or any other member (if its address is known). They take as arguments a timeout and a maximum number of unsuccessful attempts until they return null. Typically one of these methods would be called just after creating a new NotificationBus to acquire the group state. Note that if these methods are used, then the consumers must implement Consumer.getCache(), otherwise the two methods above would always return null.


next up previous contents
Next: Advanced Concepts Up: Building Blocks Previous: DistributedTree   Contents
Bela Ban 2002-11-16