You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jw...@apache.org on 2015/09/02 17:26:45 UTC

svn commit: r1700842 [3/3] - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/capabilityset/ subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ subsystem-itests/src/test/java/org/apache/aries/s...

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java?rev=1700842&r1=1700841&r2=1700842&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java Wed Sep  2 15:26:45 2015
@@ -57,24 +57,24 @@ public class Activator implements Bundle
             throw new IllegalStateException("The activator has not been initialized or has been shutdown");
 		return result;
 	}
-
-	// @GuardedBy("this")
-	private BundleEventHook bundleEventHook;
+	
 	private volatile BundleContext bundleContext;
     private volatile ConfigAdminContentHandler configAdminHandler;
 	private volatile Coordinator coordinator;
     private volatile Object modelledResourceManager;
-    private volatile ServiceModeller serviceModeller;
+    private volatile RegionDigraph regionDigraph;
 	private volatile SubsystemServiceRegistrar registrar;
-	private volatile RegionDigraph regionDigraph;
 	private volatile Resolver resolver;
-	private ServiceTracker<?,?> serviceTracker;
-
+	private volatile ServiceModeller serviceModeller;
 	private volatile Subsystems subsystems;
+	private volatile SystemRepositoryManager systemRepositoryManager;
+	
+	private BundleEventHook bundleEventHook;
+	private ServiceTracker<?,?> serviceTracker;
 
-	private final Collection<ServiceRegistration<?>> registrations = new HashSet<ServiceRegistration<?>>();
 	private final Collection<IDirectoryFinder> finders = Collections.synchronizedSet(new HashSet<IDirectoryFinder>());
-
+	private final Collection<ServiceRegistration<?>> registrations = new HashSet<ServiceRegistration<?>>();
+	
 	public BundleContext getBundleContext() {
 		return bundleContext;
 	}
@@ -110,8 +110,8 @@ public class Activator implements Bundle
 		return result;
 	}
 
