felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1058320 - in /felix/trunk/dependencymanager/compat/src/main/java/org/apache/felix/dependencymanager: DependencyActivatorBase.java impl/ServiceImpl.java
Date Wed, 12 Jan 2011 21:10:42 GMT
Author: pderop
Date: Wed Jan 12 21:10:41 2011
New Revision: 1058320

URL: http://svn.apache.org/viewvc?rev=1058320&view=rev
Log:
FELIX-2778 (DM compat layer does not cleanup left-over Service instances when bundle is stopped)

Modified:
    felix/trunk/dependencymanager/compat/src/main/java/org/apache/felix/dependencymanager/DependencyActivatorBase.java
    felix/trunk/dependencymanager/compat/src/main/java/org/apache/felix/dependencymanager/impl/ServiceImpl.java

Modified: felix/trunk/dependencymanager/compat/src/main/java/org/apache/felix/dependencymanager/DependencyActivatorBase.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/compat/src/main/java/org/apache/felix/dependencymanager/DependencyActivatorBase.java?rev=1058320&r1=1058319&r2=1058320&view=diff
==============================================================================
--- felix/trunk/dependencymanager/compat/src/main/java/org/apache/felix/dependencymanager/DependencyActivatorBase.java
(original)
+++ felix/trunk/dependencymanager/compat/src/main/java/org/apache/felix/dependencymanager/DependencyActivatorBase.java
Wed Jan 12 21:10:41 2011
@@ -20,6 +20,7 @@ package org.apache.felix.dependencymanag
 
 import java.util.List;
 
+import org.apache.felix.dependencymanager.impl.ServiceImpl;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 
@@ -82,6 +83,7 @@ public abstract class DependencyActivato
      */
     public void stop(BundleContext context) throws Exception {
         destroy(m_context, m_manager);
+        cleanup(m_manager);
         m_manager = null;
         m_context = null;
     }
@@ -112,4 +114,22 @@ public abstract class DependencyActivato
     public ConfigurationDependency createConfigurationDependency() {
     	return new org.apache.felix.dependencymanager.impl.ConfigurationDependencyImpl(m_manager);
     }
+    
+    /**
+     * Cleans up all components and their dependencies.
+     * 
+     * @param manager the dependency manager
+     */
+    private void cleanup(DependencyManager manager) {
+        List services = manager.getServices();
+        for (int i = services.size() - 1; i >= 0; i--) {
+            Service service = (Service) services.get(i);
+            manager.remove(service);
+            // remove any state listeners that are still registered
+            if (service instanceof ServiceImpl) {
+                ServiceImpl si = (ServiceImpl) service;
+                si.removeStateListeners();
+            }
+        }
+    }
 }

Modified: felix/trunk/dependencymanager/compat/src/main/java/org/apache/felix/dependencymanager/impl/ServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/compat/src/main/java/org/apache/felix/dependencymanager/impl/ServiceImpl.java?rev=1058320&r1=1058319&r2=1058320&view=diff
==============================================================================
--- felix/trunk/dependencymanager/compat/src/main/java/org/apache/felix/dependencymanager/impl/ServiceImpl.java
(original)
+++ felix/trunk/dependencymanager/compat/src/main/java/org/apache/felix/dependencymanager/impl/ServiceImpl.java
Wed Jan 12 21:10:41 2011
@@ -21,6 +21,7 @@ package org.apache.felix.dependencymanag
 import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -134,6 +135,21 @@ public class ServiceImpl implements Serv
             m_delegate.removeStateListener(wrappedListener);
         }
     }
+    
+    public void removeStateListeners()
+    {
+        synchronized (m_stateListeners)
+        {
+        	Iterator it = m_stateListeners.values().iterator();
+        	while (it.hasNext())
+        	{
+        		org.apache.felix.dm.ComponentStateListener wrappedListener =
+        			(org.apache.felix.dm.ComponentStateListener) it.next();
+        		m_delegate.removeStateListener(wrappedListener);
+        	}
+        	m_stateListeners.clear();
+        }
+    }
 
     public List getDependencies()
     {



Mime
View raw message