You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jb...@apache.org on 2010/12/13 19:26:35 UTC
svn commit: r1045274 [6/7] - in
/incubator/aries/sandbox/jbohn/interceptor-proto: ./ application/
application/application-api/src/main/java/org/apache/aries/application/
application/application-api/src/main/java/org/apache/aries/application/management/...
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-api/src/main/java/org/apache/aries/subsystem/spi/ResourceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-api/src/main/java/org/apache/aries/subsystem/spi/ResourceProcessor.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-api/src/main/java/org/apache/aries/subsystem/spi/ResourceProcessor.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-api/src/main/java/org/apache/aries/subsystem/spi/ResourceProcessor.java Mon Dec 13 18:26:19 2010
@@ -13,9 +13,8 @@
*/
package org.apache.aries.subsystem.spi;
-import org.apache.aries.subsystem.Subsystem;
+import org.apache.aries.subsystem.SubsystemAdmin;
import org.apache.aries.subsystem.SubsystemException;
-import org.osgi.framework.BundleContext;
/**
* A ResourceProcessor is an object that can manage a given resource type.
@@ -27,7 +26,7 @@ import org.osgi.framework.BundleContext;
*/
public interface ResourceProcessor {
- Session createSession(BundleContext context);
+ Session createSession(SubsystemAdmin admin);
public static interface Session {
Propchange: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/
('svn:ignore' removed)
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/pom.xml Mon Dec 13 18:26:19 2010
@@ -38,6 +38,7 @@
</aries.osgi.activator>
<aries.osgi.private.pkg>
org.apache.aries.subsystem.core.internal,
+ org.apache.aries.subsystem.core.obr,
org.apache.felix.utils.manifest
</aries.osgi.private.pkg>
</properties>
@@ -48,6 +49,10 @@
<artifactId>org.apache.aries.subsystem.api</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.aries.subsystem</groupId>
+ <artifactId>org.apache.aries.subsystem.scope.api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.aries.application</groupId>
<artifactId>org.apache.aries.application.api</artifactId>
</dependency>
@@ -63,6 +68,7 @@
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>osgi</artifactId>
+ <version>3.7.0.v20100910</version>
<scope>provided</scope>
</dependency>
<dependency>
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java Mon Dec 13 18:26:19 2010
@@ -14,21 +14,31 @@
package org.apache.aries.subsystem.core.internal;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.aries.subsystem.Subsystem;
import org.apache.aries.subsystem.SubsystemAdmin;
import org.apache.aries.subsystem.SubsystemConstants;
+import org.apache.aries.subsystem.SubsystemException;
+import org.apache.aries.subsystem.scope.ScopeAdmin;
import org.apache.aries.subsystem.spi.ResourceProcessor;
import org.apache.aries.subsystem.spi.ResourceResolver;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,18 +50,19 @@ import org.slf4j.LoggerFactory;
public class Activator implements BundleActivator {
private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
- private BundleContext context;
+ private static BundleContext context;
private List<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>();
private static SubsystemEventDispatcher eventDispatcher;
-
+ private static SubsystemAdminFactory adminFactory;
+
public void start(BundleContext context) throws Exception {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("subsystem activator starting");
}
- this.context = context;
- eventDispatcher = new SubsystemEventDispatcher(context);
-
- register(SubsystemAdmin.class, new SubsystemAdminFactory(), null);
+ Activator.context = context;
+ Activator.eventDispatcher = new SubsystemEventDispatcher(context);
+ adminFactory = new SubsystemAdminFactory();
+ register(SubsystemAdmin.class, adminFactory, null);
register(ResourceResolver.class,
new NoOpResolver(),
DictionaryBuilder.build(Constants.SERVICE_RANKING, Integer.MIN_VALUE));
@@ -86,27 +97,121 @@ public class Activator implements Bundle
}
}
eventDispatcher.destroy();
+ if (adminFactory!= null) {
+ adminFactory.destroy();
+ }
+
+ }
+
+ public static BundleContext getBundleContext() {
+ return context;
+ }
+
+ public static SubsystemEventDispatcher getEventDispatcher() {
+ return eventDispatcher;
}
public static class SubsystemAdminFactory implements ServiceFactory {
+ //private final List<ScopeAdmin> scopeAdmins = new ArrayList<ScopeAdmin>();
+ private final List<SubsystemAdmin> admins = new ArrayList<SubsystemAdmin>();
+ private final Map<SubsystemAdmin, Long> references = new HashMap<SubsystemAdmin, Long>();
+ private ScopeAdmin scopeAdmin; // scope admin for the root scope.
+ private static ServiceTracker serviceTracker;
+ private SubsystemAdmin defaultAdmin;
+ private ServiceRegistration rootAdminReg;
+
+ public SubsystemAdminFactory() throws InvalidSyntaxException {
+ context = Activator.getBundleContext();
+
+ ServiceReference[] reference = Activator.getBundleContext().getServiceReferences(ScopeAdmin.class.getName(),
+ "(&(ScopeName=root))");
+ if (reference != null && reference.length == 1) {
+ ScopeAdmin scopeAdmin = (ScopeAdmin)Activator.getBundleContext().getService(reference[0]);
+ Subsystem subsystem = new SubsystemImpl(scopeAdmin.getScope(), new HashMap<String, String>());
+ defaultAdmin = new SubsystemAdminImpl(scopeAdmin, subsystem, null);
+ rootAdminReg = context.registerService(SubsystemAdmin.class.getName(),
+ defaultAdmin,
+ DictionaryBuilder.build("Subsystem", subsystem.getSubsystemId(), "SubsystemParentId", 0));
+ admins.add(defaultAdmin);
+ } else {
+ throw new RuntimeException("Unable to locate service reference for the root scope admin");
+ }
+
+ Filter filter = FrameworkUtil.createFilter("(&("
+ + Constants.OBJECTCLASS + "=" + SubsystemAdmin.class.getName() + "))");
+ serviceTracker = new ServiceTracker(context, filter,
+ new ServiceTrackerCustomizer() {
+
+ public Object addingService(ServiceReference reference) {
+ // adding new service, update admins map
+ SubsystemAdmin sa = (SubsystemAdmin) context
+ .getService(reference);
+ admins.add(sa);
+
+ return sa;
+ }
+
+ public void modifiedService(ServiceReference reference,
+ Object service) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removedService(ServiceReference reference,
+ Object service) {
+ SubsystemAdmin sa = (SubsystemAdmin) service;
+ admins.remove(sa);
+ }
- private final Map<BundleContext, SubsystemAdminImpl> admins = new HashMap<BundleContext, SubsystemAdminImpl>();
- private final Map<SubsystemAdminImpl, Long> references = new HashMap<SubsystemAdminImpl, Long>();
-
+ });
+ }
+
+ public void destroy() {
+ serviceTracker.close();
+ }
+
+ private SubsystemAdmin getSubsystemAdmin(Bundle bundle) {
+ // first check if it is in root framework
+ Bundle[] bundles = Activator.getBundleContext().getBundles();
+ for (Bundle b : bundles) {
+ if (b == bundle) {
+ return defaultAdmin;
+ }
+ }
+ // check if they are bundles in the
+ for (SubsystemAdmin admin : admins) {
+ Collection<Subsystem> subsystems = admin.getSubsystems();
+ for (Subsystem subsystem : subsystems) {
+ Collection<Bundle> subsystemBundles = subsystem.getBundles();
+ for (Bundle b : subsystemBundles) {
+ if (b == bundle) {
+ return admin;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
public synchronized Object getService(Bundle bundle, ServiceRegistration registration) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Get SubsystemAdmin service from bundle symbolic name {} version {}", bundle.getSymbolicName(), bundle.getVersion());
}
- BundleContext systemBundleContext = bundle.getBundleContext().getBundle(0).getBundleContext();
- SubsystemAdminImpl admin = admins.get(systemBundleContext);
+
long ref = 0;
+
+ // figure out the subsystemAdmin for the bundle
+ SubsystemAdmin admin = getSubsystemAdmin(bundle);
+
if (admin == null) {
- admin = new SubsystemAdminImpl(systemBundleContext, eventDispatcher);
- admins.put(systemBundleContext, admin);
- } else {
- ref = references.get(admin);
+ throw new SubsystemException("Unable to locate the Subsystem admin for the bundle " + bundle.toString());
+ }
+
+ if (references.get(admin) == null) {
+ ref = 0;
}
+
references.put(admin, ref + 1);
return admin;
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceProcessor.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceProcessor.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceProcessor.java Mon Dec 13 18:26:19 2010
@@ -13,6 +13,7 @@
*/
package org.apache.aries.subsystem.core.internal;
+import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -20,30 +21,36 @@ import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
+import org.apache.aries.subsystem.SubsystemAdmin;
import org.apache.aries.subsystem.SubsystemConstants;
import org.apache.aries.subsystem.SubsystemException;
+import org.apache.aries.subsystem.scope.InstallInfo;
+import org.apache.aries.subsystem.scope.Scope;
+import org.apache.aries.subsystem.scope.ScopeAdmin;
+import org.apache.aries.subsystem.scope.ScopeUpdate;
import org.apache.aries.subsystem.spi.Resource;
import org.apache.aries.subsystem.spi.ResourceProcessor;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
-import org.osgi.service.composite.CompositeBundle;
public class BundleResourceProcessor implements ResourceProcessor {
- public Session createSession(BundleContext context) {
- return new BundleSession(context);
+ public Session createSession(SubsystemAdmin subsystemAdmin) {
+ return new BundleSession(subsystemAdmin);
}
public static class BundleSession implements Session {
- private final BundleContext context;
+ private final ScopeAdmin scopeAdmin;
private final List<Bundle> installed = new ArrayList<Bundle>();
private final Map<Resource, Bundle> updated = new HashMap<Resource, Bundle>();
private final Map<Resource, Bundle> removed = new HashMap<Resource, Bundle>();
+
- public BundleSession(BundleContext context) {
- this.context = context;
+ public BundleSession(SubsystemAdmin subsystemAdmin) {
+ SubsystemAdminImpl subsystemAdminImpl = (SubsystemAdminImpl)subsystemAdmin;
+ this.scopeAdmin = subsystemAdminImpl.getScopeAdmin();
}
public void process(Resource resource) throws SubsystemException {
@@ -52,9 +59,11 @@ public class BundleResourceProcessor imp
Bundle bundle = findBundle(resource);
if (bundle == null) {
- // fresh install
- bundle = context.installBundle(resource.getLocation(), resource.open());
- installed.add(bundle);
+ // fresh install
+ InstallInfo installInfo = new InstallInfo(new URL(resource.getLocation()), resource.getLocation());
+ ScopeUpdate scopeUpdate = scopeAdmin.newScopeUpdate();
+ scopeUpdate.getBundlesToInstall().add(installInfo);
+ scopeUpdate.commit();
} else {
// update only if RESOURCE_UPDATE_ATTRIBUTE is set to true
String updateAttribute = resource.getAttributes().get(SubsystemConstants.RESOURCE_UPDATE_ATTRIBUTE);
@@ -63,6 +72,11 @@ public class BundleResourceProcessor imp
updated.put(resource, bundle);
}
}
+
+ if (bundle == null) {
+ bundle = findBundle(resource);
+ installed.add(bundle);
+ }
String startAttribute = resource.getAttributes().get(SubsystemConstants.RESOURCE_START_ATTRIBUTE);
@@ -71,8 +85,6 @@ public class BundleResourceProcessor imp
startAttribute = "true";
}
if ("true".equals(startAttribute)) {
- // This will only mark the bundle as persistently started as the composite is supposed
- // to be stopped
bundle.start();
}
} catch (SubsystemException e) {
@@ -126,7 +138,10 @@ public class BundleResourceProcessor imp
Bundle bundle = entry.getValue();
Resource res = entry.getKey();
try {
- context.installBundle(res.getLocation(), res.open());
+ InstallInfo installInfo = new InstallInfo(res.open(), res.getLocation());
+ ScopeUpdate scopeUpdate = scopeAdmin.newScopeUpdate();
+ scopeUpdate.getBundlesToInstall().add(installInfo);
+ scopeUpdate.commit();
} catch (Exception e) {
// Ignore
}
@@ -137,14 +152,10 @@ public class BundleResourceProcessor imp
}
protected Bundle findBundle(Resource resource) {
- for (Bundle b : context.getBundles()) {
- if (resource.getLocation().equals(b.getLocation())) {
- if (b instanceof CompositeBundle) {
- throw new SubsystemException("A bundle with the same location already exists!");
- } else {
- return b;
-
- }
+ Scope scope = scopeAdmin.getScope();
+ for (Bundle b : scope.getBundles()) {
+ if (resource.getLocation().equals(scope.getLocation())) {
+ return b;
}
}
@@ -158,5 +169,10 @@ public class BundleResourceProcessor imp
}
}
+ public Session createSession(BundleContext arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java Mon Dec 13 18:26:19 2010
@@ -21,24 +21,20 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Future;
import org.apache.aries.subsystem.Subsystem;
import org.apache.aries.subsystem.SubsystemAdmin;
import org.apache.aries.subsystem.SubsystemConstants;
import org.apache.aries.subsystem.SubsystemEvent;
import org.apache.aries.subsystem.SubsystemException;
+import org.apache.aries.subsystem.SubsystemListener;
+import org.apache.aries.subsystem.scope.ScopeAdmin;
import org.apache.aries.subsystem.spi.Resource;
-import org.apache.felix.utils.manifest.Clause;
-import org.apache.felix.utils.manifest.Parser;
-import org.osgi.framework.Bundle;
+import org.apache.aries.subsystem.spi.ResourceResolver;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.Constants;
-import org.osgi.framework.SynchronousBundleListener;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
-import org.osgi.service.composite.CompositeBundle;
import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,125 +44,57 @@ public class SubsystemAdminImpl implemen
private static final Version SUBSYSTEM_MANIFEST_VERSION = new Version("1.0");
final BundleContext context;
+ final ScopeAdmin scopeAdmin;
final Map<Long, Subsystem> subsystems = new HashMap<Long, Subsystem>();
+ final ServiceTracker resourceResolverTracker;
final SubsystemEventDispatcher eventDispatcher;
- final ServiceTracker executorTracker;
- final HashMap<String, SubsystemFutureTask> installInProgress = new HashMap<String, SubsystemFutureTask>();
- final HashMap<String, SubsystemFutureTask> updateInProgress = new HashMap<String, SubsystemFutureTask>();
+ final ServiceTracker listenersTracker;
+ final Subsystem subsystem;
+ final Subsystem parentSubsystem;
- public SubsystemAdminImpl(BundleContext context, SubsystemEventDispatcher eventDispatcher) {
- this.context = context;
- this.eventDispatcher = eventDispatcher;
- this.executorTracker = new ServiceTracker(context, Executor.class.getName(), null);
- this.executorTracker.open();
- // Track subsystems
- synchronized (subsystems) {
- this.context.addBundleListener(new SynchronousBundleListener() {
- public void bundleChanged(BundleEvent event) {
- SubsystemAdminImpl.this.bundleChanged(event);
- }
- });
- loadSubsystems();
- }
+ public SubsystemAdminImpl(ScopeAdmin scopeAdmin, Subsystem subsystem, Subsystem parentSubsystem) {
+ context = Activator.getBundleContext();
+ this.eventDispatcher = Activator.getEventDispatcher();
+ this.scopeAdmin = scopeAdmin;
+ this.subsystem = subsystem;
+ this.parentSubsystem = parentSubsystem;
+ this.resourceResolverTracker = new ServiceTracker(context, ResourceResolver.class.getName(), null);
+ this.resourceResolverTracker.open();
+ this.listenersTracker = new ServiceTracker(context, SubsystemListener.class.getName(), null);
+ this.listenersTracker.open();
}
public void dispose() {
- executorTracker.close();
- }
-
- public void bundleChanged(BundleEvent event) {
- synchronized (subsystems) {
- Bundle bundle = event.getBundle();
- if (event.getType() == BundleEvent.UNINSTALLED) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Removing bundle symbolic name {} version {} from subsystems map being tracked", bundle.getSymbolicName(), bundle.getVersion());
- }
- subsystems.remove(bundle.getBundleId());
- }
- if (event.getType() == BundleEvent.UPDATED) {
- Subsystem s = isSubsystem(bundle);
-
- // If this is a subsystem we have in progress, then set the result on the SubsystemFutureTask
- if (updateInProgress.containsKey(s.getLocation())) {
- SubsystemFutureTask task = updateInProgress.remove(s.getLocation());
- task.set(s);
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(
- "Update of subsystem url {} is successful",
- s.getLocation());
- }
-
- // emit the subsystem event
- eventDispatcher.subsystemEvent(new SubsystemEvent(
- SubsystemEvent.Type.UPDATED, System.currentTimeMillis(), s));
-
- }
-
- }
- if (event.getType() == BundleEvent.INSTALLED) {
- Subsystem s = isSubsystem(bundle);
- if (s != null) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Adding bundle symbolic name {} version {} to subsystems map being tracked", bundle.getSymbolicName(), bundle.getVersion());
- }
- subsystems.put(s.getSubsystemId(), s);
-
- // If this is a subsystem we have in progress, then set the result on the SubsystemFutureTask
- if (installInProgress.containsKey(s.getLocation())) {
- SubsystemFutureTask task = installInProgress.remove(s
- .getLocation());
- task.set(s);
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(
- "Install of subsystem url {} is successful",
- s.getLocation());
- }
-
- // emit the subsystem event
- eventDispatcher.subsystemEvent(new SubsystemEvent(
- SubsystemEvent.Type.INSTALLED, System.currentTimeMillis(), s));
-
- }
- }
- }
- if (event.getType() == BundleEvent.RESOLVED) {
- Subsystem s = isSubsystem(bundle);
- if (s != null) {
- // emit the subsystem resolved event
- eventDispatcher.subsystemEvent(new SubsystemEvent(SubsystemEvent.Type.RESOLVED, System.currentTimeMillis(), s));
- }
- }
- }
+ resourceResolverTracker.close();
+ listenersTracker.close();
}
-
- protected void loadSubsystems() {
- synchronized (subsystems) {
- subsystems.clear();
- for (Bundle bundle : context.getBundles()) {
- Subsystem s = isSubsystem(bundle);
- if (s != null) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Adding bundle symbolic name {} version {} to subsystems map being tracked", bundle.getSymbolicName(), bundle.getVersion());
- }
- subsystems.put(s.getSubsystemId(), s);
+
+ private synchronized void refreshSubsystems() {
+ subsystems.clear();
+ /*for (Subsystem sub : subsystem.getChildrenSubsystems()) {
+ subsystems.put(sub.getSubsystemId(), sub);
+ }*/
+
+ final String filter = "(SubsystemParentId=" + subsystem.getSubsystemId() + ")";
+
+ try {
+ ServiceReference[] srs = context.getServiceReferences(SubsystemAdmin.class.getName(), filter);
+ if (srs != null) {
+ for (ServiceReference sr : srs) {
+ SubsystemAdmin childSubAdmin = (SubsystemAdmin)context.getService(sr);
+ Subsystem childSub = childSubAdmin.getSubsystem();
+ subsystems.put(childSub.getSubsystemId(), childSub);
+ context.ungetService(sr);
}
+
}
+ } catch (InvalidSyntaxException e) {
+ // ignore
}
}
-
- protected Subsystem isSubsystem(Bundle bundle) {
- if (bundle instanceof CompositeBundle) {
- // it is important not to use bundle.getSymbolicName() here as that would not contain the directives we need.
- String bsn = (String) bundle.getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- Clause[] bsnClauses = Parser.parseHeader(bsn);
- if ("true".equals(bsnClauses[0].getDirective(SubsystemConstants.SUBSYSTEM_DIRECTIVE))) {
- return new SubsystemImpl(this, (CompositeBundle) bundle, eventDispatcher);
- }
- }
- return null;
- }
-
+
public Subsystem getSubsystem(long id) {
+ refreshSubsystems();
synchronized (subsystems) {
for (Subsystem s : subsystems.values()) {
if (s.getSubsystemId() == id) {
@@ -178,6 +106,7 @@ public class SubsystemAdminImpl implemen
}
public Subsystem getSubsystem(String symbolicName, Version version) {
+ refreshSubsystems();
synchronized (subsystems) {
for (Subsystem s : subsystems.values()) {
if (s.getSymbolicName().equals(symbolicName) && s.getVersion().equals(version)) {
@@ -187,199 +116,138 @@ public class SubsystemAdminImpl implemen
return null;
}
}
-
+
public Collection<Subsystem> getSubsystems() {
+ refreshSubsystems();
synchronized (subsystems) {
return Collections.unmodifiableCollection(new ArrayList(subsystems.values()));
}
}
- public Future<Subsystem> install(String url) {
+ public Subsystem install(String url) {
return install(url, null);
}
- public synchronized Future<Subsystem> install(final String url, final InputStream is) {
+ public synchronized Subsystem install(String url, final InputStream is) throws SubsystemException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Installing subsystem url {}", url);
}
-
- // check if the subsystem install is already in progress
- Future<Subsystem> futureToReturn = installInProgress.get(url);
- if (futureToReturn != null) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("A Future<Subsystem> containing the same location identifier {} is already in installing.", url);
- }
- return futureToReturn;
- }
-
- // check if the subsystem has already been installed before proceeding with the installation
+ // let's check if the subsystem has been installed or not first before proceed installation
Subsystem toReturn = getInstalledSubsytem(url);
if (toReturn != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("A subsystem containing the same location identifier {} is already installed", url);
}
- return new ImmediateFuture<Subsystem>(toReturn);
+ return toReturn;
}
- // Create a new Future to handle the installation of the Subsystem
- SubsystemFutureTask installTask = new SubsystemFutureTask(new Runnable() {
- public void run() {
- Resource subsystemResource = new ResourceImpl(null, null,
- SubsystemConstants.RESOURCE_TYPE_SUBSYSTEM, url,
- Collections.<String, String> emptyMap()) {
- @Override
- public InputStream open() throws IOException {
- if (is != null) {
- return is;
- }
- return super.open();
- }
- };
- SubsystemResourceProcessor processor = new SubsystemResourceProcessor();
- SubsystemResourceProcessor.SubsystemSession session = processor
- .createSession(context);
- boolean success = false;
- try {
- session.process(subsystemResource);
- session.prepare();
- session.commit();
- success = true;
-
- } finally {
- if (!success) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(
- "Installing subsystem url {} is not successful, rollback now",
- url);
- }
- session.rollback();
- }
- }
+ Resource subsystemResource = new ResourceImpl(null, null, SubsystemConstants.RESOURCE_TYPE_SUBSYSTEM, url, Collections.<String, String>emptyMap()) {
+ @Override
+ public InputStream open() throws IOException {
+ if (is != null) {
+ return is;
+ }
+ return super.open();
}
- }, context, url, is);
-
- // Kick off the future and return it
- installInProgress.put(url, installTask);
-
- execute(installTask);
+ };
+ SubsystemResourceProcessor processor = new SubsystemResourceProcessor();
+ SubsystemResourceProcessor.SubsystemSession session = processor.createSession(this);
+ boolean success = false;
+ try {
+ session.process(subsystemResource);
+ session.prepare();
+ session.commit();
+ success = true;
+ } finally {
+ if (!success) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Installing subsystem url {} is not successful, rollback now", url);
+ }
+ session.rollback();
+ }
+ }
- return installTask;
- }
+ // let's get the one we just installed
+ if (success) {
+ toReturn = getInstalledSubsytem(url);
+ if (toReturn != null) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Installing subsystem url {} is successful", url);
+ }
+
+ // emit the subsystem event
+ eventDispatcher.subsystemEvent(new SubsystemEvent(SubsystemEvent.Type.INSTALLED, System.currentTimeMillis(), toReturn));
- /**
- * Execute the Future either using an Executor from the service registry or
- * a new Thread.
- *
- * @param installTask
- */
- private void execute(SubsystemFutureTask installTask) {
- Executor ex = (Executor) executorTracker.getService();
- if (ex != null) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Using Executor to execute Subsystem Install");
+ return toReturn;
}
- ex.execute(installTask);
- } else {
- // Create own thread if no executor is available
- Thread thread = new Thread(installTask);
- thread.start();
}
+
+ throw new IllegalStateException();
}
- public Future<Subsystem> update(Subsystem subsystem) throws SubsystemException {
- return update(subsystem, null);
+ public void update(Subsystem subsystem) throws SubsystemException {
+ update(subsystem, null);
}
- public Future<Subsystem> update(final Subsystem subsystem, final InputStream is) throws SubsystemException {
+ public void update(final Subsystem subsystem, final InputStream is) throws SubsystemException {
if (subsystem.getState().equals(Subsystem.State.UNINSTALLED)) {
throw new IllegalStateException("Unable to update subsystem as subsystem is already uninstalled");
}
- // check if the subsystem install is already in progress
- Future<Subsystem> futureToReturn = updateInProgress.get(subsystem.getLocation());
- if (futureToReturn != null) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("A Future<Subsystem> containing the same location identifier {} is already updating.", subsystem.getLocation());
- }
- return futureToReturn;
- }
-
- // Create a new Future to handle the update of the Subsystem
- SubsystemFutureTask updateTask = new SubsystemFutureTask(
- new Runnable() {
- public void run() {
- if (subsystem.getState().equals(Subsystem.State.ACTIVE)
- || subsystem.getState().equals(
- Subsystem.State.STARTING)
- || subsystem.getState().equals(
- Subsystem.State.STOPPING)) {
- subsystem.stop();
- }
- Resource subsystemResource = new ResourceImpl(
- subsystem.getSymbolicName(),
- subsystem.getVersion(),
- SubsystemConstants.RESOURCE_TYPE_SUBSYSTEM,
- subsystem.getLocation(),
- Collections.<String, String> emptyMap()) {
- @Override
- public InputStream open() throws IOException {
- if (is != null) {
- return is;
- }
- // subsystem-updatelocation specified the
- // manifest has higher priority than subsystem
- // original location
- String subsystemLoc = subsystem
- .getHeaders()
- .get(SubsystemConstants.SUBSYSTEM_UPDATELOCATION);
- if (subsystemLoc != null
- && subsystemLoc.length() > 0) {
- // we have a subsystem location lets us use it
- return new URL(subsystemLoc).openStream();
- }
- return super.open();
- }
- };
- SubsystemResourceProcessor processor = new SubsystemResourceProcessor();
- SubsystemResourceProcessor.SubsystemSession session = processor
- .createSession(context);
- boolean success = false;
- try {
- session.process(subsystemResource);
- session.prepare();
- session.commit();
- success = true;
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(
- "Updating subsystem {} is successful",
- subsystem.getSymbolicName());
- }
-
- } finally {
- if (!success) {
- session.rollback();
- }
- }
- }
- }, context, subsystem.getLocation(), is);
-
- // Kick off the future and return it
- updateInProgress.put(subsystem.getLocation(), updateTask);
-
- execute(updateTask);
-
- return updateTask;
+ if (subsystem.getState().equals(Subsystem.State.ACTIVE)
+ || subsystem.getState().equals(Subsystem.State.STARTING)
+ || subsystem.getState().equals(Subsystem.State.STOPPING)) {
+ subsystem.stop();
+ }
+ Resource subsystemResource = new ResourceImpl(subsystem.getSymbolicName(), subsystem.getVersion(), SubsystemConstants.RESOURCE_TYPE_SUBSYSTEM, subsystem.getLocation(), Collections.<String, String>emptyMap()) {
+ @Override
+ public InputStream open() throws IOException {
+ if (is != null) {
+ return is;
+ }
+ // subsystem-updatelocation specified the manifest has higher priority than subsystem original location
+ String subsystemLoc = subsystem.getHeaders().get(SubsystemConstants.SUBSYSTEM_UPDATELOCATION);
+ if (subsystemLoc != null && subsystemLoc.length() > 0) {
+ // we have a subsystem location let us use it
+ return new URL(subsystemLoc).openStream();
+ }
+ return super.open();
+ }
+ };
+ SubsystemResourceProcessor processor = new SubsystemResourceProcessor();
+ SubsystemResourceProcessor.SubsystemSession session = processor.createSession(this);
+ boolean success = false;
+ try {
+ session.process(subsystemResource);
+ session.prepare();
+ session.commit();
+ success = true;
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Updating subsystem {} is successful", subsystem.getSymbolicName());
+ }
+
+ // emit the subsystem event
+ eventDispatcher.subsystemEvent(new SubsystemEvent(SubsystemEvent.Type.UPDATED, System.currentTimeMillis(), subsystem));
+
+ } finally {
+ if (!success) {
+ session.rollback();
+ }
+ }
}
public void uninstall(Subsystem subsystem) {
if (subsystem.getState().equals(Subsystem.State.UNINSTALLED)) {
- throw new IllegalStateException("Unable to uninstall subsystem as subsystem is already uninstalled");
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Unable to uninstall subsystem {} as subsystem is already uninstalled", subsystem.getSymbolicName());
+ }
+ return;
}
Resource subsystemResource = new ResourceImpl(subsystem.getSymbolicName(), subsystem.getVersion(), SubsystemConstants.RESOURCE_TYPE_SUBSYSTEM, subsystem.getLocation(), Collections.<String, String>emptyMap());
SubsystemResourceProcessor processor = new SubsystemResourceProcessor();
- SubsystemResourceProcessor.SubsystemSession session = processor.createSession(context);
+ SubsystemResourceProcessor.SubsystemSession session = processor.createSession(this);
boolean success = false;
try {
session.dropped(subsystemResource);
@@ -400,6 +268,11 @@ public class SubsystemAdminImpl implemen
}
}
+ public boolean cancel() {
+ // TODO
+ return false;
+ }
+
private Subsystem getInstalledSubsytem(String url) {
for (Subsystem ss : getSubsystems()) {
if (url.equals(ss.getLocation())) {
@@ -408,5 +281,18 @@ public class SubsystemAdminImpl implemen
}
return null;
}
-
+
+ // return the scope admin associated with the subsystemadmin.
+ protected ScopeAdmin getScopeAdmin() {
+ return this.scopeAdmin;
+ }
+
+ public Subsystem getSubsystem() {
+ return this.subsystem;
+ }
+
+ public Subsystem getParentSubsystem() {
+ return this.parentSubsystem;
+ }
}
+
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemImpl.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemImpl.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemImpl.java Mon Dec 13 18:26:19 2010
@@ -1,4 +1,5 @@
/*
+ /*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -16,50 +17,126 @@ package org.apache.aries.subsystem.core.
import java.util.*;
import org.apache.aries.subsystem.Subsystem;
+import org.apache.aries.subsystem.SubsystemAdmin;
+import org.apache.aries.subsystem.SubsystemConstants;
import org.apache.aries.subsystem.SubsystemEvent;
import org.apache.aries.subsystem.SubsystemException;
+import org.apache.aries.subsystem.Subsystem.State;
+import org.apache.aries.subsystem.scope.Scope;
+import org.apache.aries.subsystem.scope.ScopeAdmin;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
-import org.osgi.service.composite.CompositeBundle;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
public class SubsystemImpl implements Subsystem {
final long id;
- final SubsystemAdminImpl admin;
- final CompositeBundle composite;
final SubsystemEventDispatcher eventDispatcher;
+ final Scope scope;
+ Map<String, String> headers;
+ private final ServiceTracker serviceTracker;
+ private final BundleContext context;
+ private final Map<Long, Subsystem> subsystems = new HashMap<Long, Subsystem>();
+
+ public SubsystemImpl(Scope scope, Map<String, String> headers) {
+ this.scope = scope;
+ this.id = this.scope.getId();
+ this.eventDispatcher = Activator.getEventDispatcher();
+ this.headers = headers;
+ Filter filter = null;
+ try {
+ filter = FrameworkUtil.createFilter("(&("
+ + Constants.OBJECTCLASS + "=" + SubsystemAdmin.class.getName() + "))");
+ } catch (InvalidSyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ this.context = Activator.getBundleContext();
+ serviceTracker = new ServiceTracker(context, filter,
+ new ServiceTrackerCustomizer() {
+
+ public Object addingService(ServiceReference reference) {
+ // adding new service, update admins map
+ SubsystemAdmin sa = (SubsystemAdmin)context.getService(reference);
+ if (sa.getParentSubsystem().getSubsystemId() == id) {
+ // it is the child subsystems for the current subsystem
+ synchronized (subsystems) {
+ subsystems.put(sa.getSubsystem().getSubsystemId(), sa.getSubsystem());
+ }
+ }
+
+ return sa;
+ }
+
+ public void modifiedService(ServiceReference reference,
+ Object service) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removedService(ServiceReference reference,
+ Object service) {
+ SubsystemAdmin sa = (SubsystemAdmin) service;
+ if (sa.getParentSubsystem().getSubsystemId() == id) {
+ // it is the child subsystems for the current subsystem
+ synchronized (subsystems) {
+ subsystems.remove(sa.getSubsystem().getSubsystemId());
+ }
+ }
+ }
- public SubsystemImpl(SubsystemAdminImpl admin, CompositeBundle composite, SubsystemEventDispatcher eventDispatcher) {
- this.admin = admin;
- this.composite = composite;
- this.id = composite.getBundleId();
- this.eventDispatcher = eventDispatcher;
+ });
}
public State getState() {
- switch (composite.getState())
- {
- case Bundle.UNINSTALLED:
- return State.UNINSTALLED;
- case Bundle.INSTALLED:
- return State.INSTALLED;
- case Bundle.RESOLVED:
- return State.RESOLVED;
- case Bundle.STARTING:
- return State.STARTING;
- case Bundle.ACTIVE:
- return State.ACTIVE;
- case Bundle.STOPPING:
- return State.STOPPING;
- }
+ // check bundles status
+ Collection<Bundle> bundles = getBundles();
+ if (checkBundlesStatus(bundles, Bundle.UNINSTALLED)) {
+ return State.UNINSTALLED;
+ } else if (checkBundlesStatus(bundles, Bundle.INSTALLED)) {
+ return State.INSTALLED;
+ } else if (checkBundlesStatus(bundles, Bundle.RESOLVED)) {
+ return State.RESOLVED;
+ } else if (checkBundlesStatus(bundles, Bundle.STARTING)) {
+ return State.STARTING;
+ } else if (checkBundlesStatus(bundles, Bundle.ACTIVE)) {
+ return State.ACTIVE;
+ } else if (checkBundlesStatus(bundles, Bundle.STOPPING)) {
+ return State.STOPPING;
+ }
+
throw new SubsystemException("Unable to retrieve subsystem state");
}
+ /**
+ * check if all bundles in the collection has the state
+ *
+ * @return
+ */
+ private boolean checkBundlesStatus(Collection<Bundle> bundles, int state) {
+ for (Bundle b : bundles) {
+ if (b.getState() != state) {
+ return false;
+ }
+ }
+
+ return true;
+ }
public void start() throws SubsystemException {
try {
eventDispatcher.subsystemEvent(new SubsystemEvent(SubsystemEvent.Type.STARTING, System.currentTimeMillis(), this));
- composite.start();
+ Collection<Bundle> bundles = this.scope.getBundles();
+ for (Bundle b : bundles) {
+ b.start();
+ }
eventDispatcher.subsystemEvent(new SubsystemEvent(SubsystemEvent.Type.STARTED, System.currentTimeMillis(), this));
} catch (BundleException e) {
throw new SubsystemException("Unable to start subsystem", e);
@@ -69,7 +146,10 @@ public class SubsystemImpl implements Su
public void stop() throws SubsystemException {
try {
eventDispatcher.subsystemEvent(new SubsystemEvent(SubsystemEvent.Type.STOPPING, System.currentTimeMillis(), this));
- composite.stop();
+ Collection<Bundle> bundles = this.scope.getBundles();
+ for (Bundle b : bundles) {
+ b.start();
+ }
eventDispatcher.subsystemEvent(new SubsystemEvent(SubsystemEvent.Type.STOPPED, System.currentTimeMillis(), this));
} catch (BundleException e) {
throw new SubsystemException("Unable to stop subsystem", e);
@@ -77,38 +157,44 @@ public class SubsystemImpl implements Su
}
public long getSubsystemId() {
- return composite.getBundleId();
+ return this.id;
}
public String getLocation() {
- return composite.getLocation();
+ return scope.getLocation();
}
public String getSymbolicName() {
- return composite.getSymbolicName();
+ return scope.getName();
}
public Version getVersion() {
- return composite.getVersion();
+ return Version.parseVersion(headers.get(SubsystemConstants.SUBSYSTEM_VERSION));
}
public Map<String, String> getHeaders() {
- return getHeaders(null);
+ return Collections.unmodifiableMap(headers);
}
+ public void updateHeaders(Map<String, String> headers) {
+ this.headers = headers;
+ }
+
public Map<String, String> getHeaders(String locale) {
- final Dictionary dict = composite.getHeaders(locale);
- return new DictionaryAsMap(dict);
+ return null;
}
- public Collection<Bundle> getConstituents() {
- List<Bundle> list = new ArrayList<Bundle>();
- Bundle[] bundles = composite.getSystemBundleContext().getBundles();
- for (Bundle bundle : bundles) {
- if (bundle.getBundleId() != 0) {
- list.add(bundle);
- }
+ public Collection<Bundle> getBundles() {
+ return this.scope.getBundles();
+ }
+
+ protected Scope getScope() {
+ return scope;
+ }
+
+ public Collection<Subsystem> getChildrenSubsystems() {
+ synchronized (subsystems) {
+ return Collections.unmodifiableCollection(new ArrayList(subsystems.values()));
}
- return list;
}
}
\ No newline at end of file
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java Mon Dec 13 18:26:19 2010
@@ -13,12 +13,23 @@
*/
package org.apache.aries.subsystem.core.internal;
+import static org.apache.aries.subsystem.SubsystemConstants.SUBSYSTEM_CONTENT;
+import static org.apache.aries.subsystem.SubsystemConstants.SUBSYSTEM_DIRECTIVE;
+import static org.apache.aries.subsystem.SubsystemConstants.SUBSYSTEM_EXPORTPACKAGE;
+import static org.apache.aries.subsystem.SubsystemConstants.SUBSYSTEM_IMPORTPACKAGE;
+import static org.apache.aries.subsystem.SubsystemConstants.SUBSYSTEM_MANIFESTVERSION;
+import static org.apache.aries.subsystem.SubsystemConstants.SUBSYSTEM_RESOURCES;
+import static org.apache.aries.subsystem.SubsystemConstants.SUBSYSTEM_SYMBOLICNAME;
+import static org.apache.aries.subsystem.SubsystemConstants.SUBSYSTEM_VERSION;
+import static org.apache.aries.subsystem.core.internal.FileUtils.closeQuietly;
+import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME;
+import static org.osgi.framework.Constants.BUNDLE_VERSION;
+
import java.io.File;
import java.io.FileInputStream;
-import java.io.IOException;
import java.io.InputStream;
-import java.net.URL;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
@@ -31,63 +42,57 @@ import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor;
+import org.apache.aries.subsystem.Subsystem;
import org.apache.aries.subsystem.SubsystemAdmin;
import org.apache.aries.subsystem.SubsystemConstants;
import org.apache.aries.subsystem.SubsystemException;
+import org.apache.aries.subsystem.scope.InstallInfo;
+import org.apache.aries.subsystem.scope.ScopeAdmin;
+import org.apache.aries.subsystem.scope.ScopeUpdate;
+import org.apache.aries.subsystem.scope.SharePolicy;
import org.apache.aries.subsystem.spi.Resource;
import org.apache.aries.subsystem.spi.ResourceProcessor;
import org.apache.aries.subsystem.spi.ResourceResolver;
import org.apache.felix.utils.manifest.Clause;
import org.apache.felix.utils.manifest.Parser;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.Version;
-import org.osgi.service.composite.CompositeAdmin;
-import org.osgi.service.composite.CompositeBundle;
-import org.osgi.service.composite.CompositeConstants;
+import org.osgi.framework.wiring.Capability;
import org.osgi.util.tracker.ServiceTracker;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.aries.subsystem.core.internal.FileUtils.closeQuietly;
-
-import static org.osgi.framework.Constants.*;
-import static org.osgi.service.composite.CompositeConstants.*;
-import static org.apache.aries.subsystem.SubsystemConstants.*;
public class SubsystemResourceProcessor implements ResourceProcessor {
- private static final Logger LOGGER = LoggerFactory
- .getLogger(SubsystemResourceProcessor.class);
-
private static final Version SUBSYSTEM_MANIFEST_VERSION = new Version("1.0");
- public SubsystemSession createSession(BundleContext context) {
- return new SubsystemSession(context);
+ public SubsystemSession createSession(SubsystemAdmin subsystemAdmin) {
+ return new SubsystemSession(subsystemAdmin);
}
public static class SubsystemSession implements Session {
private static final long TIMEOUT = 30000;
+ private final SubsystemAdmin subsystemAdmin;
- private final BundleContext context;
- private final Map<Resource, CompositeBundle> installed = new HashMap<Resource, CompositeBundle>();
+ private final Map<Resource, Subsystem> installed = new HashMap<Resource, Subsystem>();
/*
* Map to keep track of composite bundle headers before the update and
* the updated composite bundle. This is needed for rollback
*/
- private final Map<Dictionary, CompositeBundle> updated = new HashMap<Dictionary, CompositeBundle>();
- private final Map<Resource, CompositeBundle> removed = new HashMap<Resource, CompositeBundle>();
- private final List<CompositeBundle> stopped = new ArrayList<CompositeBundle>();
+ private final Map<Map<String, String>, Subsystem> updated = new HashMap<Map<String, String>, Subsystem>();
+ private final Map<Resource, Subsystem> removed = new HashMap<Resource, Subsystem>();
+ private final List<Subsystem> stopped = new ArrayList<Subsystem>();
private final Map<String, ServiceTracker> trackers = new HashMap<String, ServiceTracker>();
- private final Map<BundleContext, Map<String, Session>> sessions = new HashMap<BundleContext, Map<String, Session>>();
-
- public SubsystemSession(BundleContext context) {
- this.context = context;
+ private final Map<SubsystemAdmin, Map<String, Session>> sessions = new HashMap<SubsystemAdmin, Map<String, Session>>();
+ private final BundleContext context;
+
+ public SubsystemSession(SubsystemAdmin subsystemAdmin) {
+ this.subsystemAdmin = subsystemAdmin;
+ this.context = Activator.getBundleContext();
}
/**
@@ -99,15 +104,9 @@ public class SubsystemResourceProcessor
*/
private void process(Resource res, Manifest manifest) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(
- "Installing subsystem resource {}",
- res.getLocation());
- }
-
try {
-
- CompositeAdmin admin = getService(CompositeAdmin.class);
+ SubsystemAdminImpl adminImpl = (SubsystemAdminImpl)subsystemAdmin;
+ ScopeAdmin admin = adminImpl.getScopeAdmin();
ResourceResolver resolver = getService(ResourceResolver.class);
if (manifest == null) {
@@ -141,13 +140,6 @@ public class SubsystemResourceProcessor
List<Resource> content = new ArrayList<Resource>();
String contentHeader = manifest.getMainAttributes().getValue(
SUBSYSTEM_CONTENT);
-
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(
- "Installing subsystem content {}",
- contentHeader);
- }
-
Clause[] contentClauses = Parser.parseHeader(contentHeader);
for (Clause c : contentClauses) {
Resource r = resolver.find(c.toString());
@@ -167,40 +159,52 @@ public class SubsystemResourceProcessor
SUBSYSTEM_VERSION);
checkManifestHeaders(manifest, ssn, sv);
- Map<String, String> headers = computeCompositeHeaders(manifest,
+ Map<String, String> headers = computeSubsystemHeaders(manifest,
ssn, sv);
// Check existing bundles
- CompositeBundle composite = findSubsystemComposite(res);
- if (composite == null) {
+ Subsystem subsystem = findSubsystem(res);
+ ScopeUpdate scopeUpdate = admin.newScopeUpdate();
+ ScopeUpdate childScopeUpdate;
+ if (subsystem == null) {
// brand new install
- composite = admin.installCompositeBundle(res.getLocation(),
- headers, Collections.<String, String> emptyMap());
- installed.put(res, composite);
+
+ childScopeUpdate = scopeUpdate.newChild(headers.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + headers.get(Constants.BUNDLE_VERSION), res.getLocation());
+ Map<String, List<SharePolicy>> exportSharePolicies = childScopeUpdate.getSharePolicies(SharePolicy.TYPE_EXPORT);
+ Map<String, List<SharePolicy>> importSharePolicies = childScopeUpdate.getSharePolicies(SharePolicy.TYPE_IMPORT);
+
+ setupSharePolicies(exportSharePolicies, importSharePolicies, headers);
+ scopeUpdate.commit();
+
+ ScopeAdmin childScopeAdmin = getService(ScopeAdmin.class, "ScopeId=" + childScopeUpdate.getScope().getId());
+
+ subsystem = new SubsystemImpl(childScopeUpdate.getScope(), headers);
+ SubsystemAdmin childSubsystemAdmin = new SubsystemAdminImpl(childScopeAdmin, subsystem, subsystemAdmin.getSubsystem());
+ context.registerService(SubsystemAdmin.class.getName(), childSubsystemAdmin, DictionaryBuilder.build("SubsystemParentId", childSubsystemAdmin.getParentSubsystem().getSubsystemId(), "SubsystemId", subsystem.getSubsystemId()));
+
+ installed.put(res, subsystem);
+
+
} else {
// update
- // capture composite headers before update
- Dictionary dictionary = composite.getHeaders();
-
- String previousContentHeader = (String) composite
- .getHeaders().get(SUBSYSTEM_CONTENT);
+ // capture data before update
+ Map<String, String> subsystemHeaders = subsystem.getHeaders();
+ String previousContentHeader = (String) subsystemHeaders.get(SUBSYSTEM_CONTENT);
Clause[] previousContentClauses = Parser
.parseHeader(previousContentHeader);
for (Clause c : previousContentClauses) {
Resource r = resolver.find(c.toString());
previous.add(r);
}
- if (composite.getState() == Bundle.ACTIVE) {
- composite.stop();
- stopped.add(composite);
- }
- composite.update(headers);
- updated.put(dictionary, composite);
+
+ subsystem.updateHeaders(headers);
+ updated.put(subsystemHeaders, subsystem);
}
- composite.getSystemBundleContext().registerService(
- SubsystemAdmin.class.getName(),
- new Activator.SubsystemAdminFactory(), null);
+ // content is installed in the scope, so need to find the subsystemAdmin for the scope first
+ long scopeId = subsystem.getSubsystemId();
+ SubsystemAdmin childAdmin = getService(SubsystemAdmin.class, "SubsystemId=" + scopeId);
+
for (Resource r : previous) {
boolean stillHere = false;
for (Resource r2 : content) {
@@ -211,15 +215,19 @@ public class SubsystemResourceProcessor
}
}
if (!stillHere) {
- getSession(composite.getSystemBundleContext(),
+ getSession(childAdmin,
r.getType()).dropped(r);
}
}
+
+ // additional resource is installed outside of the subsystem.
for (Resource r : additional) {
- getSession(context, r.getType()).process(r);
+ getSession(subsystemAdmin, r.getType()).process(r);
}
+
+
for (Resource r : content) {
- getSession(composite.getSystemBundleContext(), r.getType())
+ getSession(childAdmin, r.getType())
.process(r);
}
@@ -230,45 +238,97 @@ public class SubsystemResourceProcessor
}
}
+ private void setupSharePolicies(
+ Map<String, List<SharePolicy>> exportSharePolicies,
+ Map<String, List<SharePolicy>> importSharePolicies,
+ Map<String, String> headers) {
+ String importPackage = headers.get(SubsystemConstants.SUBSYSTEM_IMPORTPACKAGE);
+ String exportPackage = headers.get(SubsystemConstants.SUBSYSTEM_EXPORTPACKAGE);
+ String importService = headers.get(SubsystemConstants.SUBSYSTEM_IMPORTSERVICE);
+ String exportService = headers.get(SubsystemConstants.SUBSYSTEM_EXPORTSERVICE);
+ if (importPackage != null && !importPackage.trim().isEmpty()) {
+ List<SharePolicy> importPackagePolicies = importSharePolicies.get(Capability.PACKAGE_CAPABILITY);
+ if (importPackagePolicies == null) {
+ importPackagePolicies = new ArrayList<SharePolicy>();
+ importSharePolicies.put(Capability.PACKAGE_CAPABILITY,importPackagePolicies);
+ }
+
+ importPackagePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, Capability.PACKAGE_CAPABILITY, createFilter(importPackage, Capability.PACKAGE_CAPABILITY)));
+ }
+
+ if (importService != null && !importService.trim().isEmpty()) {
+ List<SharePolicy> importServicePolicies = importSharePolicies.get("osgi.service");
+ if (importServicePolicies == null) {
+ importServicePolicies = new ArrayList<SharePolicy>();
+ importSharePolicies.put("osgi.service",importServicePolicies);
+ }
+
+ importServicePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, "osgi.service", createFilter(importService, "osgi.service")));
+ }
+
+ }
+
+ private Filter createFilter(String packages, String namespace) {
+ if (namespace.equals(Capability.PACKAGE_CAPABILITY)) {
+ // split packages
+ List<String> pkgs = ManifestHeaderProcessor.split(packages, ",");
+ StringBuffer sb = new StringBuffer();
+ sb.append("(|");
+ for (String pkg : pkgs) {
+ sb.append("(" + Capability.PACKAGE_CAPABILITY + "=" + pkg + ")");
+ }
+ sb.append(")");
+ try {
+ return FrameworkUtil.createFilter(sb.toString());
+ } catch (InvalidSyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+ if (namespace.equals("osgi.service")) {
+ // split packages
+ List<String> pkgs = ManifestHeaderProcessor.split(packages, ",");
+ StringBuffer sb = new StringBuffer();
+ sb.append("(|");
+ for (String pkg : pkgs) {
+ sb.append("(osgi.service=" + pkg + ")");
+ }
+ sb.append(")");
+ try {
+ return FrameworkUtil.createFilter(sb.toString());
+ } catch (InvalidSyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+ return null;
+ }
+
public void process(Resource res) throws SubsystemException {
process(res, null);
}
public void dropped(Resource res) throws SubsystemException {
- CompositeBundle composite = findSubsystemComposite(res);
- if (composite == null) {
+ Subsystem subsystem = findSubsystem(res);
+ if (subsystem == null) {
throw new SubsystemException(
"Unable to find matching subsystem to uninstall");
}
- try {
- // TODO: iterate through all resources and ask for a removal on
- // each one
- composite.uninstall();
- removed.put(res, composite);
- } catch (BundleException e) {
- throw new SubsystemException("Unable to uninstall subsystem", e);
- }
- }
+ // TODO: iterate through all resources and ask for a removal on
+ // each one
+ subsystemAdmin.uninstall(subsystem);
+ removed.put(res, subsystem);
- protected CompositeBundle findSubsystemComposite(Resource resource) {
- for (Bundle bundle : context.getBundles()) {
- if (resource.getLocation().equals(bundle.getLocation())) {
- if (bundle instanceof CompositeBundle) {
- CompositeBundle composite = (CompositeBundle) bundle;
- String bsn = (String) bundle.getHeaders().get(
- Constants.BUNDLE_SYMBOLICNAME);
- Clause[] bsnClauses = Parser.parseHeader(bsn);
- if ("true"
- .equals(bsnClauses[0]
- .getDirective(SubsystemConstants.SUBSYSTEM_DIRECTIVE))) {
- return composite;
- } else {
- throw new SubsystemException(
- "A bundle with the same location already exists!");
- }
+ }
- }
+ protected Subsystem findSubsystem(Resource resource) {
+ for (Subsystem subsystem : this.subsystemAdmin.getSubsystems()) {
+ if (resource.getLocation().equals(subsystem.getLocation())) {
+ return subsystem;
}
}
return null;
@@ -280,12 +340,8 @@ public class SubsystemResourceProcessor
s.prepare();
}
}
- for (CompositeBundle composite : stopped) {
- try {
- composite.start();
- } catch (BundleException e) {
- throw new SubsystemException(e);
- }
+ for (Subsystem subsystem : stopped) {
+ subsystem.start();
}
}
@@ -303,38 +359,32 @@ public class SubsystemResourceProcessor
public void rollback() {
- for (CompositeBundle c : installed.values()) {
- try {
- c.uninstall();
- } catch (BundleException e) {
- // Ignore
- }
+ for (Subsystem subsystem : installed.values()) {
+ subsystemAdmin.uninstall(subsystem);
}
installed.clear();
// Handle updated subsystems
- Set<Map.Entry<Dictionary, CompositeBundle>> updatedSet = updated
+ Set<Map.Entry<Map<String, String>, Subsystem>> updatedSet = updated
.entrySet();
- for (Entry<Dictionary, CompositeBundle> entry : updatedSet) {
- Dictionary oldDic = entry.getKey();
- CompositeBundle cb = entry.getValue();
+ for (Entry<Map<String, String>, Subsystem> entry : updatedSet) {
+ Map<String, String> oldHeader = entry.getKey();
+ Subsystem subsystem = entry.getValue();
// let's build a Manifest from oldDict
Manifest manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
- Map<String, String> headerMap = new DictionaryAsMap(oldDic);
-
- attributes.putAll(headerMap);
+ attributes.putAll(oldHeader);
String symbolicName = attributes
.getValue(Constants.BUNDLE_SYMBOLICNAME);
Version v = Version.parseVersion(attributes
.getValue(Constants.BUNDLE_VERSION));
Resource subsystemResource = new ResourceImpl(symbolicName, v,
- SubsystemConstants.RESOURCE_TYPE_SUBSYSTEM, cb
+ SubsystemConstants.RESOURCE_TYPE_SUBSYSTEM, subsystem
.getLocation(), Collections
.<String, String> emptyMap());
try {
- Session session = getSession(context, subsystemResource
+ Session session = getSession(subsystemAdmin, subsystemResource
.getType());
if (session instanceof SubsystemSession) {
((SubsystemSession) session).process(subsystemResource,
@@ -353,11 +403,11 @@ public class SubsystemResourceProcessor
}
// handle uninstalled subsystem
- Set<Map.Entry<Resource, CompositeBundle>> set = removed.entrySet();
- for (Map.Entry<Resource, CompositeBundle> entry : set) {
+ Set<Map.Entry<Resource, Subsystem>> set = removed.entrySet();
+ for (Map.Entry<Resource, Subsystem> entry : set) {
Resource res = entry.getKey();
try {
- getSession(context, res.getType()).process(res);
+ getSession(subsystemAdmin, res.getType()).process(res);
} catch (SubsystemException e) {
throw e;
} catch (Exception e) {
@@ -377,16 +427,16 @@ public class SubsystemResourceProcessor
closeTrackers();
}
- protected Session getSession(BundleContext context, String type)
+ protected Session getSession(SubsystemAdmin admin, String type)
throws InvalidSyntaxException, InterruptedException {
- Map<String, Session> sm = this.sessions.get(context);
+ Map<String, Session> sm = this.sessions.get(admin);
if (sm == null) {
sm = new HashMap<String, Session>();
- this.sessions.put(context, sm);
+ this.sessions.put(admin, sm);
}
Session session = sm.get(type);
if (session == null) {
- session = getProcessor(type).createSession(context);
+ session = getProcessor(type).createSession(admin);
sm.put(type, session);
}
return session;
@@ -470,19 +520,12 @@ public class SubsystemResourceProcessor
// TODO add any other symbolic name to check
Clause[] ssnClauses = Parser.parseHeader(ssn);
String ssDirective = ssnClauses[0].getDirective(SUBSYSTEM_DIRECTIVE);
- String comDirective = ssnClauses[0].getDirective(COMPOSITE_DIRECTIVE);
if (ssDirective != null && ssDirective.equalsIgnoreCase("false")) {
throw new SubsystemException("Invalid " + SUBSYSTEM_DIRECTIVE
+ " directive in " + SUBSYSTEM_SYMBOLICNAME + ": "
+ ssDirective);
}
- if (ssDirective != null && comDirective.equalsIgnoreCase("false")) {
- throw new SubsystemException("Invalid " + COMPOSITE_DIRECTIVE
- + " directive in " + SUBSYSTEM_SYMBOLICNAME + ": "
- + comDirective);
- }
-
if (sv == null || sv.length() == 0) {
throw new SubsystemException("Invalid subsystem version: " + sv);
}
@@ -500,24 +543,19 @@ public class SubsystemResourceProcessor
// if the ssn already contains COMPOSITE_DIRECTIVE or SUBSYSTEM_DIRECTIVE
// directive
// let's not add them again
- private static String getCompositeSymbolicName(String ssn) {
+ private static String getSubsystemSymbolicName(String ssn) {
Clause[] ssnClauses = Parser.parseHeader(ssn);
String ssDirective = ssnClauses[0].getDirective(SUBSYSTEM_DIRECTIVE);
- String comDirective = ssnClauses[0].getDirective(COMPOSITE_DIRECTIVE);
- if (ssDirective == null && comDirective == null) {
- ssn = ssn + ";" + COMPOSITE_DIRECTIVE + ":=true;"
+ if (ssDirective == null ) {
+ ssn = ssn + ";"
+ SUBSYSTEM_DIRECTIVE + ":=true";
- } else if (ssDirective == null) {
- ssn = ssn + ";" + COMPOSITE_DIRECTIVE + ":=true;";
- } else if (comDirective == null) {
- ssn = ssn + ";" + SUBSYSTEM_DIRECTIVE + ":=true;";
- }
+ }
return ssn;
}
- private static Map<String, String> computeCompositeHeaders(
+ private static Map<String, String> computeSubsystemHeaders(
Manifest manifest, String ssn, String sv) {
// Grab all headers
Map<String, String> headers = new HashMap<String, String>();
@@ -530,23 +568,12 @@ public class SubsystemResourceProcessor
}
// Create the required composite headers
- headers.put(BUNDLE_SYMBOLICNAME, getCompositeSymbolicName(ssn));
+ headers.put(BUNDLE_SYMBOLICNAME, getSubsystemSymbolicName(ssn));
headers.put(BUNDLE_VERSION, sv);
String subImportPkg = headers.get(SUBSYSTEM_IMPORTPACKAGE);
String subExportPkg = headers.get(SUBSYSTEM_EXPORTPACKAGE);
- if (subImportPkg != null && subImportPkg.length() > 0) {
- // use subsystem-importpackage for composite-importpackage
- headers.put(CompositeConstants.COMPOSITE_PACKAGE_IMPORT_POLICY,
- subImportPkg);
- } else {
- // TODO: let's compute the import package for the subsystem
- }
- if (subExportPkg != null && subExportPkg.length() > 0) {
- // use subsystem-importpackage for composite-importpackage
- headers.put(CompositeConstants.COMPOSITE_PACKAGE_EXPORT_POLICY,
- subExportPkg);
- }
+
// TODO: compute other composite manifest entries
// TODO: compute list of bundles
@@ -554,4 +581,9 @@ public class SubsystemResourceProcessor
return headers;
}
+ public Session createSession(BundleContext arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
\ No newline at end of file
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-example/subsystem-helloIsolation/src/main/java/org/apache/aries/subsystem/example/helloIsolation/Activator.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-example/subsystem-helloIsolation/src/main/java/org/apache/aries/subsystem/example/helloIsolation/Activator.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-example/subsystem-helloIsolation/src/main/java/org/apache/aries/subsystem/example/helloIsolation/Activator.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-example/subsystem-helloIsolation/src/main/java/org/apache/aries/subsystem/example/helloIsolation/Activator.java Mon Dec 13 18:26:19 2010
@@ -39,6 +39,15 @@ public class Activator implements Bundle
*/
public void start(BundleContext context) throws Exception {
System.out.println("bundle helloIsolation start");
+
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ System.out.println("HelloIsolationImpl: system manager is not null");
+ } else {
+ System.out.println("HelloIsolationImpl: system manager is still null");
+ }
+
+
sr = context.registerService(HelloIsolation.class.getName(),
new HelloIsolationImpl(), null);
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-example/subsystem-helloIsolation/src/main/java/org/apache/aries/subsystem/example/helloIsolation/HelloIsolation.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-example/subsystem-helloIsolation/src/main/java/org/apache/aries/subsystem/example/helloIsolation/HelloIsolation.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-example/subsystem-helloIsolation/src/main/java/org/apache/aries/subsystem/example/helloIsolation/HelloIsolation.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-example/subsystem-helloIsolation/src/main/java/org/apache/aries/subsystem/example/helloIsolation/HelloIsolation.java Mon Dec 13 18:26:19 2010
@@ -14,7 +14,10 @@
package org.apache.aries.subsystem.example.helloIsolation;
+import java.security.Permission;
+
public interface HelloIsolation
{
public void hello();
+ public void checkPermission(final Permission permission) throws SecurityException;
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-example/subsystem-helloIsolation/src/main/java/org/apache/aries/subsystem/example/helloIsolation/HelloIsolationImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-example/subsystem-helloIsolation/src/main/java/org/apache/aries/subsystem/example/helloIsolation/HelloIsolationImpl.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-example/subsystem-helloIsolation/src/main/java/org/apache/aries/subsystem/example/helloIsolation/HelloIsolationImpl.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-example/subsystem-helloIsolation/src/main/java/org/apache/aries/subsystem/example/helloIsolation/HelloIsolationImpl.java Mon Dec 13 18:26:19 2010
@@ -14,6 +14,11 @@
package org.apache.aries.subsystem.example.helloIsolation;
+import java.security.AccessController;
+import java.security.Permission;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
public class HelloIsolationImpl implements HelloIsolation
{
@@ -22,4 +27,28 @@ public class HelloIsolationImpl implemen
System.out.println("hello from HelloIsolationImpl");
}
+ // test java2 security
+
+ public void checkPermission(final Permission permission) throws SecurityException {
+ System.out.println("HelloIsolationImpl: enter checkpermission");
+
+ try {
+ AccessController.doPrivileged(new PrivilegedExceptionAction() {
+ public Object run() throws SecurityException {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ System.out.println("HelloIsolationImpl: system manager is not null");
+
+ security.checkPermission(permission);
+ return null;
+ }
+ System.out.println("HelloIsolationImpl: system manager is still null");
+
+ return null;
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ throw (SecurityException) e.getException();
+ }
+ }
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/pom.xml Mon Dec 13 18:26:19 2010
@@ -38,13 +38,9 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>org.eclipse</groupId>
<artifactId>osgi</artifactId>
+ <version>3.7.0.v20100910</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -59,11 +55,18 @@
</dependency>
<dependency>
<groupId>org.apache.aries.subsystem</groupId>
- <artifactId>org.apache.aries.subsystem.executor</artifactId>
- <scope>test</scope>
- <version>0.3-incubating-SNAPSHOT</version>
+ <artifactId>org.apache.aries.subsystem.scope.api</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.aries.subsystem</groupId>
+ <artifactId>org.apache.aries.subsystem.scope.impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.subsystem</groupId>
+ <artifactId>org.apache.aries.subsystem.executor</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.aries.testsupport</groupId>
<artifactId>org.apache.aries.testsupport.unit</artifactId>
<scope>test</scope>
@@ -137,6 +140,12 @@
<artifactId>org.apache.aries.application.utils</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.aries.subsystem.example</groupId>
+ <artifactId>org.apache.aries.subsystem.example.helloIsolation</artifactId>
+ <version>${version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>