incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1231138 - in /sling/trunk/contrib/extensions/bgservlets: ./ src/main/java/org/apache/sling/bgservlets/impl/ src/main/java/org/apache/sling/bgservlets/impl/webconsole/ src/main/resources/OSGI-INF/metatype/
Date Fri, 13 Jan 2012 15:49:11 GMT
Author: bdelacretaz
Date: Fri Jan 13 15:49:10 2012
New Revision: 1231138

URL: http://svn.apache.org/viewvc?rev=1231138&view=rev
Log:
SLING-2327 - job console plugin now has same lifecyle as JobConsoleImpl, and can be optionally
disabled

Removed:
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/Activator.java
Modified:
    sling/trunk/contrib/extensions/bgservlets/pom.xml
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/JobConsoleImpl.java
    sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/JobConsolePlugin.java
    sling/trunk/contrib/extensions/bgservlets/src/main/resources/OSGI-INF/metatype/metatype.properties

Modified: sling/trunk/contrib/extensions/bgservlets/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/pom.xml?rev=1231138&r1=1231137&r2=1231138&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/pom.xml (original)
+++ sling/trunk/contrib/extensions/bgservlets/pom.xml Fri Jan 13 15:49:10 2012
@@ -56,7 +56,6 @@
             <Export-Package>org.apache.sling.bgservlets</Export-Package>
             <Private-Package>org.apache.sling.bgservlets.impl.*</Private-Package>
             <DynamicImport-Package>org.apache.felix.webconsole</DynamicImport-Package>
-            <Bundle-Activator>org.apache.sling.bgservlets.impl.Activator</Bundle-Activator>
             <Sling-Nodetypes>SLING-INF/nodetypes/jobdata.cnd</Sling-Nodetypes>
         
           </instructions>
         </configuration>

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/JobConsoleImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/JobConsoleImpl.java?rev=1231138&r1=1231137&r2=1231138&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/JobConsoleImpl.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/JobConsoleImpl.java
Fri Jan 13 15:49:10 2012
@@ -28,7 +28,10 @@ import javax.jcr.Session;
 import javax.jcr.query.Query;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.bgservlets.ExecutionEngine;
@@ -36,11 +39,16 @@ import org.apache.sling.bgservlets.JobCo
 import org.apache.sling.bgservlets.JobStatus;
 import org.apache.sling.bgservlets.impl.storage.JobStorageException;
 import org.apache.sling.bgservlets.impl.storage.NodeJobStatusFactory;
