You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2011/11/22 16:58:50 UTC
svn commit: r1205052 - in /sling/trunk/installer/core: ./
src/main/java/org/apache/sling/installer/core/impl/
src/main/java/org/apache/sling/installer/core/impl/console/
Author: cziegeler
Date: Tue Nov 22 15:58:49 2011
New Revision: 1205052
URL: http://svn.apache.org/viewvc?rev=1205052&view=rev
Log:
SLING-2298 : Register web console plugin using a ServiceFactory
Modified:
sling/trunk/installer/core/pom.xml
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Activator.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
Modified: sling/trunk/installer/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/pom.xml?rev=1205052&r1=1205051&r2=1205052&view=diff
==============================================================================
--- sling/trunk/installer/core/pom.xml (original)
+++ sling/trunk/installer/core/pom.xml Tue Nov 22 15:58:49 2011
@@ -54,9 +54,11 @@
<Bundle-Activator>
org.apache.sling.installer.core.impl.Activator
</Bundle-Activator>
- <Import-Package>
- javax.servlet;javax.servlet.http;resolution:=optional,*
- </Import-Package>
+ <DynamicImport-Package>
+ <!-- plug into the web console -->
+ javax.servlet;
+ javax.servlet.http;version="[2.3,3)"
+ </DynamicImport-Package>
<Export-Package>
org.apache.sling.installer.api;version=3.1.0,
org.apache.sling.installer.api.event;version=1.0.0,
Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Activator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Activator.java?rev=1205052&r1=1205051&r2=1205052&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Activator.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Activator.java Tue Nov 22 15:58:49 2011
@@ -29,9 +29,11 @@ import org.apache.sling.installer.api.ta
import org.apache.sling.installer.api.tasks.ResourceTransformer;
import org.apache.sling.installer.core.impl.console.OsgiInstallerWebConsolePlugin;
import org.apache.sling.installer.core.impl.tasks.BundleTaskCreator;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
/**
@@ -75,12 +77,28 @@ public class Activator implements Bundle
};
osgiControllerServiceReg = context.registerService(serviceInterfaces, osgiControllerService, props);
- try {
- this.webReg = OsgiInstallerWebConsolePlugin.register(context,
- this.osgiControllerService);
- } catch (final Throwable ignore) {
- // ignore this
- }
+ // register service factory for the web console plugin
+ final Hashtable<String, Object> consoleProps = new Hashtable<String, Object>();
+ consoleProps.put("felix.webconsole.label", "osgi-installer");
+ consoleProps.put("felix.webconsole.title", "OSGi Installer");
+ consoleProps.put("felix.webconsole.configprinter.modes", new String[] {"zip", "txt"});
+ consoleProps.put(Constants.SERVICE_VENDOR, Activator.VENDOR);
+ consoleProps.put(Constants.SERVICE_DESCRIPTION,
+ "OSGi Installer Web Console Plugin");
+ this.webReg = context.registerService("javax.servlet.Servlet",
+ new ServiceFactory() {
+
+ public void ungetService(final Bundle bundle,
+ final ServiceRegistration reg,
+ final Object consoleObject) {
+ // nothing to do
+ }
+
+ public Object getService(final Bundle bundle,
+ final ServiceRegistration reg) {
+ return new OsgiInstallerWebConsolePlugin(osgiControllerService);
+ }
+ }, consoleProps);
}
/**
Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java?rev=1205052&r1=1205051&r2=1205052&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java Tue Nov 22 15:58:49 2011
@@ -132,7 +132,11 @@ public class OsgiInstallerImpl
* Deactivate
*/
public void deactivate() {
- this.active = false;
+ // wake up sleeping thread
+ synchronized (this.resourcesLock) {
+ this.active = false;
+ this.resourcesLock.notify();
+ }
// Stop service trackers.
this.factoryTracker.close();
@@ -144,14 +148,14 @@ public class OsgiInstallerImpl
this.listener.dispose();
- // wake up sleeping thread
- this.wakeUp();
if ( this.running ) {
this.logger.debug("Waiting for installer thread to stop");
- try {
- this.join();
- } catch (InterruptedException e) {
- // we simply ignore this
+ while ( this.running ) {
+ try {
+ this.join(50L);
+ } catch (InterruptedException e) {
+ // we simply ignore this
+ }
}
}
@@ -217,7 +221,7 @@ public class OsgiInstallerImpl
if (!tasksCreated) {
synchronized ( this.resourcesLock ) {
// before we go to sleep, check if new resources arrived in the meantime
- if ( !this.hasNewResources()) {
+ if ( !this.hasNewResources() && this.active ) {
// No tasks to execute - wait until new resources are
// registered
logger.debug("No tasks to process, going idle");
Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java?rev=1205052&r1=1205051&r2=1205052&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java Tue Nov 22 15:58:49 2011
@@ -27,7 +27,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
-import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
@@ -39,36 +38,16 @@ import org.apache.sling.installer.api.In
import org.apache.sling.installer.api.tasks.RegisteredResource;
import org.apache.sling.installer.api.tasks.ResourceState;
import org.apache.sling.installer.api.tasks.TaskResource;
-import org.apache.sling.installer.core.impl.Activator;
import org.apache.sling.installer.core.impl.EntityResourceList;
import org.apache.sling.installer.core.impl.OsgiInstallerImpl;
import org.apache.sling.installer.core.impl.RegisteredResourceImpl;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
@SuppressWarnings("serial")
public class OsgiInstallerWebConsolePlugin extends GenericServlet {
private final OsgiInstallerImpl installer;
- public static ServiceRegistration register(final BundleContext bundleContext,
- final OsgiInstallerImpl installer) {
- final OsgiInstallerWebConsolePlugin plugin = new OsgiInstallerWebConsolePlugin(
- installer);
- final Hashtable<String, Object> props = new Hashtable<String, Object>();
- props.put("felix.webconsole.label", "osgi-installer");
- props.put("felix.webconsole.title", "OSGi Installer");
- props.put("felix.webconsole.configprinter.modes", new String[] {"zip", "txt"});
- props.put(Constants.SERVICE_VENDOR, Activator.VENDOR);
- props.put(Constants.SERVICE_DESCRIPTION,
- "OSGi Installer Web Console Plugin");
- return bundleContext.registerService("javax.servlet.Servlet", plugin,
- props);
- }
-
- private OsgiInstallerWebConsolePlugin(
- final OsgiInstallerImpl installer) {
+ public OsgiInstallerWebConsolePlugin(final OsgiInstallerImpl installer) {
this.installer = installer;
}