aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2011-03-23 11:58:52 (EDT)
committerGlyn Normington2011-03-23 11:58:52 (EDT)
commit2d5214e1ca50e27ea3453b78785aeae321fe1f69 (patch)
tree8fc3aa97ebbfb1f996d366a7bc70d078b079e2a0
parent8635a443142c68ddb42ef64bad94eccb2b03c566 (diff)
downloadorg.eclipse.virgo.kernel-2d5214e1ca50e27ea3453b78785aeae321fe1f69.zip
org.eclipse.virgo.kernel-2d5214e1ca50e27ea3453b78785aeae321fe1f69.tar.gz
org.eclipse.virgo.kernel-2d5214e1ca50e27ea3453b78785aeae321fe1f69.tar.bz2
Remove use of system bundle context.
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java5
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java10
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegion.java19
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraph.java12
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHookTests.java2
5 files changed, 28 insertions, 20 deletions
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 52257f4..82a896d 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
@@ -70,7 +70,8 @@ final class RegionManager {
}
private void registerDigraphMbean(RegionDigraph regionDigraph) {
- StandardManageableRegionDigraph standardManageableRegionDigraph = new StandardManageableRegionDigraph(regionDigraph, this.domain, this.bundleContext);
+ StandardManageableRegionDigraph standardManageableRegionDigraph = new StandardManageableRegionDigraph(regionDigraph, this.domain,
+ this.bundleContext);
standardManageableRegionDigraph.registerMBean();
}
@@ -89,7 +90,7 @@ final class RegionManager {
private void registerRegionHooks(RegionDigraph regionDigraph) {
registerResolverHookFactory(new RegionResolverHookFactory(regionDigraph));
- RegionBundleFindHook bundleFindHook = new RegionBundleFindHook(regionDigraph);
+ RegionBundleFindHook bundleFindHook = new RegionBundleFindHook(regionDigraph, bundleContext.getBundle().getBundleId());
registerBundleFindHook(bundleFindHook);
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java
index 016de4b..f3c12e2 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java
@@ -32,8 +32,11 @@ public final class RegionBundleFindHook implements FindHook {
private final RegionDigraph regionDigraph;
- public RegionBundleFindHook(RegionDigraph regionDigraph) {
+ private final long hookImplID;
+
+ public RegionBundleFindHook(RegionDigraph regionDigraph, long hookImplID) {
this.regionDigraph = regionDigraph;
+ this.hookImplID = hookImplID;
}
/**
@@ -41,7 +44,10 @@ public final class RegionBundleFindHook implements FindHook {
*/
@Override
public void find(BundleContext context, Collection<Bundle> bundles) {
- if (context.getBundle().getBundleId() == 0L) {
+ long bundleID = context.getBundle().getBundleId();
+
+ if (bundleID == 0 || bundleID == hookImplID) {
+ // The system bundle and the hook impl bundle can see all bundles
return;
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegion.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegion.java
index a5346a0..ad4236c 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegion.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegion.java
@@ -57,15 +57,15 @@ final class BundleIdBasedRegion implements Region {
private final RegionDigraph regionDigraph;
- private final BundleContext systemBundleContext;
+ private final BundleContext bundleContext;
private final ThreadLocal<Region> threadLocal;
- BundleIdBasedRegion(@NonNull String regionName, @NonNull RegionDigraph regionDigraph, @NonNull BundleContext systemBundleContext,
+ BundleIdBasedRegion(@NonNull String regionName, @NonNull RegionDigraph regionDigraph, @NonNull BundleContext bundleContext,
@NonNull ThreadLocal<Region> threadLocal) {
this.regionName = regionName;
this.regionDigraph = regionDigraph;
- this.systemBundleContext = systemBundleContext;
+ this.bundleContext = bundleContext;
this.threadLocal = threadLocal;
}
@@ -112,11 +112,11 @@ final class BundleIdBasedRegion implements Region {
*/
@Override
public Bundle installBundle(String location, InputStream input) throws BundleException {
- if (this.systemBundleContext == null)
+ if (this.bundleContext == null)
throw new BundleException("This region is not connected to an OSGi Framework.", BundleException.INVALID_OPERATION);
setRegionThreadLocal();
try {
- return this.systemBundleContext.installBundle(this.regionName + REGION_LOCATION_DELIMITER + location, input);
+ return this.bundleContext.installBundle(this.regionName + REGION_LOCATION_DELIMITER + location, input);
} finally {
removeRegionThreadLocal();
}
@@ -127,11 +127,11 @@ final class BundleIdBasedRegion implements Region {
*/
@Override
public Bundle installBundle(String location) throws BundleException {
- if (this.systemBundleContext == null)
+ if (this.bundleContext == null)
throw new BundleException("This region is not connected to an OSGi Framework.", BundleException.INVALID_OPERATION);
setRegionThreadLocal();
try {
- return this.systemBundleContext.installBundle(this.regionName + REGION_LOCATION_DELIMITER + location, openBundleStream(location));
+ return this.bundleContext.installBundle(this.regionName + REGION_LOCATION_DELIMITER + location, openBundleStream(location));
} finally {
removeRegionThreadLocal();
}
@@ -176,11 +176,12 @@ final class BundleIdBasedRegion implements Region {
*/
@Override
public Bundle getBundle(@NonNull String symbolicName, @NonNull Version version) {
- if (this.systemBundleContext == null)
+ if (bundleContext == null)
return null; // this region is not connected to an OSGi framework
+
// The following iteration is weakly consistent and will never throw ConcurrentModificationException.
for (long bundleId : this.bundleIds) {
- Bundle bundle = this.systemBundleContext.getBundle(bundleId);
+ Bundle bundle = bundleContext.getBundle(bundleId);
if (bundle != null && symbolicName.equals(bundle.getSymbolicName()) && version.equals(bundle.getVersion())) {
return bundle;
}
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 b06487d..7049eab 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
@@ -51,7 +51,7 @@ 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 BundleContext bundleContext;
private final ThreadLocal<Region> threadLocal;
@@ -63,7 +63,7 @@ public final class StandardRegionDigraph implements RegionDigraph {
public StandardRegionDigraph(BundleContext bundleContext, ThreadLocal<Region> threadLocal) {
this.subgraphTraverser = new SubgraphTraverser();
- this.systemBundleContext = bundleContext == null ? null : bundleContext.getBundle(0L).getBundleContext();
+ this.bundleContext = bundleContext;
this.threadLocal = threadLocal;
}
@@ -72,7 +72,7 @@ public final class StandardRegionDigraph implements RegionDigraph {
*/
@Override
public Region createRegion(String regionName) throws BundleException {
- Region region = new BundleIdBasedRegion(regionName, this, this.systemBundleContext, this.threadLocal);
+ Region region = new BundleIdBasedRegion(regionName, this, this.bundleContext, this.threadLocal);
synchronized (this.monitor) {
if (getRegion(regionName) != null) {
throw new BundleException("Region '" + regionName + "' already exists", BundleException.UNSUPPORTED_OPERATION);
@@ -293,13 +293,13 @@ public final class StandardRegionDigraph implements RegionDigraph {
private Set<RegionLifecycleListener> getListeners() {
Set<RegionLifecycleListener> listeners = new HashSet<RegionLifecycleListener>();
- if (this.systemBundleContext == null)
+ if (this.bundleContext == null)
return listeners;
try {
- Collection<ServiceReference<RegionLifecycleListener>> listenerServiceReferences = this.systemBundleContext.getServiceReferences(
+ Collection<ServiceReference<RegionLifecycleListener>> listenerServiceReferences = this.bundleContext.getServiceReferences(
RegionLifecycleListener.class, null);
for (ServiceReference<RegionLifecycleListener> listenerServiceReference : listenerServiceReferences) {
- RegionLifecycleListener regionLifecycleListener = this.systemBundleContext.getService(listenerServiceReference);
+ RegionLifecycleListener regionLifecycleListener = this.bundleContext.getService(listenerServiceReference);
if (regionLifecycleListener != null) {
listeners.add(regionLifecycleListener);
}
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 823fe4f..cdf923d 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
@@ -84,7 +84,7 @@ public class RegionBundleFindHookTests {
stubBundleContext.addInstalledBundle(stubSystemBundle);
this.threadLocal = new ThreadLocal<Region>();
this.digraph = new StandardRegionDigraph(stubBundleContext, this.threadLocal);
- this.bundleFindHook = new RegionBundleFindHook(this.digraph);
+ this.bundleFindHook = new RegionBundleFindHook(this.digraph, stubSystemBundle.getBundleId());
this.candidates = new HashSet<Bundle>();
// Create regions A, B, C, D containing bundles A, B, C, D, respectively.