You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2012/10/16 12:19:02 UTC
svn commit: r1398715 - in
/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal:
LogManager.java slf4j/SlingLogPanel.java
Author: fmeschbe
Date: Tue Oct 16 10:19:01 2012
New Revision: 1398715
URL: http://svn.apache.org/viewvc?rev=1398715&view=rev
Log:
SLING-2397 Use ServiceFactory approach and dynamic import of Servlet API to delay creation of the log panel until used. This prevents startup errors and makes the panel available as soon as the Servlet API is available and it is actually used by the Web Console (which in turn also requires the Servlet API)
Modified:
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java
Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java?rev=1398715&r1=1398714&r2=1398715&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java (original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java Tue Oct 16 10:19:01 2012
@@ -23,8 +23,10 @@ import org.apache.sling.commons.log.inte
import org.apache.sling.commons.log.internal.slf4j.LogConfigManager;
import org.apache.sling.commons.log.internal.slf4j.SlingConfigurationPrinter;
import org.apache.sling.commons.log.internal.slf4j.SlingLogPanel;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -74,6 +76,8 @@ public class LogManager {
private ServiceRegistration configConfigurer;
+ private ServiceRegistration panelRegistration;
+
LogManager(final BundleContext context) {
// set the root folder for relative log file names
@@ -120,9 +124,10 @@ public class LogManager {
// setup the web console plugin panel. This may fail loading
// the panel class if the Servlet API is not wired
try {
- SlingLogPanel.registerPanel(context);
+ registerPanel(context);
} catch (Throwable ignore) {
}
+
// setup the web console configuration printer.
SlingConfigurationPrinter.registerPrinter(context);
}
@@ -131,10 +136,8 @@ public class LogManager {
// tear down the web console plugin panel (if created at all). This
// may fail loading the panel class if the Servlet API is not wired
- try {
- SlingLogPanel.unregisterPanel();
- } catch (Throwable ignore) {
- }
+ unregisterPanel();
+
// tear down the web console configuration printer (if created at all).
SlingConfigurationPrinter.unregisterPrinter();
@@ -179,4 +182,43 @@ public class LogManager {
return config;
}
+
+ //---------- Logging Web Console Plugin
+
+ private void registerPanel(BundleContext ctx) {
+ if (panelRegistration == null) {
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put("felix.webconsole.label", "slinglog");
+ props.put("felix.webconsole.title", "Sling Log Support");
+
+ // SLING-1068 Prevent ClassCastException in Sling Engine 2.0.2-incubator
+ props.put("sling.core.servletName", "Sling Log Support Console Servlet");
+
+ panelRegistration = ctx.registerService("javax.servlet.Servlet", new ServiceFactory() {
+
+ private Object instance;
+
+ public Object getService(Bundle bundle, ServiceRegistration registration) {
+ synchronized (this) {
+ if (this.instance == null) {
+ this.instance = new SlingLogPanel(LogManager.this.logConfigManager);
+ }
+ return instance;
+ }
+ }
+
+ public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
+ // nothing to do for cleanup, just drop reference
+ }
+ }, props);
+ }
+ }
+
+ private void unregisterPanel() {
+ if (panelRegistration != null) {
+ panelRegistration.unregister();
+ panelRegistration = null;
+ }
+ }
+
}
Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java?rev=1398715&r1=1398714&r2=1398715&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java (original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java Tue Oct 16 10:19:01 2012
@@ -20,17 +20,12 @@ package org.apache.sling.commons.log.int
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.Dictionary;
-import java.util.Hashtable;
import java.util.Iterator;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-
/**
* The <code>SlingLogPanel</code> is a Felix Web Console plugin to display the
* current active log bundle configuration.
@@ -42,28 +37,10 @@ public class SlingLogPanel extends HttpS
private static final long serialVersionUID = 1L;
- private static ServiceRegistration panelRegistration;
+ private final LogConfigManager logConfigManager;
- public static void registerPanel(BundleContext ctx) {
- if (panelRegistration == null) {
- Dictionary<String, Object> props = new Hashtable<String, Object>();
- props.put("felix.webconsole.label", "slinglog");
- props.put("felix.webconsole.title", "Sling Log Support");
-
- // SLING-1068 Prevent ClassCastException in Sling Engine 2.0.2-incubator
- props.put("sling.core.servletName", "Sling Log Support Console Servlet");
-
- SlingLogPanel panel = new SlingLogPanel();
- panelRegistration = ctx.registerService("javax.servlet.Servlet",
- panel, props);
- }
- }
-
- public static void unregisterPanel() {
- if (panelRegistration != null) {
- panelRegistration.unregister();
- panelRegistration = null;
- }
+ public SlingLogPanel(final LogConfigManager logConfigManager) {
+ this.logConfigManager = logConfigManager;
}
@Override
@@ -71,7 +48,7 @@ public class SlingLogPanel extends HttpS
throws IOException {
final PrintWriter pw = resp.getWriter();
- final LogConfigManager logConfigManager = LogConfigManager.getInstance();
+ final LogConfigManager logConfigManager = this.logConfigManager;
final String consoleAppRoot = (String) req.getAttribute("felix.webconsole.appRoot");
final String cfgColTitle = (consoleAppRoot == null) ? "PID" : "Configuration";