Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBorislav Kapukaranov2011-02-04 10:51:21 -0500
committerBorislav Kapukaranov2011-02-04 10:51:21 -0500
commit5897c3871f6083c47f35e83e48f05eb92217da45 (patch)
treefa04f0622d4b10fe9a89a9230928194eb56fa374
parent7952b693f5694bacb0cfb382d123f6738b701612 (diff)
parentbe0ddcd9d3c731774d7ac665b211ac05514ef0b7 (diff)
downloadorg.eclipse.virgo.kernel-bug333474-DS-remove-startup-order.tar.gz
org.eclipse.virgo.kernel-bug333474-DS-remove-startup-order.tar.xz
org.eclipse.virgo.kernel-bug333474-DS-remove-startup-order.zip
Merge remote branch 'origin/bug330776-framework-hooks' into bug333474-DS-remove-startup-orderbug333474-DS-remove-startup-order
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraph.java18
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java10
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleEventHook.java32
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegion.java (renamed from org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/BundleIdBasedRegion.java)61
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraph.java35
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleEventHookTests.java10
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHookTests.java39
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionResolverHookTests.java15
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionServiceFindHookTests.java18
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegionTests.java47
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphTests.java25
-rw-r--r--org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFramework.java4
-rw-r--r--org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java9
-rw-r--r--org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java8
14 files changed, 181 insertions, 150 deletions
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraph.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraph.java
index c62708fc..fabb1208 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraph.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraph.java
@@ -56,19 +56,22 @@ public interface RegionDigraph extends Iterable<Region> {
}
/**
- * Adds the given {@link Region} to the digraph.
+ * Create a {@link Region} with the given name. If a region with the given name already exists, then BundleException with
+ * exception type UNSUPPORTED_OPERATION is thrown.
*
- * @param region the region to be added
+ * @param regionName the name of the region
+ * @return the {@link Region} created
+ * @throws BundleException if the region was not created
*/
- void addRegion(Region region);
+ Region createRegion(String regionName) throws BundleException;
/**
* Removes the given {@link Region} from the digraph along with any edges which have the given region as head or
* tail. If the given region is not present in the digraph, this is not an error and there is no effect.
*
- * @param coregion the {@link Region} to be removed
+ * @param region the {@link Region} to be removed
*/
- void removeRegion(Region coregion);
+ void removeRegion(Region region);
/**
* Gets the {@link Region} in the digraph with the given name.
@@ -102,11 +105,6 @@ public interface RegionDigraph extends Iterable<Region> {
* <p>
* The given head and tail regions are added to the digraph if they are not already present.
* <p>
- * If the filter allows the same bundle symbolic name and version as a bundle already present in the tail region or
- * as a filter connecting the tail region to a region other than the head region, then BundleException with
- * exception type DUPLICATE_BUNDLE_ERROR is thrown. This ensures that bundles visible in a region are uniquely
- * identified by the combination of bundle symbolic name and bundle version.
- * <p>
* If the given tail region is already connected to the given head region, then BundleException with exception type
* UNSUPPORTED_OPERATION is thrown.
* <p>
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java
index 74592ff1..d15f4c1a 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java
@@ -45,8 +45,11 @@ final class RegionManager {
private final BundleContext bundleContext;
+ private final ThreadLocal<Region> threadLocal;
+
public RegionManager(BundleContext bundleContext) {
this.bundleContext = bundleContext;
+ this.threadLocal = new ThreadLocal<Region>();
}
public void start() throws BundleException {
@@ -55,15 +58,14 @@ final class RegionManager {
}
private RegionDigraph createRegionDigraph() throws BundleException {
- RegionDigraph regionDigraph = new StandardRegionDigraph();
+ RegionDigraph regionDigraph = new StandardRegionDigraph(this.bundleContext, this.threadLocal);
createKernelRegion(regionDigraph);
registerRegionDigraph(regionDigraph, this.bundleContext);
return regionDigraph;
}
private Region createKernelRegion(RegionDigraph regionDigraph) throws BundleException {
- Region kernelRegion = new BundleIdBasedRegion(REGION_KERNEL, regionDigraph, getSystemBundleContext());
- regionDigraph.addRegion(kernelRegion);
+ Region kernelRegion = regionDigraph.createRegion(REGION_KERNEL);
for (Bundle bundle : this.bundleContext.getBundles()) {
kernelRegion.addBundle(bundle);
@@ -81,7 +83,7 @@ final class RegionManager {
registerBundleFindHook(bundleFindHook);
- registerBundleEventHook(new RegionBundleEventHook(regionDigraph, bundleFindHook));
+ registerBundleEventHook(new RegionBundleEventHook(regionDigraph, bundleFindHook, this.threadLocal));
RegionServiceFindHook serviceFindHook = new RegionServiceFindHook(regionDigraph);
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleEventHook.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleEventHook.java
index 8175ff64..299cd0c6 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleEventHook.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleEventHook.java
@@ -31,8 +31,8 @@ import org.osgi.framework.hooks.bundle.FindHook;
* {@link RegionBundleEventHook} manages the visibility of bundle events across regions according to the
* {@link RegionDigraph}.
* <p>
- * The current implementation delegates to {@link RegionBundleFindHook}. This is likely to perform adequately
- * because of the low frequency of bundle events and the typically small number of bundle listeners.
+ * The current implementation delegates to {@link RegionBundleFindHook}. This is likely to perform adequately because of
+ * the low frequency of bundle events and the typically small number of bundle listeners.
* <p />
*
* <strong>Concurrent Semantics</strong><br />
@@ -44,9 +44,12 @@ public final class RegionBundleEventHook implements EventHook {
private final FindHook bundleFindHook;
- public RegionBundleEventHook(RegionDigraph regionDigraph, FindHook bundleFindBook) {
+ private final ThreadLocal<Region> threadLocal;
+
+ public RegionBundleEventHook(RegionDigraph regionDigraph, FindHook bundleFindBook, ThreadLocal<Region> threadLocal) {
this.regionDigraph = regionDigraph;
this.bundleFindHook = bundleFindBook;
+ this.threadLocal = threadLocal;
}
/**
@@ -78,11 +81,18 @@ public final class RegionBundleEventHook implements EventHook {
private void bundleInstalled(Bundle eventBundle, Bundle originBundle) {
/*
- * The system bundle is used, by BundleIdBasedRegion, to install bundles into arbitrary regions,
- * so ignore it as an origin.
+ * BundleIdBasedRegion sets thread local to install bundles into arbitrary regions. If this is not set, the
+ * bundle inherits the region of the origin bundle.
*/
- if (originBundle.getBundleId() != 0L) {
- Region originRegion = regionDigraph.getRegion(originBundle);
+ Region installRegion = this.threadLocal.get();
+ if (installRegion != null) {
+ try {
+ installRegion.addBundle(eventBundle);
+ } catch (BundleException e) {
+ e.printStackTrace();
+ }
+ } else {
+ Region originRegion = this.regionDigraph.getRegion(originBundle);
if (originRegion != null) {
try {
originRegion.addBundle(eventBundle);
@@ -92,12 +102,12 @@ public final class RegionBundleEventHook implements EventHook {
}
}
}
-
+
private void bundleUninstalled(Bundle eventBundle) {
- Region region = regionDigraph.getRegion(eventBundle);
+ Region region = this.regionDigraph.getRegion(eventBundle);
if (region != null) {
region.removeBundle(eventBundle);
- }
+ }
}
-
+
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/BundleIdBasedRegion.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegion.java
index a1a80512..6ba84201 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/BundleIdBasedRegion.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegion.java
@@ -9,7 +9,7 @@
* VMware Inc. - initial contribution
*******************************************************************************/
-package org.eclipse.virgo.kernel.osgi.region;
+package org.eclipse.virgo.kernel.osgi.region.internal;
import java.io.File;
import java.io.IOException;
@@ -18,6 +18,9 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
+import org.eclipse.virgo.kernel.osgi.region.Region;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
+import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.eclipse.virgo.util.math.ConcurrentHashSet;
import org.osgi.framework.Bundle;
@@ -33,7 +36,7 @@ import org.osgi.framework.Version;
* <strong>Concurrent Semantics</strong><br />
* Thread safe.
*/
-public final class BundleIdBasedRegion implements Region {
+final class BundleIdBasedRegion implements Region {
private static final String REGION_LOCATION_DELIMITER = "@";
@@ -53,10 +56,14 @@ public final class BundleIdBasedRegion implements Region {
private final BundleContext systemBundleContext;
- public BundleIdBasedRegion(@NonNull String regionName, @NonNull RegionDigraph regionDigraph, @NonNull BundleContext systemBundleContext) {
+ private final ThreadLocal<Region> threadLocal;
+
+ BundleIdBasedRegion(@NonNull String regionName, @NonNull RegionDigraph regionDigraph, @NonNull BundleContext systemBundleContext,
+ @NonNull ThreadLocal<Region> threadLocal) {
this.regionName = regionName;
this.regionDigraph = regionDigraph;
this.systemBundleContext = systemBundleContext;
+ this.threadLocal = threadLocal;
}
/**
@@ -100,8 +107,8 @@ public final class BundleIdBasedRegion implements Region {
BundleException.DUPLICATE_BUNDLE_ERROR);
}
}
-
- /**
+
+ /**
* {@inheritDoc}
*/
@Override
@@ -116,13 +123,12 @@ public final class BundleIdBasedRegion implements Region {
*/
@Override
public Bundle installBundle(String location, InputStream input) throws BundleException {
- /*
- * TODO: use bundle install hook to close the window between the bundle being installed and it belonging to the region.
- * See bug 333189.
- */
- Bundle bundle = this.systemBundleContext.installBundle(this.regionName + REGION_LOCATION_DELIMITER + location, input);
- addBundle(bundle);
- return bundle;
+ setRegionThreadLocal();
+ try {
+ return this.systemBundleContext.installBundle(this.regionName + REGION_LOCATION_DELIMITER + location, input);
+ } finally {
+ removeRegionThreadLocal();
+ }
}
/**
@@ -130,13 +136,20 @@ public final class BundleIdBasedRegion implements Region {
*/
@Override
public Bundle installBundle(String location) throws BundleException {
- /*
- * TODO: use bundle install hook to close the window between the bundle being installed and it belonging to the region.
- * See bug 333189.
- */
- Bundle bundle = this.systemBundleContext.installBundle(this.regionName + REGION_LOCATION_DELIMITER + location, openBundleStream(location));
- addBundle(bundle);
- return bundle;
+ setRegionThreadLocal();
+ try {
+ return this.systemBundleContext.installBundle(this.regionName + REGION_LOCATION_DELIMITER + location, openBundleStream(location));
+ } finally {
+ removeRegionThreadLocal();
+ }
+ }
+
+ private void setRegionThreadLocal() {
+ this.threadLocal.set(this);
+ }
+
+ private void removeRegionThreadLocal() {
+ this.threadLocal.remove();
}
private InputStream openBundleStream(String location) throws BundleException {
@@ -220,7 +233,7 @@ public final class BundleIdBasedRegion implements Region {
return this.regionName.equals(other.regionName);
}
- /**
+ /**
* {@inheritDoc}
*/
@Override
@@ -228,16 +241,16 @@ public final class BundleIdBasedRegion implements Region {
return this.bundleIds.contains(bundleId);
}
- /**
+ /**
* {@inheritDoc}
*/
@Override
public void removeBundle(Bundle bundle) {
removeBundle(bundle.getBundleId());
-
+
}
- /**
+ /**
* {@inheritDoc}
*/
@Override
@@ -247,7 +260,7 @@ public final class BundleIdBasedRegion implements Region {
}
}
- /**
+ /**
* {@inheritDoc}
*/
@Override
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraph.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraph.java
index e0a8ab42..854df858 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraph.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraph.java
@@ -25,6 +25,7 @@ import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.eclipse.virgo.util.math.OrderedPair;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
/**
@@ -44,6 +45,30 @@ public final class StandardRegionDigraph implements RegionDigraph {
private final Map<OrderedPair<Region, Region>, RegionFilter> filter = new HashMap<OrderedPair<Region, Region>, RegionFilter>();
+ private final BundleContext systemBundleContext;
+
+ private final ThreadLocal<Region> threadLocal;
+
+ public StandardRegionDigraph(BundleContext bundleContext, ThreadLocal<Region> threadLocal) {
+ this.systemBundleContext = bundleContext.getBundle(0L).getBundleContext();
+ this.threadLocal = threadLocal;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Region createRegion(String regionName) throws BundleException {
+ Region region = new BundleIdBasedRegion(regionName, this, this.systemBundleContext, this.threadLocal);
+ synchronized (this.monitor) {
+ if (getRegion(regionName) != null) {
+ throw new BundleException("Region '" + regionName + "' already exists", BundleException.UNSUPPORTED_OPERATION);
+ }
+ this.regions.add(region);
+ return region;
+ }
+ }
+
/**
* {@inheritDoc}
*/
@@ -87,16 +112,6 @@ public final class StandardRegionDigraph implements RegionDigraph {
* {@inheritDoc}
*/
@Override
- public void addRegion(Region region) {
- synchronized (this.monitor) {
- this.regions.add(region);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
public Set<FilteredRegion> getEdges(Region tailRegion) {
Set<FilteredRegion> edges = new HashSet<FilteredRegion>();
synchronized (this.monitor) {
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleEventHookTests.java b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleEventHookTests.java
index 1674c850..7c570f81 100644
--- a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleEventHookTests.java
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleEventHookTests.java
@@ -20,6 +20,7 @@ import java.util.Collection;
import java.util.HashSet;
import org.easymock.EasyMock;
+import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
@@ -44,6 +45,8 @@ public class RegionBundleEventHookTests {
private RegionDigraph mockRegionDigraph;
+ private ThreadLocal<Region> threadLocal;
+
@Before
public void setUp() throws Exception {
this.mockRegionDigraph = EasyMock.createMock(RegionDigraph.class);
@@ -53,6 +56,7 @@ public class RegionBundleEventHookTests {
this.contexts = new HashSet<BundleContext>();
StubBundleContext stubListenerBundleContext = new StubBundleContext();
this.contexts.add(stubListenerBundleContext);
+ this.threadLocal = new ThreadLocal<Region>();
}
@After
@@ -67,11 +71,11 @@ public class RegionBundleEventHookTests {
public void find(BundleContext context, Collection<Bundle> bundles) {
}
};
- EventHook eventHook = new RegionBundleEventHook(this.mockRegionDigraph, this.mockFindHook);
+ EventHook eventHook = new RegionBundleEventHook(this.mockRegionDigraph, this.mockFindHook, this.threadLocal);
eventHook.event(this.bundleEvent, this.contexts);
assertEquals(1, this.contexts.size());
}
-
+
@Test
public void testEventNotAllowed() {
this.mockFindHook = new FindHook() {
@@ -81,7 +85,7 @@ public class RegionBundleEventHookTests {
bundles.clear();
}
};
- EventHook eventHook = new RegionBundleEventHook(this.mockRegionDigraph, this.mockFindHook);
+ EventHook eventHook = new RegionBundleEventHook(this.mockRegionDigraph, this.mockFindHook, this.threadLocal);
eventHook.event(this.bundleEvent, this.contexts);
assertTrue(this.contexts.isEmpty());
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHookTests.java b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHookTests.java
index ef9a3810..e87db112 100644
--- a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHookTests.java
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHookTests.java
@@ -20,7 +20,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
-import org.eclipse.virgo.kernel.osgi.region.BundleIdBasedRegion;
import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
import org.eclipse.virgo.kernel.osgi.region.StandardRegionFilter;
@@ -62,8 +61,6 @@ public class RegionBundleFindHookTests {
private StandardRegionDigraph digraph;
- private StubBundleContext stubBundleContext;
-
private FindHook bundleFindHook;
private Map<String, Region> regions;
@@ -72,13 +69,19 @@ public class RegionBundleFindHookTests {
private Collection<Bundle> candidates;
+ private ThreadLocal<Region> threadLocal;
+
@Before
public void setUp() throws Exception {
this.bundleId = 1L;
this.regions = new HashMap<String, Region>();
this.bundles = new HashMap<String, Bundle>();
- this.digraph = new StandardRegionDigraph();
- this.stubBundleContext = new StubBundleContext();
+
+ StubBundle stubSystemBundle = new StubBundle(0L, "osgi.framework", new Version("0"), "loc");
+ StubBundleContext stubBundleContext = new StubBundleContext();
+ stubBundleContext.addInstalledBundle(stubSystemBundle);
+ this.threadLocal = new ThreadLocal<Region>();
+ this.digraph = new StandardRegionDigraph(stubBundleContext, this.threadLocal);
this.bundleFindHook = new RegionBundleFindHook(this.digraph);
this.candidates = new HashSet<Bundle>();
@@ -87,7 +90,7 @@ public class RegionBundleFindHookTests {
createRegion(REGION_B, BUNDLE_B);
createRegion(REGION_C, BUNDLE_C);
createRegion(REGION_D, BUNDLE_D);
-
+
createBundle(BUNDLE_X);
}
@@ -152,16 +155,16 @@ public class RegionBundleFindHookTests {
@Test
public void testFindInCyclicGraph() throws BundleException {
region(REGION_D).addBundle(bundle(BUNDLE_X));
-
+
region(REGION_A).connectRegion(region(REGION_B), createFilter(BUNDLE_D, BUNDLE_X));
region(REGION_B).connectRegion(region(REGION_A), createFilter());
-
+
region(REGION_B).connectRegion(region(REGION_D), createFilter(BUNDLE_D));
region(REGION_D).connectRegion(region(REGION_B), createFilter());
-
+
region(REGION_B).connectRegion(region(REGION_C), createFilter(BUNDLE_X));
region(REGION_C).connectRegion(region(REGION_B), createFilter());
-
+
region(REGION_C).connectRegion(region(REGION_D), createFilter(BUNDLE_X));
region(REGION_D).connectRegion(region(REGION_C), createFilter());
@@ -181,24 +184,24 @@ public class RegionBundleFindHookTests {
assertEquals(2, this.candidates.size());
assertTrue(this.candidates.contains(bundle(BUNDLE_D)));
assertTrue(this.candidates.contains(bundle(BUNDLE_X)));
-
+
// Find from region B
this.candidates.add(bundle(BUNDLE_B));
this.candidates.add(bundle(BUNDLE_C));
this.candidates.add(bundle(BUNDLE_D));
this.candidates.add(bundle(BUNDLE_X));
-
+
this.bundleFindHook.find(bundleContext(BUNDLE_B), this.candidates);
assertEquals(3, this.candidates.size());
assertTrue(this.candidates.contains(bundle(BUNDLE_B)));
assertTrue(this.candidates.contains(bundle(BUNDLE_D)));
assertTrue(this.candidates.contains(bundle(BUNDLE_X)));
}
-
+
@Test
public void testFindFromSystemBundle() {
this.candidates.add(bundle(BUNDLE_A));
-
+
Bundle stubBundle = new StubBundle(0L, "sys", BUNDLE_VERSION, "");
this.bundleFindHook.find(stubBundle.getBundleContext(), this.candidates);
assertEquals(1, this.candidates.size());
@@ -208,21 +211,19 @@ public class RegionBundleFindHookTests {
@Test
public void testFindFromBundleInNoRegion() {
this.candidates.add(bundle(BUNDLE_A));
-
+
Bundle stranger = createBundle("stranger");
this.bundleFindHook.find(stranger.getBundleContext(), this.candidates);
assertEquals(0, this.candidates.size());
}
-
private Region createRegion(String regionName, String... bundleSymbolicNames) throws BundleException {
- Region region = new BundleIdBasedRegion(regionName, this.digraph, this.stubBundleContext);
+ Region region = this.digraph.createRegion(regionName);
for (String bundleSymbolicName : bundleSymbolicNames) {
Bundle stubBundle = createBundle(bundleSymbolicName);
region.addBundle(stubBundle);
}
this.regions.put(regionName, region);
- this.digraph.addRegion(region);
return region;
}
@@ -237,7 +238,7 @@ public class RegionBundleFindHookTests {
}
return filter;
}
-
+
private Bundle createBundle(String bundleSymbolicName) {
Bundle stubBundle = new StubBundle(this.bundleId++, bundleSymbolicName, BUNDLE_VERSION, "loc:" + bundleSymbolicName);
this.bundles.put(bundleSymbolicName, stubBundle);
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionResolverHookTests.java b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionResolverHookTests.java
index 32db48a4..237bec75 100644
--- a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionResolverHookTests.java
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionResolverHookTests.java
@@ -21,7 +21,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import org.eclipse.virgo.kernel.osgi.region.BundleIdBasedRegion;
import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
import org.eclipse.virgo.kernel.osgi.region.RegionPackageImportPolicy;
@@ -75,8 +74,6 @@ public class RegionResolverHookTests {
private StandardRegionDigraph digraph;
- private StubBundleContext stubBundleContext;
-
private ResolverHook resolverHook;
private Map<String, Region> regions;
@@ -85,13 +82,18 @@ public class RegionResolverHookTests {
private Collection<Capability> candidates;
+ private ThreadLocal<Region> threadLocal;
+
@Before
public void setUp() throws Exception {
this.bundleId = 1L;
this.regions = new HashMap<String, Region>();
this.bundles = new HashMap<String, Bundle>();
- this.digraph = new StandardRegionDigraph();
- this.stubBundleContext = new StubBundleContext();
+ this.threadLocal = new ThreadLocal<Region>();
+ StubBundle stubSystemBundle = new StubBundle(0L, "osgi.framework", new Version("0"), "loc");
+ StubBundleContext stubBundleContext = new StubBundleContext();
+ stubBundleContext.addInstalledBundle(stubSystemBundle);
+ this.digraph = new StandardRegionDigraph(stubBundleContext, this.threadLocal);
this.resolverHook = new RegionResolverHook(this.digraph);
this.candidates = new HashSet<Capability>();
@@ -267,13 +269,12 @@ public class RegionResolverHookTests {
}
private Region createRegion(String regionName, String... bundleSymbolicNames) throws BundleException {
- Region region = new BundleIdBasedRegion(regionName, this.digraph, this.stubBundleContext);
+ Region region = this.digraph.createRegion(regionName);
for (String bundleSymbolicName : bundleSymbolicNames) {
Bundle stubBundle = createBundle(bundleSymbolicName);
region.addBundle(stubBundle);
}
this.regions.put(regionName, region);
- this.digraph.addRegion(region);
return region;
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionServiceFindHookTests.java b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionServiceFindHookTests.java
index 26907f52..c6602f84 100644
--- a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionServiceFindHookTests.java
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionServiceFindHookTests.java
@@ -21,7 +21,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
-import org.eclipse.virgo.kernel.osgi.region.BundleIdBasedRegion;
import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
import org.eclipse.virgo.kernel.osgi.region.StandardRegionFilter;
@@ -35,8 +34,8 @@ import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.Filter;
import org.osgi.framework.BundleException;
+import org.osgi.framework.Filter;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
import org.osgi.framework.hooks.service.FindHook;
@@ -70,8 +69,6 @@ public class RegionServiceFindHookTests {
private StandardRegionDigraph digraph;
- private StubBundleContext stubBundleContext;
-
private FindHook bundleFindHook;
private Map<String, Region> regions;
@@ -82,14 +79,20 @@ public class RegionServiceFindHookTests {
private Collection<ServiceReference<?>> candidates;
+ private ThreadLocal<Region> threadLocal;
+
@Before
public void setUp() throws Exception {
this.bundleId = 1L;
this.regions = new HashMap<String, Region>();
this.bundles = new HashMap<String, Bundle>();
this.serviceReferences = new HashMap<String, ServiceReference<Object>>();
- this.digraph = new StandardRegionDigraph();
- this.stubBundleContext = new StubBundleContext();
+
+ StubBundle stubSystemBundle = new StubBundle(0L, "osgi.framework", new Version("0"), "loc");
+ StubBundleContext stubBundleContext = new StubBundleContext();
+ stubBundleContext.addInstalledBundle(stubSystemBundle);
+ this.threadLocal = new ThreadLocal<Region>();
+ this.digraph = new StandardRegionDigraph(stubBundleContext, this.threadLocal);
this.bundleFindHook = new RegionServiceFindHook(this.digraph);
this.candidates = new HashSet<ServiceReference<?>>();
@@ -225,13 +228,12 @@ public class RegionServiceFindHookTests {
}
private Region createRegion(String regionName, String... bundleSymbolicNames) throws BundleException {
- Region region = new BundleIdBasedRegion(regionName, this.digraph, this.stubBundleContext);
+ Region region = this.digraph.createRegion(regionName);
for (String bundleSymbolicName : bundleSymbolicNames) {
Bundle stubBundle = createBundle(bundleSymbolicName);
region.addBundle(stubBundle);
}
this.regions.put(regionName, region);
- this.digraph.addRegion(region);
return region;
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegionTests.java b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegionTests.java
index 893744c2..dc31c736 100644
--- a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegionTests.java
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegionTests.java
@@ -18,7 +18,6 @@ import java.util.Iterator;
import java.util.Set;
import org.easymock.EasyMock;
-import org.eclipse.virgo.kernel.osgi.region.BundleIdBasedRegion;
import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
@@ -43,7 +42,7 @@ public class BundleIdBasedRegionTests {
private static final Version BUNDLE_VERSION = new Version("1");
private static final long BUNDLE_ID = 1L;
-
+
private static final long BUNDLE_ID_2 = 2L;
private static final String REGION_NAME = "reg";
@@ -64,8 +63,11 @@ public class BundleIdBasedRegionTests {
private RegionFilter mockRegionFilter;
+ private ThreadLocal<Region> threadLocal;
+
@Before
public void setUp() throws Exception {
+ this.threadLocal = new ThreadLocal<Region>();
this.mockBundle = EasyMock.createMock(Bundle.class);
EasyMock.expect(this.mockBundle.getSymbolicName()).andReturn(BUNDLE_SYMBOLIC_NAME).anyTimes();
EasyMock.expect(this.mockBundle.getVersion()).andReturn(BUNDLE_VERSION).anyTimes();
@@ -101,21 +103,19 @@ public class BundleIdBasedRegionTests {
}
private void replayMocks() {
- EasyMock.replay(this.mockBundleContext, this.mockBundle, this.mockRegion, this.mockRegion2, this.mockRegionFilter,
- this.mockGraph);
+ EasyMock.replay(this.mockBundleContext, this.mockBundle, this.mockRegion, this.mockRegion2, this.mockRegionFilter, this.mockGraph);
}
@After
public void tearDown() throws Exception {
- EasyMock.verify(this.mockBundleContext, this.mockBundle, this.mockRegion, this.mockRegion2, this.mockRegionFilter,
- this.mockGraph);
+ EasyMock.verify(this.mockBundleContext, this.mockBundle, this.mockRegion, this.mockRegion2, this.mockRegionFilter, this.mockGraph);
}
@Test
public void testGetName() {
defaultSetUp();
- Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
assertEquals(REGION_NAME, r.getName());
}
@@ -148,7 +148,7 @@ public class BundleIdBasedRegionTests {
allowedBundles.add(new OrderedPair<String, Version>(BUNDLE_SYMBOLIC_NAME_2, BUNDLE_VERSION));
replayMocks();
- Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
r.addBundle(this.mockBundle);
}
@@ -156,7 +156,7 @@ public class BundleIdBasedRegionTests {
public void testAddExistingBundle() throws BundleException {
defaultSetUp();
- Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
r.addBundle(this.mockBundle);
r.addBundle(this.mockBundle);
}
@@ -164,19 +164,18 @@ public class BundleIdBasedRegionTests {
@Test(expected = BundleException.class)
public void testAddConflictingBundle() throws BundleException {
defaultSetUp();
-
+
Bundle mockBundle2 = EasyMock.createMock(Bundle.class);
EasyMock.expect(mockBundle2.getSymbolicName()).andReturn(BUNDLE_SYMBOLIC_NAME).anyTimes();
EasyMock.expect(mockBundle2.getVersion()).andReturn(BUNDLE_VERSION).anyTimes();
EasyMock.expect(mockBundle2.getBundleId()).andReturn(BUNDLE_ID_2).anyTimes();
EasyMock.replay(mockBundle2);
- Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
r.addBundle(this.mockBundle);
r.addBundle(mockBundle2);
}
-
@Test(expected = BundleException.class)
public void testAddBundlePresentInAnotherRegion() throws BundleException {
this.regionIterator = new Iterator<Region>() {
@@ -209,7 +208,7 @@ public class BundleIdBasedRegionTests {
replayMocks();
- Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
r.addBundle(this.mockBundle);
}
@@ -231,7 +230,7 @@ public class BundleIdBasedRegionTests {
public void testContains() throws BundleException {
defaultSetUp();
- Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
r.addBundle(this.mockBundle);
assertTrue(r.contains(this.mockBundle));
}
@@ -240,7 +239,7 @@ public class BundleIdBasedRegionTests {
public void testDoesNotContain() throws BundleException {
defaultSetUp();
- Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
assertFalse(r.contains(this.mockBundle));
}
@@ -248,7 +247,7 @@ public class BundleIdBasedRegionTests {
public void testGetBundle() throws BundleException {
defaultSetUp();
- Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
r.addBundle(this.mockBundle);
assertEquals(this.mockBundle, r.getBundle(BUNDLE_SYMBOLIC_NAME, BUNDLE_VERSION));
}
@@ -257,7 +256,7 @@ public class BundleIdBasedRegionTests {
public void testGetBundleNotFound() throws BundleException {
defaultSetUp();
- Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
r.addBundle(this.mockBundle);
assertNull(r.getBundle(BUNDLE_SYMBOLIC_NAME_2, BUNDLE_VERSION));
}
@@ -266,7 +265,7 @@ public class BundleIdBasedRegionTests {
public void testConnectRegion() throws BundleException {
defaultSetUp();
- Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
r.connectRegion(this.mockRegion, this.mockRegionFilter);
}
@@ -274,8 +273,8 @@ public class BundleIdBasedRegionTests {
public void testEquals() {
defaultSetUp();
- Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
- Region s = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
+ Region s = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
assertEquals(r, r);
assertEquals(r, s);
assertEquals(r.hashCode(), s.hashCode());
@@ -285,16 +284,16 @@ public class BundleIdBasedRegionTests {
public void testNotEqual() {
defaultSetUp();
- Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
- Region s = new BundleIdBasedRegion(OTHER_REGION_NAME, this.mockGraph, this.mockBundleContext);
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
+ Region s = new BundleIdBasedRegion(OTHER_REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
assertFalse(r.equals(s));
assertFalse(r.equals(null));
}
-
+
@Test
public void testAddRemoveBundleId() {
defaultSetUp();
- Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext, this.threadLocal);
r.addBundle(TEST_BUNDLE_ID);
assertTrue(r.contains(TEST_BUNDLE_ID));
r.removeBundle(TEST_BUNDLE_ID);
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphTests.java b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphTests.java
index 0eb4bb56..fbe74aa2 100644
--- a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphTests.java
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphTests.java
@@ -16,7 +16,6 @@ package org.eclipse.virgo.kernel.osgi.region.internal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Set;
@@ -24,8 +23,10 @@ import java.util.Set;
import org.easymock.EasyMock;
import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
-import org.eclipse.virgo.kernel.osgi.region.RegionDigraph.FilteredRegion;
import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph.FilteredRegion;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
import org.eclipse.virgo.util.math.OrderedPair;
import org.junit.After;
import org.junit.Before;
@@ -52,7 +53,10 @@ public class StandardRegionDigraphTests {
@Before
public void setUp() throws Exception {
- this.digraph = new StandardRegionDigraph();
+ StubBundle stubSystemBundle = new StubBundle(0L, "osgi.framework", new Version("0"), "loc");
+ StubBundleContext stubBundleContext = new StubBundleContext();
+ stubBundleContext.addInstalledBundle(stubSystemBundle);
+ this.digraph = new StandardRegionDigraph(stubBundleContext, new ThreadLocal<Region>());
this.mockRegion1 = EasyMock.createMock(Region.class);
EasyMock.expect(this.mockRegion1.getName()).andReturn("mockRegion1").anyTimes();
@@ -135,21 +139,6 @@ public class StandardRegionDigraphTests {
}
@Test
- public void testAddRegion() {
- setDefaultMockFilters();
- replayMocks();
-
- this.digraph.addRegion(this.mockRegion1);
- boolean found = false;
- for (Region region : this.digraph) {
- if (this.mockRegion1.equals(region)) {
- found = true;
- }
- }
- assertTrue(found);
- }
-
- @Test
public void testGetEdges() throws BundleException {
setDefaultMockFilters();
replayMocks();
diff --git a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFramework.java b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFramework.java
index 33014a56..5385eb46 100644
--- a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFramework.java
+++ b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFramework.java
@@ -39,7 +39,6 @@ import org.eclipse.virgo.kernel.osgi.framework.UnableToSatisfyDependenciesExcept
import org.eclipse.virgo.kernel.osgi.quasi.QuasiBundle;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiFramework;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiResolutionFailure;
-import org.eclipse.virgo.kernel.osgi.region.BundleIdBasedRegion;
import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
@@ -155,9 +154,8 @@ final class StandardQuasiFramework implements QuasiFramework {
private void createCoregionIfNecessary() {
synchronized (this.monitor) {
if (this.coregion == null) {
- this.coregion = new BundleIdBasedRegion(this.userRegion.getName() + COREGION_SUFFIX, this.regionDigraph,
- this.bundleContext.getBundle(0L).getBundleContext());
try {
+ this.coregion = this.regionDigraph.createRegion(this.userRegion.getName() + COREGION_SUFFIX);
this.userRegion.connectRegion(this.coregion, RegionFilter.TOP);
this.coregion.connectRegion(this.userRegion, RegionFilter.TOP);
} catch (BundleException e) {
diff --git a/org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java b/org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java
index 866c6635..4106ed06 100644
--- a/org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java
+++ b/org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java
@@ -27,7 +27,6 @@ import org.eclipse.virgo.kernel.artifact.bundle.BundleBridge;
import org.eclipse.virgo.kernel.artifact.library.LibraryBridge;
import org.eclipse.virgo.kernel.osgi.framework.ImportExpander;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiFramework;
-import org.eclipse.virgo.kernel.osgi.region.BundleIdBasedRegion;
import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.osgi.region.internal.StandardRegionDigraph;
@@ -79,6 +78,8 @@ public abstract class AbstractOsgiFrameworkLaunchingTests {
protected QuasiFramework quasiFramework;
+ private ThreadLocal<Region> threadLocal;
+
@Before
public void setUp() throws Exception {
@@ -113,10 +114,10 @@ public abstract class AbstractOsgiFrameworkLaunchingTests {
};
- RegionDigraph regionDigraph = new StandardRegionDigraph();
+ this.threadLocal = new ThreadLocal<Region>();
+ RegionDigraph regionDigraph = new StandardRegionDigraph(this.bundleContext, this.threadLocal);
- Region userRegion = new BundleIdBasedRegion("org.eclipse.virgo.region.user", regionDigraph, bundleContext.getBundle(0L).getBundleContext());
- regionDigraph.addRegion(userRegion);
+ Region userRegion = regionDigraph.createRegion("org.eclipse.virgo.region.user");
userRegion.addBundle(this.bundleContext.getBundle());
final EventLogger mockEventLogger = new MockEventLogger();
diff --git a/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java b/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java
index d3b35fad..999acc52 100644
--- a/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java
+++ b/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java
@@ -27,7 +27,6 @@ import org.eclipse.virgo.kernel.core.Shutdown;
import org.eclipse.virgo.kernel.osgi.framework.OsgiFrameworkLogEvents;
import org.eclipse.virgo.kernel.osgi.framework.OsgiFrameworkUtils;
import org.eclipse.virgo.kernel.osgi.framework.OsgiServiceHolder;
-import org.eclipse.virgo.kernel.osgi.region.BundleIdBasedRegion;
import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
@@ -140,12 +139,11 @@ public final class Activator implements BundleActivator {
BundleContext systemBundleContext = getSystemBundleContext();
Bundle userRegionFactoryBundle = userRegionBundleContext.getBundle();
-
+
Region kernelRegion = getKernelRegion(regionDigraph);
kernelRegion.removeBundle(userRegionFactoryBundle);
- Region userRegion = new BundleIdBasedRegion(REGION_USER, regionDigraph, systemBundleContext);
- regionDigraph.addRegion(userRegion);
+ Region userRegion = regionDigraph.createRegion(REGION_USER);
userRegion.addBundle(userRegionFactoryBundle);
RegionFilter kernelFilter = createKernelFilter(systemBundleContext);
@@ -221,7 +219,7 @@ public final class Activator implements BundleActivator {
expandedUserRegionImportsProperty = PackageImportWildcardExpander.expandPackageImportsWildcards(userRegionImportsProperty,
systemBundleContext);
}
-
+
UserRegionPackageImportPolicy userRegionPackageImportPolicy = new UserRegionPackageImportPolicy(expandedUserRegionImportsProperty);
return userRegionPackageImportPolicy;
}

Back to the top