Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2011-01-26 04:51:08 -0500
committerGlyn Normington2011-01-26 04:51:08 -0500
commit730f6d095f4d33e7155f691cd195e86b44815735 (patch)
tree32ca68884c56b4f2b5bf32c2c65f843b8af8579a /org.eclipse.virgo.kernel.userregionfactory
parent8250663a67b3c2393c09bc223de3a1da82810bdb (diff)
downloadorg.eclipse.virgo.kernel-730f6d095f4d33e7155f691cd195e86b44815735.tar.gz
org.eclipse.virgo.kernel-730f6d095f4d33e7155f691cd195e86b44815735.tar.xz
org.eclipse.virgo.kernel-730f6d095f4d33e7155f691cd195e86b44815735.zip
bug 330776: use region digraph in place of region membership
Diffstat (limited to 'org.eclipse.virgo.kernel.userregionfactory')
-rw-r--r--org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java183
-rw-r--r--org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionPackageImportPolicy.java17
-rw-r--r--org.eclipse.virgo.kernel.userregionfactory/src/test/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionPackageImportPolicyTests.java27
-rw-r--r--org.eclipse.virgo.kernel.userregionfactory/template.mf1
4 files changed, 118 insertions, 110 deletions
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 4524b576..50c04f73 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
@@ -13,12 +13,7 @@
package org.eclipse.virgo.kernel.userregionfactory;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
import java.net.URI;
-import java.net.URL;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashMap;
@@ -32,9 +27,11 @@ 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.ImmutableRegion;
+import org.eclipse.virgo.kernel.osgi.region.BundleIdBasedRegion;
import org.eclipse.virgo.kernel.osgi.region.Region;
-import org.eclipse.virgo.kernel.osgi.region.RegionMembership;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
+import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
+import org.eclipse.virgo.kernel.osgi.region.StandardRegionFilter;
import org.eclipse.virgo.medic.eventlog.EventLogger;
import org.eclipse.virgo.osgi.launcher.parser.ArgumentParser;
import org.eclipse.virgo.osgi.launcher.parser.BundleEntry;
@@ -43,13 +40,15 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin;
/**
- *{@link Activator} initialises the user region factory bundle.
+ * {@link Activator} initialises the user region factory bundle.
* <p />
*
* <strong>Concurrent Semantics</strong><br />
@@ -58,13 +57,15 @@ import org.osgi.service.event.EventAdmin;
*
*/
public final class Activator implements BundleActivator {
-
+
+ private static final String CLASS_LIST_SEPARATOR = ",";
+
private static final long MAX_SECONDS_WAIT_FOR_SERVICE = 30;
private static final long MAX_MILLIS_WAIT_FOR_SERVICE = TimeUnit.SECONDS.toMillis(MAX_SECONDS_WAIT_FOR_SERVICE);
-
+
private static final String USER_REGION_CONFIGURATION_PID = "org.eclipse.virgo.kernel.userregion";
-
+
private static final String USER_REGION_BASE_BUNDLES_PROPERTY = "baseBundles";
private static final String USER_REGION_PACKAGE_IMPORTS_PROPERTY = "packageImports";
@@ -72,23 +73,17 @@ public final class Activator implements BundleActivator {
private static final String USER_REGION_SERVICE_IMPORTS_PROPERTY = "serviceImports";
private static final String USER_REGION_SERVICE_EXPORTS_PROPERTY = "serviceExports";
-
+
private static final String USER_REGION_BUNDLE_CONTEXT_SERVICE_PROPERTY = "org.eclipse.virgo.kernel.regionContext";
-
+
private static final String REGION_USER = "org.eclipse.virgo.region.user";
-
+
private static final String EVENT_REGION_STARTING = "org/eclipse/virgo/kernel/region/STARTING";
private static final String EVENT_PROPERTY_REGION_BUNDLECONTEXT = "region.bundleContext";
-
- private static final String USER_REGION_LOCATION_TAG = "userregion@";
-
- private static final String REFERENCE_SCHEME = "reference:";
-
- private static final String FILE_SCHEME = "file:";
private EventAdmin eventAdmin;
-
+
private String regionBundles;
private String regionImports;
@@ -98,9 +93,9 @@ public final class Activator implements BundleActivator {
private String regionServiceExports;
private BundleContext bundleContext;
-
+
private final ArgumentParser parser = new ArgumentParser();
-
+
private final ServiceRegistrationTracker tracker = new ServiceRegistrationTracker();
/**
@@ -109,16 +104,16 @@ public final class Activator implements BundleActivator {
@Override
public void start(BundleContext bundleContext) throws Exception {
this.bundleContext = bundleContext;
- RegionMembership regionMembership = getPotentiallyDelayedService(bundleContext, RegionMembership.class);
+ RegionDigraph regionDigraph = getPotentiallyDelayedService(bundleContext, RegionDigraph.class);
this.eventAdmin = getPotentiallyDelayedService(bundleContext, EventAdmin.class);
- ConfigurationAdmin configAdmin= getPotentiallyDelayedService(bundleContext, ConfigurationAdmin.class);
+ ConfigurationAdmin configAdmin = getPotentiallyDelayedService(bundleContext, ConfigurationAdmin.class);
EventLogger eventLogger = getPotentiallyDelayedService(bundleContext, EventLogger.class);
Shutdown shutdown = getPotentiallyDelayedService(bundleContext, Shutdown.class);
getRegionConfiguration(configAdmin, eventLogger, shutdown);
- createUserRegion(bundleContext, regionMembership);
+ createUserRegion(bundleContext, regionDigraph);
}
-
+
private void getRegionConfiguration(ConfigurationAdmin configAdmin, EventLogger eventLogger, Shutdown shutdown) {
try {
Configuration config = configAdmin.getConfiguration(USER_REGION_CONFIGURATION_PID, null);
@@ -141,9 +136,80 @@ public final class Activator implements BundleActivator {
}
}
-
- private void createUserRegion(BundleContext userRegionBundleContext, RegionMembership regionMembership) throws BundleException {
-
+ private void createUserRegion(BundleContext userRegionBundleContext, RegionDigraph regionDigraph) throws BundleException {
+
+ BundleContext systemBundleContext = getSystemBundleContext();
+
+ Region userRegion = new BundleIdBasedRegion(REGION_USER, regionDigraph, systemBundleContext);
+
+ Region kernelRegion = getKernelRegion(regionDigraph);
+
+ RegionFilter kernelFilter = createKernelFilter(systemBundleContext);
+ userRegion.connectRegion(kernelRegion, kernelFilter);
+
+ RegionFilter userRegionFilter = createUserRegionFilter();
+ kernelRegion.connectRegion(userRegion, userRegionFilter);
+
+ notifyUserRegionStarting(userRegionBundleContext);
+
+ initialiseUserRegionBundles(userRegion);
+
+ registerRegionService(userRegion);
+ publishUserRegionBundleContext(userRegionBundleContext);
+ }
+
+ private RegionFilter createUserRegionFilter() throws BundleException {
+ RegionFilter userRegionFilter = new StandardRegionFilter();
+ Filter serviceFilter;
+ try {
+ serviceFilter = this.bundleContext.createFilter(classesToFilter(this.regionServiceExports));
+ } catch (InvalidSyntaxException e) {
+ throw new BundleException("Invalid " + USER_REGION_SERVICE_EXPORTS_PROPERTY + "in user region configuration: '"
+ + this.regionServiceExports + "'", e);
+ }
+ userRegionFilter.setServiceFilter(serviceFilter);
+
+ return userRegionFilter;
+ }
+
+ private Region getKernelRegion(RegionDigraph regionDigraph) {
+ return regionDigraph.iterator().next();
+ }
+
+ private RegionFilter createKernelFilter(BundleContext systemBundleContext) throws BundleException {
+ RegionFilter kernelFilter = new StandardRegionFilter();
+ Bundle systemBundle = systemBundleContext.getBundle();
+ kernelFilter.allowBundle(systemBundle.getSymbolicName(), systemBundle.getVersion());
+ kernelFilter.setPackageImportPolicy(createUserRegionPackageImportPolicy(systemBundleContext));
+ Filter serviceFilter;
+ try {
+ serviceFilter = this.bundleContext.createFilter(classesToFilter(this.regionServiceImports));
+ } catch (InvalidSyntaxException e) {
+ throw new BundleException("Invalid " + USER_REGION_SERVICE_IMPORTS_PROPERTY + "in user region configuration: '"
+ + this.regionServiceImports + "'", e);
+ }
+ kernelFilter.setServiceFilter(serviceFilter);
+ return kernelFilter;
+ }
+
+ private String classesToFilter(String classList) {
+ if (classList == null) {
+ return "";
+ }
+ String[] classes = classList.split(CLASS_LIST_SEPARATOR);
+ if (classes.length == 0) {
+ return "";
+ }
+ StringBuffer filter = new StringBuffer();
+ filter.append("(|");
+ for (String className : classes) {
+ filter.append("(objectClass=" + className + ")");
+ }
+ filter.append(")");
+ return filter.toString();
+ }
+
+ private UserRegionPackageImportPolicy createUserRegionPackageImportPolicy(BundleContext systemBundleContext) {
String userRegionImportsProperty = this.regionImports != null ? this.regionImports
: this.bundleContext.getProperty(USER_REGION_PACKAGE_IMPORTS_PROPERTY);
String expandedUserRegionImportsProperty = null;
@@ -152,25 +218,29 @@ public final class Activator implements BundleActivator {
this.bundleContext);
}
+ //expandedUserRegionImportsProperty += getSystemBundleExports(systemBundleContext);
+
UserRegionPackageImportPolicy userRegionPackageImportPolicy = new UserRegionPackageImportPolicy(expandedUserRegionImportsProperty);
- ImmutableRegion userRegion = new ImmutableRegion(REGION_USER, userRegionBundleContext, userRegionPackageImportPolicy);
- userRegionPackageImportPolicy.setUserRegion(userRegion);
- regionMembership.setUserRegion(userRegion);
- notifyUserRegionStarting(userRegionBundleContext);
+ return userRegionPackageImportPolicy;
+ }
- initialiseUserRegionBundles();
+ private String getSystemBundleExports(BundleContext systemBundleContext) {
+ //systemBundleContext.getBundle().get
+ // TODO Auto-generated method stub
+ return ",org.osgi.framework,org.osgi.service.packageadmin,org.eclipse.osgi.baseadaptor,org.eclipse.osgi.baseadaptor.bundlefile";
+ }
- registerRegionService(userRegion);
- publishUserRegionBundleContext(userRegionBundleContext);
+ private BundleContext getSystemBundleContext() {
+ return this.bundleContext.getBundle(0L).getBundleContext();
}
-
+
private void notifyUserRegionStarting(BundleContext userRegionBundleContext) {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(EVENT_PROPERTY_REGION_BUNDLECONTEXT, userRegionBundleContext);
this.eventAdmin.sendEvent(new Event(EVENT_REGION_STARTING, properties));
}
- private void initialiseUserRegionBundles() throws BundleException {
+ private void initialiseUserRegionBundles(Region userRegion) throws BundleException {
String userRegionBundlesProperty = this.regionBundles != null ? this.regionBundles
: this.bundleContext.getProperty(USER_REGION_BASE_BUNDLES_PROPERTY);
@@ -180,7 +250,7 @@ public final class Activator implements BundleActivator {
for (BundleEntry entry : this.parser.parseBundleEntries(userRegionBundlesProperty)) {
URI uri = entry.getURI();
- Bundle bundle = this.bundleContext.installBundle(USER_REGION_LOCATION_TAG + uri.toString(), openBundleStream(uri));
+ Bundle bundle = userRegion.installBundle(uri.toString());
if (entry.isAutoStart()) {
bundlesToStart.add(bundle);
@@ -196,37 +266,6 @@ public final class Activator implements BundleActivator {
}
}
}
-
- private InputStream openBundleStream(URI uri) throws BundleException {
- String absoluteBundleUriString = getAbsoluteUriString(uri);
-
- try {
- // Use the reference: scheme to obtain an InputStream for either a file or a directory.
- return new URL(REFERENCE_SCHEME + absoluteBundleUriString).openStream();
-
- } catch (MalformedURLException e) {
- throw new BundleException(USER_REGION_BASE_BUNDLES_PROPERTY + " property resulted in an invalid bundle URI '" + absoluteBundleUriString
- + "'", e);
- } catch (IOException e) {
- throw new BundleException(USER_REGION_BASE_BUNDLES_PROPERTY + " property referred to an invalid bundle at URI '"
- + absoluteBundleUriString + "'", e);
- }
- }
-
- private String getAbsoluteUriString(URI uri) throws BundleException {
- String bundleUriString = uri.toString();
-
- if (!bundleUriString.startsWith(FILE_SCHEME)) {
- throw new BundleException(USER_REGION_BASE_BUNDLES_PROPERTY + " property contained an entry '" + bundleUriString
- + "' which did not start with '" + FILE_SCHEME + "'");
- }
-
- String filePath = bundleUriString.substring(FILE_SCHEME.length());
-
- return FILE_SCHEME + new File(filePath).getAbsolutePath();
- }
-
-
private void registerRegionService(Region region) {
Dictionary<String, String> props = new Hashtable<String, String>();
@@ -271,6 +310,6 @@ public final class Activator implements BundleActivator {
private static long sleepABitMore() throws InterruptedException {
long before = System.currentTimeMillis();
Thread.sleep(100);
- return (System.currentTimeMillis() - before);
+ return System.currentTimeMillis() - before;
}
}
diff --git a/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionPackageImportPolicy.java b/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionPackageImportPolicy.java
index 1f708c42..06a85b13 100644
--- a/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionPackageImportPolicy.java
+++ b/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionPackageImportPolicy.java
@@ -19,7 +19,6 @@ import java.util.Map;
import java.util.Set;
import org.eclipse.osgi.service.resolver.VersionRange;
-import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionPackageImportPolicy;
import org.eclipse.virgo.util.osgi.manifest.BundleManifest;
import org.eclipse.virgo.util.osgi.manifest.BundleManifestFactory;
@@ -47,10 +46,6 @@ class UserRegionPackageImportPolicy implements RegionPackageImportPolicy {
private final Map<String, ImportedPackage> importedPackages = new HashMap<String, ImportedPackage>();
- private Region userRegion;
-
- private final Object monitor = new Object();
-
/**
* Construct a {@link UserRegionPackageImportPolicy} for the specified import package list which must not contain
* wildcards.
@@ -72,18 +67,6 @@ class UserRegionPackageImportPolicy implements RegionPackageImportPolicy {
}
}
- void setUserRegion(Region userRegion) {
- synchronized (this.monitor) {
- this.userRegion = userRegion;
- }
- }
-
- public Region getUserRegion() {
- synchronized (this.monitor) {
- return this.userRegion;
- }
- }
-
/**
* {@inheritDoc}
*/
diff --git a/org.eclipse.virgo.kernel.userregionfactory/src/test/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionPackageImportPolicyTests.java b/org.eclipse.virgo.kernel.userregionfactory/src/test/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionPackageImportPolicyTests.java
index ac5ccb39..3975dcb4 100644
--- a/org.eclipse.virgo.kernel.userregionfactory/src/test/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionPackageImportPolicyTests.java
+++ b/org.eclipse.virgo.kernel.userregionfactory/src/test/java/org/eclipse/virgo/kernel/userregionfactory/UserRegionPackageImportPolicyTests.java
@@ -16,27 +16,14 @@ package org.eclipse.virgo.kernel.userregionfactory;
import java.util.HashMap;
import java.util.Map;
-import org.easymock.EasyMock;
-import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionPackageImportPolicy;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Version;
import org.osgi.framework.wiring.Capability;
public class UserRegionPackageImportPolicyTests {
- private Region mockUserRegion;
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- mockUserRegion = EasyMock.createMock(Region.class);
- }
-
@Test
public void testNullPackageString() {
new UserRegionPackageImportPolicy(null);
@@ -46,8 +33,8 @@ public class UserRegionPackageImportPolicyTests {
public void testEmptyPackageString() {
new UserRegionPackageImportPolicy("");
}
-
- @Test(expected=IllegalArgumentException.class)
+
+ @Test(expected = IllegalArgumentException.class)
public void testWildcard() {
new UserRegionPackageImportPolicy("*");
}
@@ -59,12 +46,11 @@ public class UserRegionPackageImportPolicyTests {
Map<String, Object> attributes = createAttributes("p");
attributes.put("pa", "pv");
Assert.assertTrue(userRegionPackageImportPolicy.isImported("p", attributes, null));
-
+
}
private UserRegionPackageImportPolicy createUserRegionPackageImportPolicy(String regionImports) {
UserRegionPackageImportPolicy userRegionPackageImportPolicy = new UserRegionPackageImportPolicy(regionImports);
- userRegionPackageImportPolicy.setUserRegion(this.mockUserRegion);
return userRegionPackageImportPolicy;
}
@@ -74,7 +60,7 @@ public class UserRegionPackageImportPolicyTests {
Map<String, Object> attributes = createAttributes("p");
attributes.put("pa", "pv");
Assert.assertTrue(userRegionPackageImportPolicy.isImported("p", attributes, null));
-
+
}
private Map<String, Object> createAttributes(String packageName) {
@@ -115,10 +101,9 @@ public class UserRegionPackageImportPolicyTests {
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("version", new Version("2.0.0"));
Assert.assertTrue(userRegionPackageImportPolicy.isImported("p", attributes, null));
-
+
}
-
@Test
public void testPackages() {
RegionPackageImportPolicy userRegionPackageImportPolicy = createUserRegionPackageImportPolicy("p,q");
@@ -126,5 +111,5 @@ public class UserRegionPackageImportPolicyTests {
Assert.assertTrue(userRegionPackageImportPolicy.isImported("q", null, null));
Assert.assertFalse(userRegionPackageImportPolicy.isImported("r", null, null));
}
-
+
}
diff --git a/org.eclipse.virgo.kernel.userregionfactory/template.mf b/org.eclipse.virgo.kernel.userregionfactory/template.mf
index 68a35591..95c321b5 100644
--- a/org.eclipse.virgo.kernel.userregionfactory/template.mf
+++ b/org.eclipse.virgo.kernel.userregionfactory/template.mf
@@ -11,6 +11,7 @@ Import-Template:
org.osgi.framework.*;version="0",
org.osgi.service.*;version="0",
org.eclipse.virgo.medic.*;version="${org.eclipse.virgo.medic:[=.=.=, =.+1)}"
+Import-Package: org.aspectj.lang
Bundle-Activator: org.eclipse.virgo.kernel.userregionfactory.Activator
Excluded-Imports: org.easymock,
org.eclipse.virgo.osgi.launcher.*,

Back to the top