FileDocCategorySizeDatePackage
HANotificationBroadcasterClientExample.javaAPI DocJBoss 4.2.15162Fri Jul 13 20:52:42 BST 2007org.jboss.ha.jmx.examples

HANotificationBroadcasterClientExample

public class HANotificationBroadcasterClientExample extends org.jboss.system.ServiceMBeanSupport implements HANotificationBroadcasterClientExampleMBean, NotificationListener
This MBean is an example that shows how to delegate notification services to a HANotificationBroadcaster. Use the sendNotiication() operation to trigger new clustered notifications. Observe the status of each instance of this mbean in the participating cluster partition nodes.
author
Ivelin Ivanov

Fields Summary
Collection
messages_
ObjectName
broadcasterName_
The broadcaster MBean that this class listens to and delegates HA notifications to
Constructors Summary
Methods Summary
protected voidaddHANotificationListener(javax.management.NotificationListener listener)

    server.addNotificationListener(broadcasterName_, listener, 
      /* no need for filter */ null, 
      /* no handback object */ null);
  
public java.lang.StringgetHANotificationBroadcasterName()

return
the name of the broadcaster MBean

    return broadcasterName_ == null ? null : broadcasterName_.toString();
  
public java.util.CollectiongetReceivedNotifications()
Lists the notifications received on the cluster partition

    return messages_;
  
public voidhandleNotification(javax.management.Notification notification, java.lang.Object handback)

    messages_.add(notification.getMessage());
  
protected voidremoveHANotificationListener(javax.management.NotificationListener listener)

    server.removeNotificationListener(broadcasterName_, listener);
  
public voidsendTextMessageViaHANBExample(java.lang.String message)
Broadcasts a notification to the cluster partition. This example does not ensure that a notification sequence number is unique throughout the partition.

    long now = System.currentTimeMillis();
    Notification notification =
      new Notification(
        "hanotification.example.counter",
        super.getServiceName(),
        now,
        now,
        message);
    server.invoke(
        broadcasterName_,
        "sendNotification",
        new Object[] { notification },
        new String[] { Notification.class.getName() }
        );
  
public voidsetHANotificationBroadcasterName(java.lang.String newBroadcasterName)
Sets the name of the broadcaster MBean.

param

    if (newBroadcasterName == null)
    {
      throw new InvalidParameterException("Broadcaster MBean must be specified");
    }
    try
    {
      broadcasterName_ = new ObjectName(newBroadcasterName);
    }
    catch (MalformedObjectNameException mone)
    {
      log.error("Broadcaster MBean Object Name is malformed", mone);
      throw new InvalidParameterException("Broadcaster MBean is not correctly formatted");
    }
  
protected voidstartService()
On service start, subscribes to notification sent by this broadcaster or its remote peers.

    super.startService();
    addHANotificationListener(this);
  
protected voidstopService()
On service stop, unsubscribes to notification sent by this broadcaster or its remote peers.

    removeHANotificationListener(this);
    super.stopService();