-	public org.apache.aries.subsystem.core.repository.Repository getSystemRepository() {
-		return new SystemRepository(getSubsystems().getRootSubsystem());
+	public SystemRepository getSystemRepository() {
+		return systemRepositoryManager.getSystemRepository();
 	}
 
 	@Override
@@ -146,6 +146,8 @@ public class Activator implements Bundle
         configAdminHandler = new ConfigAdminContentHandler(bundleContext);
         registrations.add(bundleContext.registerService(ContentHandler.class, configAdminHandler, handlerProps));
 		registrar = new SubsystemServiceRegistrar(bundleContext);
+		systemRepositoryManager = new SystemRepositoryManager(bundleContext.getBundle(0).getBundleContext());
+        systemRepositoryManager.open();
 		BasicSubsystem root = subsystems.getRootSubsystem();
 		bundleEventHook.activate();
 		root.start();
@@ -156,6 +158,7 @@ public class Activator implements Bundle
 		if (!isActive())
 			return;
 		bundleEventHook.deactivate();
+		systemRepositoryManager.close();
 		new StopAction(subsystems.getRootSubsystem(), subsystems.getRootSubsystem(), true).run();
 		for (ServiceRegistration<?> registration : registrations) {
 			try {

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java?rev=1700842&r1=1700841&r2=1700842&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java Wed Sep  2 15:26:45 2015
@@ -170,8 +170,12 @@ public class BundleResourceInstaller ext
 	
 	public Resource install() {
 		BundleRevision revision;
-		if (resource instanceof BundleRevision)
+		if (resource instanceof BundleRevision) {
 			revision = (BundleRevision)resource;
+		}
+		else if (resource instanceof BundleRevisionResource) {
+		    revision = ((BundleRevisionResource)resource).getRevision();
+		}
 		else {
 			ThreadLocalSubsystem.set(provisionTo);
 			try {

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleRevisionResource.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleRevisionResource.java?rev=1700842&r1=1700841&r2=1700842&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleRevisionResource.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleRevisionResource.java Wed Sep  2 15:26:45 2015
@@ -91,6 +91,10 @@ public class BundleRevisionResource impl
 	    return revisionRequirements;
 	}
 	
+	public BundleRevision getRevision() {
+	    return revision;
+	}
+	
 	private ServiceModeller.ServiceModel getModel() {
 	    Activator activator = Activator.getInstance();
 	    ServiceModeller modeller = activator.getServiceModeller();

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResolveContext.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResolveContext.java?rev=1700842&r1=1700841&r2=1700842&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResolveContext.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResolveContext.java Wed Sep  2 15:26:45 2015
@@ -211,11 +211,13 @@ public class ResolveContext extends org.
 		}
 		else {
 			// This is an already installed resource from the system repository.
-			if (Utils.isBundle(resource))
+			if (Utils.isBundle(resource)) {
+			    BundleRevision revision = resource instanceof BundleRevision ? (BundleRevision)resource : ((BundleRevisionResource)resource).getRevision();
 				// If it's a bundle, use region digraph to get the region in order
 				// to account for bundles in isolated regions outside of the
 				// subsystems API.
-				return Activator.getInstance().getRegionDigraph().getRegion(((BundleRevision)resource).getBundle());
+				return Activator.getInstance().getRegionDigraph().getRegion(revision.getBundle());
+			}
 			else
 				// If it's anything else, get the region from one of the
 				// subsystems referencing it.

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResolverHook.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResolverHook.java?rev=1700842&r1=1700841&r2=1700842&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResolverHook.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResolverHook.java Wed Sep  2 15:26:45 2015
@@ -71,6 +71,12 @@ public class SubsystemResolverHook imple
 					// Don't want to filter out the region context bundle.
 					continue;
 				Collection<BasicSubsystem> subsystems = this.subsystems.getSubsystemsReferencing(revision);
+				if (subsystems.isEmpty()) {
+				    // This is the revision of a bundle being installed as part of a subsystem installation
+				    // before it has been added as a reference or constituent.
+				    iterator.remove();
+				    continue;
+				}
 				for (BasicSubsystem subsystem : subsystems) {
 					if (subsystem.isFeature()) {
 						// Feature subsystems require no isolation.

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SystemRepository.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SystemRepository.java?rev=1700842&r1=1700841&r2=1700842&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SystemRepository.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SystemRepository.java Wed Sep  2 15:26:45 2015
@@ -1,78 +1,99 @@
 /*
- * 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
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
  *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *   http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  */
 package org.apache.aries.subsystem.core.internal;
 
 import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
 
+import org.apache.aries.subsystem.AriesSubsystem;
+import org.apache.aries.subsystem.core.capabilityset.CapabilitySetRepository;
+import org.apache.aries.subsystem.core.repository.Repository;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.resource.Capability;
 import org.osgi.resource.Requirement;
-import org.osgi.resource.Resource;
+import org.osgi.util.tracker.BundleTrackerCustomizer;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
-public class SystemRepository implements org.apache.aries.subsystem.core.repository.Repository {
-	private final BasicSubsystem root;
-	
-	public SystemRepository(BasicSubsystem root) {
-		this.root = root;
-	}
-
-	@Override
-	public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
-		Map<Requirement, Collection<Capability>> result = new HashMap<Requirement, Collection<Capability>>();
-		for (Requirement requirement : requirements)
-			result.put(requirement, findProviders(requirement));
-		return result;
-	}
-	
-	public Collection<Capability> findProviders(Requirement requirement) {
-		Collection<Capability> result = new HashSet<Capability>();
-		findProviders(requirement, result, root, new HashSet<Resource>());
-		return result;
-	}
-	
-	private void findProviders(
-	        Requirement requirement, 
-	        Collection<Capability> capabilities, 
-	        BasicSubsystem subsystem,
-	        Set<Resource> processedResources) {
-		// Need to examine capabilities offered by the subsystem itself.
-		// For example, the requirement might be an osgi.identity
-		// requirement for a preferred provider that's a subsystem.
-		for (Capability capability : subsystem.getCapabilities(requirement.getNamespace())) {
-			if (ResourceHelper.matches(requirement, capability)) {
-				capabilities.add(capability);
-			}
-		}
-		for (Resource constituent : subsystem.getConstituents()) {
-		    if (processedResources.contains(constituent)) {
-		        continue;
-		    }
-		    processedResources.add(constituent);
-			if (constituent instanceof BasicSubsystem) {
-				findProviders(requirement, capabilities, (BasicSubsystem)constituent, processedResources);
-			}
-			else {
-				for (Capability capability : constituent.getCapabilities(requirement.getNamespace())) {
-					if (ResourceHelper.matches(requirement, capability)) {
-						capabilities.add(capability);
-					}
-				}
-				processedResources.add(constituent);
-			}
-		}
-	}
+public class SystemRepository 
+        implements 
+                Repository,
+                BundleTrackerCustomizer<AtomicReference<BundleRevisionResource>>,
+                ServiceTrackerCustomizer<AriesSubsystem, BasicSubsystem> {
+    
+    private final BundleContext bundleContext;
+    private final CapabilitySetRepository repository;
+
+    public SystemRepository(BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
+        repository = new CapabilitySetRepository();
+    }
+
+    @Override
+    public AtomicReference<BundleRevisionResource> addingBundle(Bundle bundle, BundleEvent event) {
+        // The state mask must guarantee this will only be called when the bundle is in the INSTALLED state.
+        BundleRevision revision = bundle.adapt(BundleRevision.class);
+        BundleRevisionResource resource = new BundleRevisionResource(revision);
+        repository.addResource(resource);
+        return new AtomicReference<BundleRevisionResource>(resource);
+    }
+
+    @Override
+    public BasicSubsystem addingService(ServiceReference<AriesSubsystem> reference) {
+        // Intentionally letting the ClassCastException propagate. Everything received should be a BasicSubsystem.
+        BasicSubsystem subsystem = (BasicSubsystem)bundleContext.getService(reference);
+        repository.addResource(subsystem);
+        return subsystem;
+    }
+
+    @Override
+    public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
+        return repository.findProviders(requirements);
+    }
+
+    @Override
+    public void modifiedBundle(Bundle bundle, BundleEvent event, AtomicReference<BundleRevisionResource> object) {
+        if (BundleEvent.UPDATED == event.getType()) {
+            BundleRevision revision = bundle.adapt(BundleRevision.class);
+            BundleRevisionResource resource = new BundleRevisionResource(revision);
+            repository.removeResource(object.getAndSet(resource));
+            repository.addResource(resource);
+        }
+    }
+
+    @Override
+    public void modifiedService(ServiceReference<AriesSubsystem> reference, BasicSubsystem service) {
+        // Nothing.
+    }
+
+    @Override
+    public void removedBundle(Bundle bundle, BundleEvent event, AtomicReference<BundleRevisionResource> object) {
+        // The state mask must guarantee this will only be called when the bundle is in the UNINSTALLED state.
+        repository.removeResource(object.get());
+    }
+
+    @Override
+    public void removedService(ServiceReference<AriesSubsystem> reference, BasicSubsystem service) {
+        repository.removeResource(service);
+    }
 }

Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SystemRepositoryManager.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SystemRepositoryManager.java?rev=1700842&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SystemRepositoryManager.java (added)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SystemRepositoryManager.java Wed Sep  2 15:26:45 2015
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.subsystem.core.internal;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.aries.subsystem.AriesSubsystem;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.SubsystemConstants;
+import org.osgi.util.tracker.BundleTracker;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class SystemRepositoryManager {
+    private static final Filter filter = createFilter();
+    
+    private static Filter createFilter() {
+        try {
+            return FrameworkUtil.createFilter(new StringBuilder()
+                    .append("(&(!(|(")
+                    .append(SubsystemConstants.SUBSYSTEM_STATE_PROPERTY)
+                    .append('=')
+                    .append(Subsystem.State.INSTALL_FAILED)
+                    .append(")(")
+                    .append(SubsystemConstants.SUBSYSTEM_STATE_PROPERTY)
+                    .append('=')
+                    .append(Subsystem.State.UNINSTALLING)
+                    .append(")(")
+                    .append(SubsystemConstants.SUBSYSTEM_STATE_PROPERTY)
+                    .append('=')
+                    .append(Subsystem.State.UNINSTALLED)
+                    .append(")))(")
+                    .append(org.osgi.framework.Constants.OBJECTCLASS)
+                    .append('=')
+                    .append(AriesSubsystem.class.getName())
+                    .append("))")
+                    .toString());
+        } 
+        catch (InvalidSyntaxException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+    
+    private final BundleTracker<AtomicReference<BundleRevisionResource>> bundleTracker;
+    private final ServiceTracker<AriesSubsystem, BasicSubsystem> serviceTracker;
+    private final SystemRepository systemRepository;
+    
+    public SystemRepositoryManager(BundleContext bundleContext) {
+        systemRepository = new SystemRepository(bundleContext);
+        bundleTracker = new BundleTracker<AtomicReference<BundleRevisionResource>>(
+                bundleContext, ~Bundle.UNINSTALLED, systemRepository);
+        serviceTracker = new ServiceTracker<AriesSubsystem, BasicSubsystem>(
+                bundleContext, filter, systemRepository);
+    }
+    
+    public SystemRepository getSystemRepository() {
+        return systemRepository;
+    }
+
+    public void open() {
+        bundleTracker.open();
+        serviceTracker.open();
+    }
+    
+    public void close() {
+        serviceTracker.close();
+        bundleTracker.close();
+    }
+}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java?rev=1700842&r1=1700841&r2=1700842&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java Wed Sep  2 15:26:45 2015
@@ -137,7 +137,7 @@ public class Utils {
 	}
 	
 	public static boolean isSharedResource(Resource resource) {
-		return resource instanceof BasicSubsystem || resource instanceof BundleRevision;
+		return resource instanceof BasicSubsystem || resource instanceof BundleRevision || resource instanceof BundleRevisionResource;
 	}
 	
 	public static boolean isSubsystem(Resource resource) {

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java?rev=1700842&r1=1700841&r2=1700842&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java Wed Sep  2 15:26:45 2015
@@ -14,6 +14,7 @@
 package org.apache.aries.subsystem.itests;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.File;
@@ -73,7 +74,7 @@ public class RootSubsystemTest extends S
 		getSubsystemCoreBundle().stop();
 		getSubsystemCoreBundle().start();
 		Bundle bundleA = context().getBundleByName(BUNDLE_A);
-		assertEquals("Extraneous root region bundle should not be started", Bundle.INSTALLED, bundleA.getState());
+		assertTrue("Extraneous root region bundle should not be started", (bundleA.getState() & (Bundle.INSTALLED | Bundle.RESOLVED)) != 0);
 	}
 	
 	@Test