Browse files

PAXLOGGING-140: Ensure Appender resources get released on bundle rest…

…art/refresh
  • Loading branch information...
1 parent 29c27a7 commit 290b2cd83b6a88f2d336b452fabd5de6a571485f @gertv gertv committed May 15, 2012
View
15 pax-logging-service/src/main/java/org/ops4j/pax/logging/service/internal/Activator.java
@@ -58,6 +58,7 @@
/**
* Reference to the registered service
*/
+ private PaxLoggingServiceImpl m_PaxLogging;
private ServiceRegistration m_RegistrationPaxLogging;
private JdkHandler m_JdkHandler;
private ServiceRegistration m_registrationLogReaderService;
@@ -105,11 +106,11 @@ public void destroy()
}
// register the Pax Logging service
- PaxLoggingServiceImpl paxLogging = new PaxLoggingServiceImpl( bundleContext, logReader, m_eventAdmin );
+ m_PaxLogging = new PaxLoggingServiceImpl( bundleContext, logReader, m_eventAdmin );
Hashtable serviceProperties = new Hashtable();
serviceProperties.put( Constants.SERVICE_ID, "org.ops4j.pax.logging.configuration" );
serviceProperties.put( Constants.SERVICE_PID, CONFIGURATION_PID );
- m_RegistrationPaxLogging = bundleContext.registerService( LOGSERVICE_NAMES, paxLogging, serviceProperties );
+ m_RegistrationPaxLogging = bundleContext.registerService( LOGSERVICE_NAMES, m_PaxLogging, serviceProperties );
// Add a global handler for all JDK Logging (java.util.logging).
String skipJULProperty=bundleContext.getProperty("org.ops4j.pax.logging.skipJUL");
@@ -127,10 +128,10 @@ public void destroy()
rootLogger.setFilter(null);
- m_JdkHandler = new JdkHandler( paxLogging );
+ m_JdkHandler = new JdkHandler( m_PaxLogging );
rootLogger.addHandler( m_JdkHandler );
}
- m_frameworkHandler = new FrameworkHandler( paxLogging );
+ m_frameworkHandler = new FrameworkHandler( m_PaxLogging );
bundleContext.addBundleListener( m_frameworkHandler );
bundleContext.addFrameworkListener( m_frameworkHandler );
bundleContext.addServiceListener( m_frameworkHandler );
@@ -163,6 +164,12 @@ public void stop( BundleContext bundleContext )
m_RegistrationPaxLogging.unregister();
m_RegistrationPaxLogging = null;
+ // Shutdown Pax Logging to ensure appender file locks get released
+ if (m_PaxLogging != null) {
+ m_PaxLogging.shutdown();
+ m_PaxLogging = null;
+ }
+
m_registrationLogReaderService.unregister();
m_registrationLogReaderService = null;
}
View
9 ...g-service/src/main/java/org/ops4j/pax/logging/service/internal/PaxLoggingServiceImpl.java
@@ -25,6 +25,7 @@
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level;
+
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PaxLoggingConfigurator;
@@ -65,6 +66,14 @@ public PaxLoggingServiceImpl( BundleContext context, LogReaderServiceImpl logRea
configureDefaults();
}
+ /**
+ * Shut down the Pax Logging service. This will reset the logging configuration entirely, so it should only be
+ * used just before disposing of the service instance.
+ */
+ protected void shutdown() {
+ LogManager.resetConfiguration();
+ }
+
ReadWriteLock getConfigLock() {
return m_configLock;
}

0 comments on commit 290b2cd

Please sign in to comment.