[jboss-cvs] JBossAS SVN: r64873 - branches/Branch_4_2/jmx/src/main/org/jboss/mx/loading.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Aug 25 00:26:43 EDT 2007


Author: scott.stark at jboss.org
Date: 2007-08-25 00:26:43 -0400 (Sat, 25 Aug 2007)
New Revision: 64873

Modified:
   branches/Branch_4_2/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository3.java
Log:
JBAS-4593, add property to control whether class loader addition/removal emits a notification

Modified: branches/Branch_4_2/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository3.java
===================================================================
--- branches/Branch_4_2/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository3.java	2007-08-25 04:03:52 UTC (rev 64872)
+++ branches/Branch_4_2/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository3.java	2007-08-25 04:26:43 UTC (rev 64873)
@@ -21,6 +21,7 @@
  */
 package org.jboss.mx.loading;
 
+import java.lang.ref.WeakReference;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -72,6 +73,17 @@
    /** Used to provide a relative ordering of UCLs based on the order in
     * which they are added to the repository */
    private static int addedCount;
+   /** The jmx notification behavior mode. This is set by the
+    * org.jboss.mx.loading.UnifiedLoaderRepository.notifyMode system
+    * property.
+    */
+   // Send notification with the ClassLoader as the user data
+   private static final int LEGACY_MODE = 0;
+   // Send notification with the ClassLoader as the user data wrapped in a WeakReference
+   private static final int WEAK_REFERENCE_MODE = 1;
+   // Don't send any notifications
+   private static final int NO_NOTIFICATION_MODE = 2;
+   private static int NOTIFICATION_MODE;
 
    // Attributes ----------------------------------------------------
 
@@ -148,6 +160,24 @@
     */
    private MBeanNotificationInfo[] info;
 
+   static
+   {
+      // JBAS-4593 notification behavior
+      String value = ClassToStringAction.getProperty("org.jboss.mx.loading.UnifiedLoaderRepository.notifyMode", "0");
+      NOTIFICATION_MODE = Integer.valueOf(value).intValue();
+      switch(NOTIFICATION_MODE)
+      {
+         case LEGACY_MODE:
+         case WEAK_REFERENCE_MODE:
+         case NO_NOTIFICATION_MODE:
+         break;
+         default:
+            log.warn("Invalid org.jboss.mx.loading.UnifiedLoaderRepository.notifyMode("
+                  +value+"), defaulting to LEGACY_MODE");
+            NOTIFICATION_MODE = LEGACY_MODE;
+         break;
+      }
+   }
 
    // Public --------------------------------------------------------
 
@@ -932,9 +962,15 @@
          broadcaster.sendNotification(msg);
       }
 
-      Notification msg = new Notification(CLASSLOADER_REMOVED, this, getNextSequenceNumber());
-      msg.setUserData(cl);
-      broadcaster.sendNotification(msg);
+      if (NOTIFICATION_MODE == LEGACY_MODE || NOTIFICATION_MODE == WEAK_REFERENCE_MODE)
+      {
+         Notification msg = new Notification(CLASSLOADER_REMOVED, this, getNextSequenceNumber());
+         if (NOTIFICATION_MODE == WEAK_REFERENCE_MODE)
+            msg.setUserData(new WeakReference(cl));
+         else
+            msg.setUserData(cl);
+         broadcaster.sendNotification(msg);
+      }
    }
 
    /**
@@ -949,9 +985,15 @@
    public LoaderRepository registerClassLoader(RepositoryClassLoader ucl)
    {
       addClassLoader(ucl);
-      Notification msg = new Notification(CLASSLOADER_ADDED, this, getNextSequenceNumber());
-      msg.setUserData(ucl);
-      broadcaster.sendNotification(msg);
+      if (NOTIFICATION_MODE == LEGACY_MODE || NOTIFICATION_MODE == WEAK_REFERENCE_MODE)
+      {
+         Notification msg = new Notification(CLASSLOADER_ADDED, this, getNextSequenceNumber());
+         if (NOTIFICATION_MODE == WEAK_REFERENCE_MODE)
+            msg.setUserData(new WeakReference(ucl));
+         else
+            msg.setUserData(ucl);
+         broadcaster.sendNotification(msg);
+      }
 
       return this;
    }
@@ -988,15 +1030,22 @@
    {
       if (info == null)
       {
-         info = new MBeanNotificationInfo[]{
-            new MBeanNotificationInfo(new String[]{"CLASSLOADER_ADDED"},
-                    "javax.management.Notification",
-                    "Notification that a classloader has been added to the extensible classloader"),
-            new MBeanNotificationInfo(new String[]{"CLASS_REMOVED"},
-                    "javax.management.Notification",
-                    "Notification that a class has been removed from the extensible classloader")
-
-         };
+         if (NOTIFICATION_MODE != NO_NOTIFICATION_MODE)
+         {
+            info = new MBeanNotificationInfo[]{
+               new MBeanNotificationInfo(new String[]{"CLASSLOADER_ADDED"},
+                       "javax.management.Notification",
+                       "Notification that a classloader has been added to the extensible classloader"),
+               new MBeanNotificationInfo(new String[]{"CLASS_REMOVED"},
+                       "javax.management.Notification",
+                       "Notification that a class has been removed from the extensible classloader")
+   
+            };
+         }
+         else
+         {
+            info = new MBeanNotificationInfo[0];
+         }
       }
       return info;
    }




More information about the jboss-cvs-commits mailing list