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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 24 23:53:52 EDT 2007


Author: scott.stark at jboss.org
Date: 2007-08-24 23:53:52 -0400 (Fri, 24 Aug 2007)
New Revision: 64871

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

Modified: branches/JBoss_4_0_5_GA_CP/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository3.java
===================================================================
--- branches/JBoss_4_0_5_GA_CP/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository3.java	2007-08-24 23:09:01 UTC (rev 64870)
+++ branches/JBoss_4_0_5_GA_CP/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository3.java	2007-08-25 03:53:52 UTC (rev 64871)
@@ -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,14 @@
    /** 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.
+    */
+   private static int LEGACY_MODE = 0;
+   private static int WEAK_REFERENCE_MODE = 1;
+   private static int NO_NOTIFICATION_MODE = 2;
+   private static int NOTIFICATION_MODE = LEGACY_MODE;
 
    // Attributes ----------------------------------------------------
 
@@ -148,6 +157,12 @@
     */
    private MBeanNotificationInfo[] info;
 
+   static
+   {
+      // JBAS-4593
+      String value = ClassToStringAction.getProperty("org.jboss.mx.loading.UnifiedLoaderRepository.notifyMode", "0");
+      NOTIFICATION_MODE = Integer.valueOf(value).intValue();
+   }
 
    // Public --------------------------------------------------------
 
@@ -927,9 +942,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);
+      }
    }
 
    /**
@@ -944,9 +965,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;
    }
@@ -983,15 +1010,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