You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gu...@apache.org on 2013/05/30 10:09:54 UTC
svn commit: r1487779 - in /felix/trunk/ipojo/runtime/core: pom.xml
src/main/java/org/apache/felix/ipojo/extender/internal/Extender.java
Author: guillaume
Date: Thu May 30 08:09:54 2013
New Revision: 1487779
URL: http://svn.apache.org/r1487779
Log:
FELIX-4089 Extender do not deactivate managed components when stopped
* Used BundleTracker to track ACTIVE bundles
* Cleanly deactivate managed bundles when iPOJO bundle is stopping
* Notice that we have now a dependency on compendium R4.2
Modified:
felix/trunk/ipojo/runtime/core/pom.xml
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Extender.java
Modified: felix/trunk/ipojo/runtime/core/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/pom.xml?rev=1487779&r1=1487778&r2=1487779&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/pom.xml (original)
+++ felix/trunk/ipojo/runtime/core/pom.xml Thu May 30 08:09:54 2013
@@ -61,7 +61,7 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
- <version>4.0.0</version>
+ <version>4.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
@@ -129,7 +129,7 @@
org.osgi.framework.wiring;resolution:=optional,
org.osgi.service.cm,
org.osgi.service.log,
- org.osgi.util.tracker;version=1.3,
+ org.osgi.util.tracker;version=1.4, <!-- BundleTracker is in R4.2 -->
!sun.io,
!net.sourceforge.cobertura.*, <!-- To support code coverage -->
!org.objectweb.asm.signature,
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Extender.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Extender.java?rev=1487779&r1=1487778&r2=1487779&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Extender.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Extender.java Thu May 30 08:09:54 2013
@@ -32,11 +32,13 @@ import org.apache.felix.ipojo.extender.i
import org.apache.felix.ipojo.extender.internal.queue.pref.enforce.EnforcedQueueService;
import org.apache.felix.ipojo.util.Logger;
import org.osgi.framework.*;
+import org.osgi.util.tracker.BundleTracker;
+import org.osgi.util.tracker.BundleTrackerCustomizer;
/**
* iPOJO main activator.
*/
-public class Extender implements BundleActivator, SynchronousBundleListener {
+public class Extender implements BundleActivator {
/**
* Enables the iPOJO internal dispatcher.
* This internal dispatcher helps the OSGi framework to support large
@@ -93,6 +95,11 @@ public class Extender implements BundleA
private LifecycleQueueService m_queueService;
/**
+ * Track ACTIVE bundles.
+ */
+ private BundleTracker m_tracker;
+
+ /**
* The iPOJO bundle is starting.
* This method configures the iPOJO system (internal dispatcher and bundle processing). Then it initiates the
* bundle processing.
@@ -150,16 +157,24 @@ public class Extender implements BundleA
// Begin by initializing core handlers
m_processor.activate(m_bundle);
- synchronized (this) {
- // listen to any changes in bundles.
- m_context.addBundleListener(this);
- // compute already started bundles.
- for (int i = 0; i < context.getBundles().length; i++) {
- if (context.getBundles()[i].getState() == Bundle.ACTIVE) {
- m_processor.activate(context.getBundles()[i]);
+ m_tracker = new BundleTracker(context, Bundle.ACTIVE, new BundleTrackerCustomizer() {
+ public Object addingBundle(final Bundle bundle, final BundleEvent event) {
+ if (bundle.getBundleId() == m_bundle.getBundleId()) {
+ // Not interested in our own bundle
+ return null;
}
+ m_processor.activate(bundle);
+ return bundle;
}
- }
+
+ public void modifiedBundle(final Bundle bundle, final BundleEvent event, final Object object) {}
+
+ public void removedBundle(final Bundle bundle, final BundleEvent event, final Object object) {
+ m_processor.deactivate(bundle);
+ }
+ });
+
+ m_tracker.open();
m_logger.log(Logger.INFO, "iPOJO Main Extender started");
}
@@ -171,7 +186,9 @@ public class Extender implements BundleA
* @throws Exception something terrible happen
*/
public void stop(BundleContext context) throws Exception {
- context.removeBundleListener(this);
+ m_tracker.close();
+
+ m_processor.deactivate(m_bundle);
//Shutdown ConfigurationTracker
ConfigurationTracker.shutdown();
@@ -190,28 +207,6 @@ public class Extender implements BundleA
}
/**
- * A bundle event was caught.
- *
- * @param event the event
- */
- public void bundleChanged(BundleEvent event) {
- if (m_bundle.getBundleId() != (event.getBundle().getBundleId())) {
- // Do not process our-self (already done)
- switch (event.getType()) {
- case BundleEvent.STARTED:
- // Put the bundle in the queue
- m_processor.activate(event.getBundle());
- break;
- case BundleEvent.STOPPING:
- m_processor.deactivate(event.getBundle());
- break;
- default:
- break;
- }
- }
- }
-
- /**
* Gets iPOJO bundle context.
*
* @return the iPOJO Bundle Context