aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1344727 [2/2] - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ subsystem-itests/src/test/java/org/apache/aries/subsyst...
Date Thu, 31 May 2012 14:00:58 GMT
Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceUninstaller.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceUninstaller.java?rev=1344727&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceUninstaller.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceUninstaller.java
Thu May 31 14:00:57 2012
@@ -0,0 +1,84 @@
+package org.apache.aries.subsystem.core.internal;
+
+import org.apache.aries.util.io.IOUtils;
+import org.osgi.resource.Resource;
+import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.Subsystem.State;
+import org.osgi.service.subsystem.SubsystemException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SubsystemResourceUninstaller extends ResourceUninstaller {
+	private static final Logger logger = LoggerFactory.getLogger(AriesSubsystem.class);
+	
+	private static void removeChild(AriesSubsystem parent, AriesSubsystem child) {
+		Activator.getInstance().getSubsystems().removeChild(parent, child);
+	}
+	
+	public SubsystemResourceUninstaller(Resource resource, AriesSubsystem subsystem) {
+		super(resource, subsystem);
+	}
+	
+	public void uninstall() {
+		if (isResourceUninstallable())
+			uninstallSubsystem();
+		removeReferences();
+		removeConstituents();
+		removeChildren();
+	}
+	
+	private void removeChildren() {
+		if (isImplicit()) {
+			removeChild((AriesSubsystem)subsystem, (AriesSubsystem)resource);
+			return;
+		}
+		for (Subsystem subsystem : ((AriesSubsystem)resource).getParents())
+			removeChild((AriesSubsystem)subsystem, (AriesSubsystem)resource);
+	}
+	
+	private void removeConstituents() {
+		if (isImplicit()) {
+			removeConstituent();
+			return;
+		}
+		for (Subsystem subsystem : ((AriesSubsystem)resource).getParents())
+			removeConstituent((AriesSubsystem)subsystem, (AriesSubsystem)resource);
+	}
+	
+	private void removeReferences() {
+		if (isImplicit()) {
+			removeReference();
+			return;
+		}
+		for (Subsystem subsystem : ((AriesSubsystem)resource).getParents())
+			removeReference((AriesSubsystem)subsystem, (AriesSubsystem)resource);
+	}
+	
+	private void uninstallSubsystem() {
+		AriesSubsystem subsystem = (AriesSubsystem)resource;
+		if (subsystem.getState().equals(Subsystem.State.RESOLVED))
+				subsystem.setState(State.INSTALLED);
+			subsystem.setState(State.UNINSTALLING);
+			Throwable firstError = null;
+			for (Resource resource : Activator.getInstance().getSubsystems().getResourcesReferencedBy(subsystem))
{
+				// Don't uninstall the region context bundle here.
+				if (ResourceHelper.getSymbolicNameAttribute(resource).startsWith(RegionContextBundleHelper.SYMBOLICNAME_PREFIX))
+					continue;
+				try {
+					ResourceUninstaller.newInstance(resource, subsystem).uninstall();
+				}
+				catch (Throwable t) {
+					logger.error("An error occurred while uninstalling resource " + resource + " of subsystem
" + subsystem, t);
+					if (firstError == null)
+						firstError = t;
+				}
+			}
+			IOUtils.deleteRecursive(subsystem.getDirectory());
+			subsystem.setState(State.UNINSTALLED);
+			Activator.getInstance().getSubsystemServiceRegistrar().unregister(subsystem);
+			if (subsystem.isScoped())
+				RegionContextBundleHelper.uninstallRegionContextBundle(subsystem);
+			if (firstError != null)
+				throw new SubsystemException(firstError);
+	}
+}
\ No newline at end of file

Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Subsystems.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Subsystems.java?rev=1344727&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Subsystems.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Subsystems.java
Thu May 31 14:00:57 2012
@@ -0,0 +1,166 @@
+package org.apache.aries.subsystem.core.internal;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.osgi.resource.Resource;
+import org.osgi.service.subsystem.Subsystem;
+
+public class Subsystems {
+	private final SubsystemGraph graph;
+	private final Map<Long, AriesSubsystem> idToSubsystem = new HashMap<Long, AriesSubsystem>();
+	private final Map<String, AriesSubsystem> locationToSubsystem = new HashMap<String,
AriesSubsystem>();
+	private final ResourceReferences resourceReferences = new ResourceReferences();
+	private final AriesSubsystem root;
+	private final Map<AriesSubsystem, Set<Resource>> subsystemToConstituents = new
HashMap<AriesSubsystem, Set<Resource>>();
+	
+	public Subsystems() throws Exception {
+		root = new AriesSubsystem();
+		graph = new SubsystemGraph(root);
+	}
+	
+	public void addChild(AriesSubsystem parent, AriesSubsystem child) {
+		graph.add(parent, child);
+	}
+	
+	public void addConstituent(AriesSubsystem subsystem, Resource constituent) {
+		synchronized (subsystemToConstituents) {
+			Set<Resource> constituents = subsystemToConstituents.get(subsystem);
+			if (constituents == null) {
+				constituents = new HashSet<Resource>();
+				subsystemToConstituents.put(subsystem, constituents);
+			}
+			if (!constituents.add(constituent))
+				throw new IllegalArgumentException("Constituent already exists");
+		}
+	}
+	
+	public void addReference(AriesSubsystem subsystem, Resource resource) {
+		resourceReferences.addReference(subsystem, resource);
+	}
+	
+	public void addSubsystem(AriesSubsystem subsystem) {
+		synchronized (idToSubsystem) {
+			synchronized (locationToSubsystem) {
+				addIdToSubsystem(subsystem);
+				addLocationToSubsystem(subsystem);
+			}
+		}
+	}
+	
+	public Collection<Subsystem> getChildren(AriesSubsystem parent) {
+		return graph.getChildren(parent);
+	}
+	
+	public Collection<Resource> getConstituents(AriesSubsystem subsystem) {
+		synchronized (subsystemToConstituents) {
+			Collection<Resource> result = subsystemToConstituents.get(subsystem);
+			if (result == null)
+				return Collections.emptyList();
+			return Collections.unmodifiableCollection(result);
+		}
+	}
+	
+	public Collection<Subsystem> getParents(AriesSubsystem child) {
+		return graph.getParents(child);
+	}
+	
+	public Collection<Resource> getResourcesReferencedBy(AriesSubsystem subsystem) {
+		return resourceReferences.getResources(subsystem);
+	}
+	
+	public AriesSubsystem getRootSubsystem() {
+		return root;
+	}
+	
+	public AriesSubsystem getSubsystemById(long id) {
+		synchronized (idToSubsystem) {
+			return idToSubsystem.get(id);
+		}
+	}
+	
+	public AriesSubsystem getSubsystemByLocation(String location) {
+		synchronized (locationToSubsystem) {
+			return locationToSubsystem.get(location);
+		}
+	}
+	
+	public Collection<AriesSubsystem> getSubsystems() {
+		return new ArrayList<AriesSubsystem>(idToSubsystem.values());
+	}
+	
+	public Collection<AriesSubsystem> getSubsystemsByConstituent(Resource constituent)
{
+		ArrayList<AriesSubsystem> result = new ArrayList<AriesSubsystem>();
+		synchronized (subsystemToConstituents) {
+			for (AriesSubsystem subsystem : subsystemToConstituents.keySet())
+				if (subsystem.contains(constituent))
+					result.add(subsystem);
+		}
+		result.trimToSize();
+		return result;
+	}
+	
+	public Collection<AriesSubsystem> getSubsystemsReferencing(Resource resource) {
+		return resourceReferences.getSubsystems(resource);
+	}
+	
+	public void removeChild(AriesSubsystem child) {
+		graph.remove(child);
+	}
+	
+	public void removeChild(AriesSubsystem parent, AriesSubsystem child) {
+		graph.remove(parent, child);
+	}
+	
+	public void removeConstituent(AriesSubsystem subsystem, Resource constituent) {
+		synchronized (subsystemToConstituents) {
+			Set<Resource> constituents = subsystemToConstituents.get(subsystem);
+			if (!constituents.remove(constituent))
+				throw new IllegalArgumentException("Constituent does not exist");
+		}
+	}
+	
+	public void removeReference(AriesSubsystem subsystem, Resource resource) {
+		resourceReferences.removeReference(subsystem, resource);
+	}
+	
+	public void removeSubsystem(AriesSubsystem subsystem) {
+		synchronized (idToSubsystem) {
+			synchronized (locationToSubsystem) {
+				removeLocationToSubsystem(subsystem);
+				removeIdToSubsystem(subsystem);
+			}
+		}
+	}
+	
+	private void addIdToSubsystem(AriesSubsystem subsystem) {
+		long id = subsystem.getSubsystemId();
+		if (idToSubsystem.containsKey(id))
+			throw new IllegalArgumentException("Subsystem ID already exists: " + id);
+		idToSubsystem.put(id, subsystem);
+	}
+	
+	private void addLocationToSubsystem(AriesSubsystem subsystem) {
+		String location = subsystem.getLocation();
+		if (locationToSubsystem.containsKey(location))
+			throw new IllegalArgumentException("Subsystem location already exists: " + location);
+		locationToSubsystem.put(location, subsystem);
+	}
+	
+	private void removeIdToSubsystem(AriesSubsystem subsystem) {
+		long id = subsystem.getSubsystemId();
+		if (idToSubsystem.remove(id) == null)
+			throw new IllegalArgumentException("Subsystem ID does not exist: " + id);
+	}
+	
+	private void removeLocationToSubsystem(AriesSubsystem subsystem) {
+		String location = subsystem.getLocation();
+		if (locationToSubsystem.remove(location) == null)
+			throw new IllegalArgumentException("Subsystem location does not exist: " + location);
+	}
+}

Added: 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=1344727&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
Thu May 31 14:00:57 2012
@@ -0,0 +1,21 @@
+package org.apache.aries.subsystem.core.internal;
+
+import org.osgi.service.coordinator.Coordination;
+
+public class Utils {
+	public static Coordination createCoordination(AriesSubsystem subsystem) {
+		return Activator.getInstance().getCoordinator().create(subsystem.getSymbolicName() + '-'
+ subsystem.getSubsystemId(), 0);
+	}
+	
+	public static AriesSubsystem findFirstSubsystemAcceptingDependenciesStartingFrom(AriesSubsystem
subsystem) {
+		// The following loop is guaranteed to end once the root subsystem has
+		// been reached.
+		while (!isAcceptDependencies(subsystem))
+			subsystem = (AriesSubsystem)subsystem.getParents().iterator().next();
+		return subsystem;
+	}
+	
+	public static boolean isAcceptDependencies(AriesSubsystem subsystem) {
+		return subsystem.getArchive().getSubsystemManifest().getSubsystemTypeHeader().getProvisionPolicyDirective().isAcceptDependencies();
+	}
+}

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java?rev=1344727&r1=1344726&r2=1344727&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
Thu May 31 14:00:57 2012
@@ -716,8 +716,10 @@ public abstract class SubsystemTest exte
 		if (subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION)
 				|| subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE))
 			b = getRegionContextBundle(subsystem);
+		State state = subsystem.getState();
 		subsystem.uninstall();
-		assertEvent(subsystem, State.INSTALLED, 5000);
+		if (!EnumSet.of(State.INSTALL_FAILED, State.INSTALLED, State.INSTALLING).contains(state))
+			assertEvent(subsystem, State.INSTALLED, 5000);
 		assertEvent(subsystem, State.UNINSTALLING, 5000);
 		assertEvent(subsystem, State.UNINSTALLED, 5000);
 		assertState(State.UNINSTALLED, subsystem);



Mime
View raw message