Author: mahrwald
Date: Fri Feb 4 17:38:07 2011
New Revision: 1067236
URL: http://svn.apache.org/viewvc?rev=1067236&view=rev
Log:
ARIES-568: Fix leaking of BundleContext objects in
InternalRecursiveBundleTracker
Modified:
aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
Modified:
aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
URL:
http://svn.apache.org/viewvc/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java?rev=1067236&r1=1067235&r2=1067236&view=diff
==============================================================================
---
aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
(original)
+++
aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
Fri Feb 4 17:38:07 2011
@@ -19,9 +19,9 @@
package org.apache.aries.util.tracker;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -40,7 +40,7 @@ public class InternalRecursiveBundleTrac
{
private final int mask;
- private final Set<BundleContext> alreadyRecursedContexts = new
HashSet<BundleContext>();
+ private final ConcurrentMap<String,String> alreadyRecursedContexts = new
ConcurrentHashMap<String, String>();
private final BundleTrackerCustomizer customizer;
@@ -126,9 +126,9 @@ public class InternalRecursiveBundleTrac
if (event.getType() == BundleEvent.STOPPED) {
// if CompositeBundle is being stopped, let's remove the bundle
// tracker(s) associated with the composite bundle
- BundleContext compositeBundleContext = ((CompositeBundle)
b).getCompositeFramework()
- .getBundleContext();
- alreadyRecursedContexts.remove(compositeBundleContext);
+ String bundleId = b.getSymbolicName()+"/"+b.getVersion();
+ alreadyRecursedContexts.remove(bundleId);
+
if (btList != null) {
// unregister the bundlescope off the factory and close
// bundle trackers
@@ -147,8 +147,9 @@ public class InternalRecursiveBundleTrac
{
// let's process each of the bundle in the CompositeBundle
BundleContext compositeBundleContext =
cb.getCompositeFramework().getBundleContext();
- if (!alreadyRecursedContexts.contains(compositeBundleContext)) {
- alreadyRecursedContexts.add(compositeBundleContext);
+
+ String bundleId = cb.getSymbolicName()+"/"+cb.getVersion();
+ if (alreadyRecursedContexts.putIfAbsent(bundleId, bundleId) == null) {
// let's track each of the bundle in the CompositeBundle
BundleTracker bt = new
InternalRecursiveBundleTracker(compositeBundleContext, stateMask,