[Jboss-cvs] JBossAS SVN: r56211 - branches/Branch_4_0/cluster/src/main/org/jboss/ha/jmx

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 23 21:36:22 EDT 2006


Author: bstansberry at jboss.com
Date: 2006-08-23 21:36:21 -0400 (Wed, 23 Aug 2006)
New Revision: 56211

Modified:
   branches/Branch_4_0/cluster/src/main/org/jboss/ha/jmx/HAServiceMBeanSupport.java
Log:
[JBAS-3194] Add ability to suppress JMX notifications of lifecycle events

Modified: branches/Branch_4_0/cluster/src/main/org/jboss/ha/jmx/HAServiceMBeanSupport.java
===================================================================
--- branches/Branch_4_0/cluster/src/main/org/jboss/ha/jmx/HAServiceMBeanSupport.java	2006-08-24 00:28:13 UTC (rev 56210)
+++ branches/Branch_4_0/cluster/src/main/org/jboss/ha/jmx/HAServiceMBeanSupport.java	2006-08-24 01:36:21 UTC (rev 56211)
@@ -25,6 +25,7 @@
 import java.util.List;
 import java.util.Set;
 
+import javax.management.AttributeChangeNotification;
 import javax.management.InstanceNotFoundException;
 import javax.management.Notification;
 import javax.management.ObjectInstance;
@@ -77,6 +78,9 @@
     */
    private String REPLICANT_TOKEN = "";
 
+   private boolean sendLocalLifecycleNotifications = true;
+   private boolean sendRemoteLifecycleNotifications = true;
+   
    // Public --------------------------------------------------------
 
    public HAServiceMBeanSupport()
@@ -314,9 +318,69 @@
          true);
    }
 
+   /**
+    * Gets whether JMX Notifications should be sent to local (same JVM) listeners
+    * if the notification is for an attribute change to attribute "State".
+    * <p>
+    * Default is <code>true</code>.
+    * </p>
+    * @see #sendNotification(Notification)
+    */
+   public boolean getSendLocalLifecycleNotifications()
+   {
+      return sendLocalLifecycleNotifications;
+   }
 
    /**
+    * Sets whether JMX Notifications should be sent to local (same JVM) listeners
+    * if the notification is for an attribute change to attribute "State".
+    * <p>
+    * Default is <code>true</code>.
+    * </p>
+    * @see #sendNotification(Notification)
+    */
+   public void setSendLocalLifecycleNotifications(boolean sendLocalLifecycleNotifications)
+   {
+      this.sendLocalLifecycleNotifications = sendLocalLifecycleNotifications;
+   }
+
+   /**
+    * Gets whether JMX Notifications should be sent to remote listeners
+    * if the notification is for an attribute change to attribute "State".
+    * <p>
+    * Default is <code>true</code>.
+    * </p>
+    * <p>
+    * See http://jira.jboss.com/jira/browse/JBAS-3194 for an example of a
+    * use case where this property should be set to false.
+    * </p>
     * 
+    * @see #sendNotification(Notification)
+    */
+   public boolean getSendRemoteLifecycleNotifications()
+   {
+      return sendRemoteLifecycleNotifications;
+   }
+
+   /**
+    * Sets whether JMX Notifications should be sent to remote listeners
+    * if the notification is for an attribute change to attribute "State".
+    * <p>
+    * Default is <code>true</code>.
+    * </p>
+    * <p>
+    * See http://jira.jboss.com/jira/browse/JBAS-3194 for an example of a
+    * use case where this property should be set to false.
+    * </p>
+    * 
+    * @see #sendNotification(Notification)
+    */
+   public void setSendRemoteLifecycleNotifications(boolean sendRemoteLifecycleNotifications)
+   {
+      this.sendRemoteLifecycleNotifications = sendRemoteLifecycleNotifications;
+   }
+
+   /** 
     * Broadcast the notification to the remote listener nodes (if any) and then 
     * invoke super.sendNotification() to notify local listeners.
     * 
@@ -324,30 +388,49 @@
     * It is recommended that the source of the notification is an ObjectName of an MBean that 
     * is is available on all nodes where the broadcaster MBean is registered. 
     *   
-    * 
+    * @see #getSendLocalLifecycleNotifications()
+    * @see #getSendRemoteLifecycleNotifications()
     * @see javax.management.NotificationBroadcasterSupport#sendNotification(Notification)
-    * 
     */
    public void sendNotification(Notification notification)
    {
-      try
+      boolean stateChange = isStateChangeNotification(notification);
+      
+      if (!stateChange || sendRemoteLifecycleNotifications)
       {
-         // Overriding the source MBean with its ObjectName
-         // to ensure that it can be safely transferred over the wire
-         notification.setSource(this.getServiceName());
-         sendNotificationRemote(notification);
+         try
+         {
+            // Overriding the source MBean with its ObjectName
+            // to ensure that it can be safely transferred over the wire
+            notification.setSource(this.getServiceName());
+            sendNotificationRemote(notification);
+         }
+   
+         catch (Throwable th)
+         {
+            boolean debug = log.isDebugEnabled();
+            if (debug)
+               log.debug("sendNotificationRemote( " + notification + " ) failed ", th);
+            // even if broadcast failed, local notification should still be sent
+   
+         }
       }
-
-      catch (Throwable th)
+      
+      if (!stateChange || sendLocalLifecycleNotifications)
       {
-         boolean debug = log.isDebugEnabled();
-         if (debug)
-            log.debug("sendNotificationRemote( " + notification + " ) failed ", th);
-         // even if broadcast failed, local notification should still be sent
-
+         sendNotificationToLocalListeners(notification);
       }
-      sendNotificationToLocalListeners(notification);
    }
+   
+   private boolean isStateChangeNotification(Notification notification)
+   {
+      boolean stateChange = false;
+      if (notification instanceof AttributeChangeNotification)
+      {
+         stateChange = "State".equals(((AttributeChangeNotification) notification).getAttributeName());
+      }
+      return stateChange;
+   }
 
    protected void sendNotificationToLocalListeners(Notification notification)
    {




More information about the jboss-cvs-commits mailing list