+import org.apache.sling.bgservlets.impl.webconsole.JobConsolePlugin;
+import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /** JobConsole implementation */
-@Component
+@Component(
+        metatype=true,
+        label="%JobConsoleImpl.label",
+        description="%JobConsoleImpl.description")
 @Service
 public class JobConsoleImpl implements JobConsole {
 
@@ -54,6 +62,9 @@ public class JobConsoleImpl implements J
     @Reference
     private NodeJobStatusFactory jobStatusFactory;
     
+    @Property(boolValue=true)
+    private final static String PROP_CONSOLE_PLUGIN_ACTIVE = "console.plugin.active";
+    
     public Iterator<JobStatus> getJobStatus(Session session, boolean activeOnly) {
         if(activeOnly) {
             log.debug("activeOnly is set, getting jobs from ExecutionEngine");
@@ -68,6 +79,22 @@ public class JobConsoleImpl implements J
         }
     }
     
+    @Activate
+    protected void activate(ComponentContext ctx) {
+        final Object obj = ctx.getProperties().get(PROP_CONSOLE_PLUGIN_ACTIVE);
+        final boolean pluginActive = (obj instanceof Boolean ? (Boolean)obj : true);
+        if(pluginActive) {
+            JobConsolePlugin.initPlugin(ctx.getBundleContext(), this);
+        } else {
+            log.info("{} is false, not activating JobConsolePlugin", PROP_CONSOLE_PLUGIN_ACTIVE);
+        }
+    }
+    
+    @Deactivate
+    protected void deactivate(ComponentContext ctx) {
+        JobConsolePlugin.destroyPlugin();
+    }
+    
     public JobStatus getJobStatus(Session session, String path) {
         // Try ExecutionEngine first, persistent storage if not found
         JobStatus result = executionEngine.getJobStatus(path);

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/JobConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/JobConsolePlugin.java?rev=1231138&r1=1231137&r2=1231138&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/JobConsolePlugin.java
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/java/org/apache/sling/bgservlets/impl/webconsole/JobConsolePlugin.java
Fri Jan 13 15:49:10 2012
@@ -51,9 +51,9 @@ public class JobConsolePlugin {
     public static final String TITLE = "Background Servlets & Jobs";
     public static final String STATUS_EXTENSION = "html";
 
-    public static void initPlugin(BundleContext context) {
+    public static void initPlugin(BundleContext context, JobConsole jobConsole) {
         if (plugin == null) {
-            Plugin tmp = new Plugin();
+            Plugin tmp = new Plugin(jobConsole);
             tmp.activate(context);
             plugin = tmp;
             log.info("{} activated", plugin);
@@ -74,14 +74,16 @@ public class JobConsolePlugin {
     @SuppressWarnings("serial")
     public static final class Plugin extends AbstractWebConsolePlugin {
         private ServiceRegistration serviceRegistration;
-        private ServiceTracker jobConsoleTracker;
+        private final JobConsole jobConsole;
         private ServiceTracker repositoryTracker;
 
+        public Plugin(JobConsole console) {
+            jobConsole = console;
+        }
+        
         public void activate(BundleContext ctx) {
             super.activate(ctx);
 
-            jobConsoleTracker = new ServiceTracker(ctx, JobConsole.class.getName(), null);
-            jobConsoleTracker.open();
             repositoryTracker = new ServiceTracker(ctx, SlingRepository.class.getName(),
null);
             repositoryTracker.open();
 
@@ -101,10 +103,6 @@ public class JobConsolePlugin {
                 serviceRegistration.unregister();
                 serviceRegistration = null;
             }
-            if (jobConsoleTracker != null) {
-                jobConsoleTracker.close();
-                jobConsoleTracker = null;
-            }
             if (repositoryTracker != null) {
                 repositoryTracker.close();
                 repositoryTracker = null;
@@ -128,11 +126,6 @@ public class JobConsolePlugin {
             final PrintWriter pw = res.getWriter();
             
             // Access required services
-            final JobConsole console = (JobConsole)jobConsoleTracker.getService();
-            if (console == null) {
-                pw.println("No JobConsole service found");
-                return;
-            }
             final SlingRepository repository = (SlingRepository)repositoryTracker.getService();
             if(repository == null) {
                 pw.println("No SlingRepository service found");
@@ -141,8 +134,8 @@ public class JobConsolePlugin {
             Session s = null;
             try {
                 s = repository.loginAdministrative(repository.getDefaultWorkspace());
-                processCommands(req, pw, s, console);
-                renderJobs(req, pw, s, console);
+                processCommands(req, pw, s, jobConsole);
+                renderJobs(req, pw, s, jobConsole);
             } catch(RepositoryException re) {
                 throw new ServletException("RepositoryExceptio in renderContent()", re);
             } finally {

Modified: sling/trunk/contrib/extensions/bgservlets/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1231138&r1=1231137&r2=1231138&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ sling/trunk/contrib/extensions/bgservlets/src/main/resources/OSGI-INF/metatype/metatype.properties
Fri Jan 13 15:49:10 2012
@@ -27,6 +27,13 @@ BackgroundServletStarterFilter.label = A
 BackgroundServletStarterFilter.description = ServletFilter that runs \
 	requests in the background if a specific request parameter is set \
 	to true.
+	
+JobConsoleImpl.label = Apache Sling Background Jobs Console
+JobConsoleImpl.description = Provides a simple API to manage background jobs.
+
+console.plugin.active.name = Console plugin active?
+console.plugin.active.description = Turn the Felix Web Console JobConsole \
+	plugin on or off.
 
 background.parameter.name.name = Background request parameter name 
 background.parameter.name.description = Requests run in the background \



Mime
View raw message