logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1476705 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/ core/src/main/java/org/apache/logging/log4j/core/config/ core/src/main/java/org/apache/logging/log4j/core/jmx/ core/src/test/java/org/apache/loggin...
Date Sun, 28 Apr 2013 01:44:44 GMT
Author: rgoers
Date: Sun Apr 28 01:44:44 2013
New Revision: 1476705

URL: http://svn.apache.org/r1476705
Log:
LOG4J2-223 - Fix LoggerContext start and stop to eliminate IllegalStateException and NoClassDefFound
errors.

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/AdvertiserTest.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml
    logging/log4j/log4j2/trunk/web/src/test/java/org/apache/logging/log4j/core/web/Log4jContextListenerTest.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java?rev=1476705&r1=1476704&r2=1476705&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
Sun Apr 28 01:44:44 2013
@@ -118,7 +118,7 @@ public class LoggerContext implements or
     /**
      * Constructor taking a name external context and a configuration location
      * String. The location must be resolvable to a File.
-     * 
+     *
      * @param name The configuration location.
      * @param externalContext The external context.
      * @param configLocn The configuration location.
@@ -142,7 +142,7 @@ public class LoggerContext implements or
     public void start() {
         if (configLock.tryLock()) {
             try {
-                if (status == Status.INITIALIZED) {
+                if (status == Status.INITIALIZED || status == Status.STOPPED) {
                     status = Status.STARTING;
                     reconfigure();
                     shutdownThread = new ShutdownThread(this);
@@ -160,16 +160,45 @@ public class LoggerContext implements or
         }
     }
 
+    /**
+     * Start with a specific configuration.
+     * @param config The new Configuration.
+     */
+    public void start(final Configuration config) {
+        if (configLock.tryLock()) {
+            try {
+                if (status == Status.INITIALIZED || status == Status.STOPPED) {
+                    shutdownThread = new ShutdownThread(this);
+                    try {
+                        Runtime.getRuntime().addShutdownHook(shutdownThread);
+                    } catch (SecurityException se) {
+                        LOGGER.warn("Unable to register shutdown hook due to security restrictions");
+                        shutdownThread = null;
+                    }
+                    status = Status.STARTED;
+                }
+            } finally {
+                configLock.unlock();
+            }
+        }
+        setConfiguration(config);
+    }
+
     public void stop() {
         configLock.lock();
         try {
+            if (status == Status.STOPPED) {
+                return;
+            }
             status = Status.STOPPING;
             if (shutdownThread != null) {
                 Runtime.getRuntime().removeShutdownHook(shutdownThread);
                 shutdownThread = null;
             }
-            updateLoggers(new NullConfiguration());
-            config.stop();
+            Configuration prev = config;
+            config = new NullConfiguration();
+            updateLoggers();
+            prev.stop();
             externalContext = null;
             status = Status.STOPPED;
         } finally {
@@ -251,7 +280,7 @@ public class LoggerContext implements or
     /**
      * Returns the current Configuration. The Configuration will be replaced
      * when a reconfigure occurs.
-     * 
+     *
      * @return The Configuration.
      */
     public Configuration getConfiguration() {
@@ -280,7 +309,7 @@ public class LoggerContext implements or
      * @param config The new Configuration.
      * @return The previous Configuration.
      */
-    public synchronized Configuration setConfiguration(final Configuration config) {
+    private synchronized Configuration setConfiguration(final Configuration config) {
         if (config == null) {
             throw new NullPointerException("No Configuration was provided");
         }
@@ -357,7 +386,7 @@ public class LoggerContext implements or
     /**
      * Cause a reconfiguration to take place when the underlying configuration
      * file changes.
-     * 
+     *
      * @param reconfigurable The Configuration that can be reconfigured.
      */
     public synchronized void onChange(final Reconfigurable reconfigurable) {

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java?rev=1476705&r1=1476704&r2=1476705&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
Sun Apr 28 01:44:44 2013
@@ -65,7 +65,7 @@ public final class Configurator {
             if (context instanceof LoggerContext) {
                 final LoggerContext ctx = (LoggerContext) context;
                 final Configuration config = ConfigurationFactory.getInstance().getConfiguration(name,
configLocation);
-                ctx.setConfiguration(config);
+                ctx.start(config);
                 return ctx;
             } else {
                 LOGGER.error("LogManager returned an instance of {} which does not implement
{}. Unable to initialize Log4j",
@@ -97,7 +97,7 @@ public final class Configurator {
             if (context instanceof LoggerContext) {
                 final LoggerContext ctx = (LoggerContext) context;
                 final Configuration config = ConfigurationFactory.getInstance().getConfiguration(source);
-                ctx.setConfiguration(config);
+                ctx.start(config);
                 return ctx;
             } else {
                 LOGGER.error("LogManager returned an instance of {} which does not implement
{}. Unable to initialize Log4j",
@@ -115,7 +115,7 @@ public final class Configurator {
      */
     public static void shutdown(final LoggerContext ctx) {
         if (ctx != null) {
-            ctx.setConfiguration(new DefaultConfiguration());
+            ctx.stop();
         }
     }
 }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java?rev=1476705&r1=1476704&r2=1476705&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
Sun Apr 28 01:44:44 2013
@@ -23,7 +23,7 @@ import org.apache.logging.log4j.Level;
  */
 public class NullConfiguration extends BaseConfiguration {
 
-    private static final String NULL_NAME = "Null";
+    public static final String NULL_NAME = "Null";
 
     public NullConfiguration() {
 

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java?rev=1476705&r1=1476704&r2=1476705&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
Sun Apr 28 01:44:44 2013
@@ -61,7 +61,7 @@ public class LoggerContextAdmin extends 
     /**
      * Constructs a new {@code LoggerContextAdmin} with the {@code Executor} to
      * be used for sending {@code Notification}s asynchronously to listeners.
-     * 
+     *
      * @param executor
      */
     public LoggerContextAdmin(LoggerContext loggerContext, Executor executor) {
@@ -166,7 +166,7 @@ public class LoggerContextAdmin extends 
             ConfigurationSource source = new ConfigurationSource(in);
             Configuration updated = ConfigurationFactory.getInstance()
                     .getConfiguration(source);
-            loggerContext.setConfiguration(updated);
+            loggerContext.start(updated);
             LOGGER.debug("Completed remote request to reconfigure from config text.");
         } catch (Exception ex) {
             customConfigText = old;

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java?rev=1476705&r1=1476704&r2=1476705&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java
Sun Apr 28 01:44:44 2013
@@ -46,7 +46,7 @@ public class SimplePerfTest {
         final Configuration config = ((LoggerContext)LogManager.getContext()).getConfiguration();
         if (!DefaultConfiguration.DEFAULT_NAME.equals(config.getName())) {
             System.out.println("Configuration was " + config.getName());
-            ((LoggerContext)LogManager.getContext()).setConfiguration(new DefaultConfiguration());
+            ((LoggerContext)LogManager.getContext()).start(new DefaultConfiguration());
         }
 
         for (int i=0; i < WARMUP; ++i) {

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/AdvertiserTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/AdvertiserTest.java?rev=1476705&r1=1476704&r2=1476705&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/AdvertiserTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/AdvertiserTest.java
Sun Apr 28 01:44:44 2013
@@ -92,7 +92,7 @@ public class AdvertiserTest {
     public void testAdvertisementsFound() {
         verifyExpectedEntriesAdvertised(InMemoryAdvertiser.getAdvertisedEntries());
     }
-    
+
     @Test
     public void testAdvertisementsRemovedOnConfigStop() {
         verifyExpectedEntriesAdvertised(InMemoryAdvertiser.getAdvertisedEntries());
@@ -102,9 +102,9 @@ public class AdvertiserTest {
 
         Map<Object, Map<String, String>> entries = InMemoryAdvertiser.getAdvertisedEntries();
         assertTrue("Entries found: " + entries, entries.isEmpty());
-        
+
         //reconfigure for subsequent testing
-        ctx.reconfigure();
+        ctx.start();
     }
 
     @Test
@@ -116,8 +116,8 @@ public class AdvertiserTest {
 
         Map<Object, Map<String, String>> entries = InMemoryAdvertiser.getAdvertisedEntries();
         assertTrue("Entries found: " + entries, entries.isEmpty());
-        
-        ctx.reconfigure();
+
+        ctx.start();
 
         verifyExpectedEntriesAdvertised(InMemoryAdvertiser.getAdvertisedEntries());
     }

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java?rev=1476705&r1=1476704&r2=1476705&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
Sun Apr 28 01:44:44 2013
@@ -76,8 +76,8 @@ public class TestConfigurator {
         assertTrue("Wrong configuration", map.containsKey("List"));
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
-        assertTrue("Incorrect Configuration. Expected " + DefaultConfiguration.DEFAULT_NAME
+ " but found " +
-            config.getName(), DefaultConfiguration.DEFAULT_NAME.equals(config.getName()));
+        assertTrue("Incorrect Configuration. Expected " + NullConfiguration.NULL_NAME + "
but found " +
+            config.getName(), NullConfiguration.NULL_NAME.equals(config.getName()));
     }
 
     @Test
@@ -96,8 +96,8 @@ public class TestConfigurator {
         assertTrue("Wrong configuration", map.containsKey("List"));
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
-        assertTrue("Incorrect Configuration. Expected " + DefaultConfiguration.DEFAULT_NAME
+ " but found " +
-            config.getName(), DefaultConfiguration.DEFAULT_NAME.equals(config.getName()));
+        assertTrue("Incorrect Configuration. Expected " + NullConfiguration.NULL_NAME + "
but found " +
+            config.getName(), NullConfiguration.NULL_NAME.equals(config.getName()));
     }
 
     @Test
@@ -116,8 +116,8 @@ public class TestConfigurator {
         assertTrue("Wrong configuration", map.containsKey("List"));
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
-        assertTrue("Incorrect Configuration. Expected " + DefaultConfiguration.DEFAULT_NAME
+ " but found " +
-            config.getName(), DefaultConfiguration.DEFAULT_NAME.equals(config.getName()));
+        assertTrue("Incorrect Configuration. Expected " + NullConfiguration.NULL_NAME + "
but found " +
+            config.getName(), NullConfiguration.NULL_NAME.equals(config.getName()));
     }
 
     @Test
@@ -133,8 +133,8 @@ public class TestConfigurator {
         assertTrue("Wrong configuration", map.containsKey("List"));
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
-        assertTrue("Incorrect Configuration. Expected " + DefaultConfiguration.DEFAULT_NAME
+ " but found " +
-            config.getName(), DefaultConfiguration.DEFAULT_NAME.equals(config.getName()));
+        assertTrue("Incorrect Configuration. Expected " + NullConfiguration.NULL_NAME + "
but found " +
+            config.getName(), NullConfiguration.NULL_NAME.equals(config.getName()));
     }
 
     @Test
@@ -150,8 +150,8 @@ public class TestConfigurator {
         assertTrue("Wrong configuration", map.containsKey("List"));
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
-        assertTrue("Incorrect Configuration. Expected " + DefaultConfiguration.DEFAULT_NAME
+ " but found " +
-            config.getName(), DefaultConfiguration.DEFAULT_NAME.equals(config.getName()));
+        assertTrue("Incorrect Configuration. Expected " + NullConfiguration.NULL_NAME + "
but found " +
+            config.getName(), NullConfiguration.NULL_NAME.equals(config.getName()));
     }
 
     @Test
@@ -177,8 +177,8 @@ public class TestConfigurator {
         assertTrue("Configuration not reset", newConfig != config);
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
-        assertTrue("Incorrect Configuration. Expected " + DefaultConfiguration.DEFAULT_NAME
+ " but found " +
-            config.getName(), DefaultConfiguration.DEFAULT_NAME.equals(config.getName()));
+        assertTrue("Incorrect Configuration. Expected " + NullConfiguration.NULL_NAME + "
but found " +
+            config.getName(), NullConfiguration.NULL_NAME.equals(config.getName()));
     }
 
     @Test

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1476705&r1=1476704&r2=1476705&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sun Apr 28 01:44:44 2013
@@ -23,7 +23,10 @@
 
   <body>
     <release version="2.0-beta6" date="@TBD@" description="Bug fixes and enhancements">
-      <action issue="LOG4J2-221" dev-"rgoers" type="fix" due-to="Nick Williams">
+      <action issue="LOG4J2-223" dev="rgoers" type="fix">
+        Fix LoggerContext start and stop to eliminate IllegalStateException and NoClassDefFound
errors.
+      </action>
+      <action issue="LOG4J2-221" dev="rgoers" type="fix" due-to="Nick Williams">
         Remove hundreds of compiler warnings.
       </action>
       <action issue="LOG4J2-215" dev="rpopma" type="fix">

Modified: logging/log4j/log4j2/trunk/web/src/test/java/org/apache/logging/log4j/core/web/Log4jContextListenerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/web/src/test/java/org/apache/logging/log4j/core/web/Log4jContextListenerTest.java?rev=1476705&r1=1476704&r2=1476705&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/web/src/test/java/org/apache/logging/log4j/core/web/Log4jContextListenerTest.java
(original)
+++ logging/log4j/log4j2/trunk/web/src/test/java/org/apache/logging/log4j/core/web/Log4jContextListenerTest.java
Sun Apr 28 01:44:44 2013
@@ -20,7 +20,7 @@ import org.apache.logging.log4j.LogManag
 import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.apache.logging.log4j.core.config.NullConfiguration;
 import org.junit.Test;
 
 import javax.servlet.RequestDispatcher;
@@ -65,8 +65,8 @@ public class Log4jContextListenerTest {
         assertTrue("Wrong configuration", map.containsKey("List"));
         listener.contextDestroyed(event);
         config = ctx.getConfiguration();
-        assertTrue("Incorrect Configuration. Expected " + DefaultConfiguration.DEFAULT_NAME
+ " but found " +
-            config.getName(), DefaultConfiguration.DEFAULT_NAME.equals(config.getName()));
+        assertTrue("Incorrect Configuration. Expected " + NullConfiguration.NULL_NAME + "
but found " +
+            config.getName(), NullConfiguration.NULL_NAME.equals(config.getName()));
     }
 
     @Test
@@ -88,8 +88,8 @@ public class Log4jContextListenerTest {
         assertTrue("Wrong configuration", map.containsKey("List"));
         listener.contextDestroyed(event);
         config = ctx.getConfiguration();
-        assertTrue("Incorrect Configuration. Expected " + DefaultConfiguration.DEFAULT_NAME
+ " but found " +
-            config.getName(), DefaultConfiguration.DEFAULT_NAME.equals(config.getName()));
+        assertTrue("Incorrect Configuration. Expected " + NullConfiguration.NULL_NAME + "
but found " +
+            config.getName(), NullConfiguration.NULL_NAME.equals(config.getName()));
     }
 
     @Test
@@ -110,8 +110,8 @@ public class Log4jContextListenerTest {
         assertTrue("Wrong configuration", map.containsKey("List"));
         listener.contextDestroyed(event);
         config = ctx.getConfiguration();
-        assertTrue("Incorrect Configuration. Expected " + DefaultConfiguration.DEFAULT_NAME
+ " but found " +
-            config.getName(), DefaultConfiguration.DEFAULT_NAME.equals(config.getName()));
+        assertTrue("Incorrect Configuration. Expected " + NullConfiguration.NULL_NAME + "
but found " +
+            config.getName(), NullConfiguration.NULL_NAME.equals(config.getName()));
     }
 
 



Mime
View raw message