[jboss-cvs] JBossAS SVN: r64874 - trunk/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:31:14 EDT 2007


Author: scott.stark at jboss.org
Date: 2007-08-25 00:31:14 -0400 (Sat, 25 Aug 2007)
New Revision: 64874

Modified:
   trunk/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: trunk/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository3.java
===================================================================
--- trunk/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository3.java	2007-08-25 04:26:43 UTC (rev 64873)
+++ trunk/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository3.java	2007-08-25 04:31:14 UTC (rev 64874)
@@ -1,26 +1,27 @@
 /*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt in the distribution for a
-  * full listing of individual contributors.
-  *
-  * This is free software; you can redistribute it and/or modify it
-  * under the terms of the GNU Lesser General Public License as
-  * published by the Free Software Foundation; either version 2.1 of
-  * the License, or (at your option) any later version.
-  *
-  * This software is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  * Lesser General Public License for more details.
-  *
-  * You should have received a copy of the GNU Lesser General Public
-  * License along with this software; if not, write to the Free
-  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-  */
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 package org.jboss.mx.loading;
 
+import java.lang.ref.WeakReference;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -74,6 +75,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 ----------------------------------------------------
 
@@ -150,6 +162,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 --------------------------------------------------------
 
@@ -935,9 +965,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);
+      }
    }
 
    /**
@@ -952,9 +988,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;
    }
@@ -991,15 +1033,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