felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uiter...@apache.org
Subject svn commit: r1351732 - in /felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm: ./ impl/index/
Date Tue, 19 Jun 2012 14:51:53 GMT
Author: uiterlix
Date: Tue Jun 19 14:51:52 2012
New Revision: 1351732

URL: http://svn.apache.org/viewvc?rev=1351732&view=rev
Log:
FELIX-3564: Fixed memory leak in ServiceRegistryCache

Modified:
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/FilterIndex.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AdapterFilterIndex.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AspectFilterIndex.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/BundleContextInterceptor.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/MultiPropertyExactFilter.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/ServiceRegistryCache.java

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/FilterIndex.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/FilterIndex.java?rev=1351732&r1=1351731&r2=1351732&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/FilterIndex.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/FilterIndex.java
Tue Jun 19 14:51:52 2012
@@ -42,6 +42,6 @@ public interface FilterIndex {
     public void serviceChanged(ServiceEvent event);
     /** Adds a service listener to this filter index. */
     public void addServiceListener(ServiceListener listener, String filter);
-    /** Removes a service listener from this filter index. */
+    /** Removes a service listener from this filter index. If the listener is not present
in the filter index, this method does nothing. */
     public void removeServiceListener(ServiceListener listener);
 }

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AdapterFilterIndex.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AdapterFilterIndex.java?rev=1351732&r1=1351731&r2=1351732&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AdapterFilterIndex.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AdapterFilterIndex.java
Tue Jun 19 14:51:52 2012
@@ -172,12 +172,15 @@ public class AdapterFilterIndex implemen
     public void removeServiceListener(ServiceListener listener) {
         synchronized (m_sidToListenersMap) {
             String filter = (String) m_listenerToFilterMap.remove(listener);
-            FilterData data = getFilterData(null, filter);
-            if (data != null) {
-            	Long sidObject = Long.valueOf(data.serviceId);
-            	List /* ServiceListener */ listeners = (List) m_sidToListenersMap.get(sidObject);
-            	if (listeners != null) {
-            		listeners.remove(listener);
+            if (filter != null) {
+            	// the listener does exist
+            	FilterData data = getFilterData(null, filter);
+            	if (data != null) {
+            		Long sidObject = Long.valueOf(data.serviceId);
+            		List /* ServiceListener */ listeners = (List) m_sidToListenersMap.get(sidObject);
+            		if (listeners != null) {
+            			listeners.remove(listener);
+            		}
             	}
             }
         }

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AspectFilterIndex.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AspectFilterIndex.java?rev=1351732&r1=1351731&r2=1351732&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AspectFilterIndex.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/AspectFilterIndex.java
Tue Jun 19 14:51:52 2012
@@ -189,14 +189,17 @@ public class AspectFilterIndex implement
     public void removeServiceListener(ServiceListener listener) {
         synchronized (m_sidToRankingToListenersMap) {
             String filter = (String) m_listenerToFilterMap.remove(listener);
-            FilterData data = getFilterData(null, filter);
-            if (data != null) {
-                synchronized (m_sidToRankingToListenersMap) {
-                    SortedMap /* <Integer, ServiceListener> */ rankingToListenersMap
= (SortedMap) m_sidToRankingToListenersMap.get(Long.valueOf(data.serviceId));
-                    if (rankingToListenersMap != null) {
-                        rankingToListenersMap.remove(Integer.valueOf(data.ranking));
-                    }
-                }
+            if (filter != null) {
+            	// the listener does exist
+	            FilterData data = getFilterData(null, filter);
+	            if (data != null) {
+	                synchronized (m_sidToRankingToListenersMap) {
+	                    SortedMap /* <Integer, ServiceListener> */ rankingToListenersMap
= (SortedMap) m_sidToRankingToListenersMap.get(Long.valueOf(data.serviceId));
+	                    if (rankingToListenersMap != null) {
+	                        rankingToListenersMap.remove(Integer.valueOf(data.ranking));
+	                    }
+	                }
+	            }
             }
         }
     }

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/BundleContextInterceptor.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/BundleContextInterceptor.java?rev=1351732&r1=1351731&r2=1351732&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/BundleContextInterceptor.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/BundleContextInterceptor.java
Tue Jun 19 14:51:52 2012
@@ -64,13 +64,13 @@ public class BundleContextInterceptor ex
     }
 
     public void removeServiceListener(ServiceListener listener) {
-        FilterIndex filterIndex = m_cache.hasFilterIndexFor(null, null);
-        if (filterIndex != null) {
-            filterIndex.removeServiceListener(listener);
-        }
-        else {
-            m_context.removeServiceListener(listener);
-        }
+    	// remove servicelistener. although it would be prettier to find the correct filterindex
first it's
+    	// probaby faster to do a brute force removal.
+    	Iterator filterIndexIterator = m_cache.getFilterIndices().iterator();
+    	while (filterIndexIterator.hasNext()) {
+    		((FilterIndex) filterIndexIterator.next()).removeServiceListener(listener);
+    	}
+    	m_context.removeServiceListener(listener);
     }
 
     public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException
{

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/MultiPropertyExactFilter.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/MultiPropertyExactFilter.java?rev=1351732&r1=1351731&r2=1351732&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/MultiPropertyExactFilter.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/MultiPropertyExactFilter.java
Tue Jun 19 14:51:52 2012
@@ -398,19 +398,22 @@ public class MultiPropertyExactFilter im
     public void removeServiceListener(ServiceListener listener) {
         synchronized (m_keyToListenersMap) {
             String filter = (String) m_listenerToFilterMap.remove(listener);
-            List keys = createKeysFromFilter(null, filter);
-            Iterator iterator = keys.iterator();
-            while (iterator.hasNext()) {
-                String key = (String) iterator.next();
-                
-                boolean result = filter != null;
-                if (result) {
-                    List /* <ServiceListener> */ listeners = (List) m_keyToListenersMap.get(key);
-                    if (listeners != null) {
-                        listeners.remove(listener);
-                    }
-                    // TODO actually, if listeners == null that would be strange....
-                }
+            if (filter != null) {
+            	// the listener does exist
+            	List keys = createKeysFromFilter(null, filter);
+            	Iterator iterator = keys.iterator();
+            	while (iterator.hasNext()) {
+            		String key = (String) iterator.next();
+            		
+            		boolean result = filter != null;
+            		if (result) {
+            			List /* <ServiceListener> */ listeners = (List) m_keyToListenersMap.get(key);
+            			if (listeners != null) {
+            				listeners.remove(listener);
+            			}
+            			// TODO actually, if listeners == null that would be strange....
+            		}
+            	}
             }
         }
     }

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/ServiceRegistryCache.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/ServiceRegistryCache.java?rev=1351732&r1=1351731&r2=1351732&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/ServiceRegistryCache.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/index/ServiceRegistryCache.java
Tue Jun 19 14:51:52 2012
@@ -169,4 +169,8 @@ public class ServiceRegistryCache implem
         sb.append("]");
         return sb.toString();
     }
+
+	public List getFilterIndices() {
+		return m_filterIndexList;
+	}
 }



Mime
View raw message