logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1524866 - /logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
Date Thu, 19 Sep 2013 23:46:18 GMT
Author: rpopma
Date: Thu Sep 19 23:46:18 2013
New Revision: 1524866

URL: http://svn.apache.org/r1524866
Log:
LOG4J2-406: added methods to unregister all MBeans associated with a LoggerContext

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java?rev=1524866&r1=1524865&r2=1524866&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
Thu Sep 19 23:46:18 2013
@@ -146,8 +146,8 @@ public final class Server {
                     }
                     // first unregister the MBeans that instrument the
                     // previous instrumented LoggerConfigs and Appenders
-                    unregisterLoggerConfigs(context, mbs);
-                    unregisterAppenders(context, mbs);
+                    unregisterLoggerConfigs(context.getName(), mbs);
+                    unregisterAppenders(context.getName(), mbs);
 
                     // now provide instrumentation for the newly configured
                     // LoggerConfigs and Appenders
@@ -163,6 +163,39 @@ public final class Server {
         }
     }
 
+    /**
+     * Unregisters all MBeans associated with the specified logger context
+     * (including MBeans for {@code LoggerConfig}s and {@code Appender}s from
+     * the platform MBean server.
+     *
+     * @param loggerContextName
+     *            name of the logger context to unregister
+     * @throws JMException
+     *             if a problem occurs during de-registration
+     */
+    public static void unregisterContext(String loggerContextName) {
+        final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+        unregisterContext(loggerContextName, mbs);
+    }
+
+    /**
+     * Unregisters all MBeans associated with the specified logger context
+     * (including MBeans for {@code LoggerConfig}s and {@code Appender}s from
+     * the platform MBean server.
+     *
+     * @param loggerContextName
+     *            name of the logger context to unregister
+     * @param mbs
+     *            the MBean Server to unregister the instrumented objects from
+     * @throws JMException
+     *             if a problem occurs during de-registration
+     */
+    public static void unregisterContext(String contextName, MBeanServer mbs) {
+        final String pattern = LoggerContextAdminMBean.PATTERN;
+        final String search = String.format(pattern, contextName, "*");
+        unregisterAllMatching(search, mbs);
+    }
+
     private static void registerStatusLogger(final MBeanServer mbs, final Executor executor)
             throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException
{
 
@@ -188,17 +221,17 @@ public final class Server {
         }
     }
 
-    private static void unregisterLoggerConfigs(final LoggerContext context,
+    private static void unregisterLoggerConfigs(final String contextName,
             final MBeanServer mbs) {
         final String pattern = LoggerConfigAdminMBean.PATTERN;
-        final String search = String.format(pattern, context.getName(), "*");
+        final String search = String.format(pattern, contextName, "*");
         unregisterAllMatching(search, mbs);
     }
 
-    private static void unregisterAppenders(final LoggerContext context,
+    private static void unregisterAppenders(final String contextName,
             final MBeanServer mbs) {
         final String pattern = AppenderAdminMBean.PATTERN;
-        final String search = String.format(pattern, context.getName(), "*");
+        final String search = String.format(pattern, contextName, "*");
         unregisterAllMatching(search, mbs);
     }
 



Mime
View raw message