aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1702099 - in /aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal: BundleEventHook.java BundleRevisionResource.java
Date Wed, 09 Sep 2015 20:05:50 GMT
Author: jwross
Date: Wed Sep  9 20:05:50 2015
New Revision: 1702099

URL: http://svn.apache.org/r1702099
Log:
ARIES-1399 Trunk fails OSGi R6 CT

Lazily compute service dependencies and requirements in bundle revision resource.

Use already cached activator variable in bundle event hook.

Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleEventHook.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleRevisionResource.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleEventHook.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleEventHook.java?rev=1702099&r1=1702098&r2=1702099&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleEventHook.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleEventHook.java
Wed Sep  9 20:05:50 2015
@@ -175,14 +175,14 @@ public class BundleEventHook implements
 		Collection<BasicSubsystem> subsystems;
 		if (revision == null) {
 			// The bundle was installed while the bundle event hook was unregistered.
-			Object[] o = Activator.getInstance().getSubsystems().getSubsystemsByBundle(bundle);
+			Object[] o = activator.getSubsystems().getSubsystemsByBundle(bundle);
 			if (o == null)
 				return;
 			revision = (BundleRevision)o[0];
 			subsystems = (Collection<BasicSubsystem>)o[1];
 		}
 		else
-			subsystems = Activator.getInstance().getSubsystems().getSubsystemsByConstituent(new BundleConstituent(null,
revision));
+			subsystems = activator.getSubsystems().getSubsystemsByConstituent(new BundleConstituent(null,
revision));
 		for (BasicSubsystem subsystem : subsystems)
 			ResourceUninstaller.newInstance(revision, subsystem).uninstall();
 	}

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=1702099&r1=1702098&r2=1702099&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  9 20:05:50 2015
@@ -25,49 +25,21 @@ import org.osgi.resource.Resource;
 
 public class BundleRevisionResource implements Resource {
 	private final BundleRevision revision;
-	private final List<Capability> serviceCapabilities;
-	private final List<Requirement> serviceRequirements;
 
 	public BundleRevisionResource(BundleRevision revision) {
 		if (revision == null)
 			throw new NullPointerException();
 		this.revision = revision;
-		ServiceModeller.ServiceModel model = null;
-		boolean gotModel = false;
-        List<Capability> capabilities = revision.getCapabilities(ServiceNamespace.SERVICE_NAMESPACE);
-        // OSGi RFC 201 for R6: The presence of any Provide-Capability clauses
-        // in the osgi.service namespace overrides any service related
-        // capabilities that might have been found by other means.
-        if (capabilities.isEmpty()) {
-            model = getModel();
-            gotModel = true;
-            if (model != null) {
-                capabilities = model.getServiceCapabilities();
-            }
-        }
-        serviceCapabilities = capabilities;
-        List<Requirement> requirements = revision.getRequirements(ServiceNamespace.SERVICE_NAMESPACE);
-        // OSGi RFC 201 for R6: The presence of any Require-Capability clauses
-        // in the osgi.service namespace overrides any service related
-        // requirements that might have been found by other means.
-        if (requirements.isEmpty()) {
-            if (model == null && !gotModel) {
-                model = getModel();
-            }
-            if (model != null) {
-                requirements = model.getServiceRequirements();
-            }
-        }
-        serviceRequirements = requirements;
 	}
 
 	@Override
 	public List<Capability> getCapabilities(String namespace) {
 	    if (ServiceNamespace.SERVICE_NAMESPACE.equals(namespace)) {
-	        return Collections.unmodifiableList(serviceCapabilities);
+	        return Collections.unmodifiableList(getServiceCapabilities());
 	    }
 	    List<Capability> revisionCapabilities = revision.getCapabilities(namespace);
 	    if (namespace == null) {
+	    	List<Capability> serviceCapabilities = getServiceCapabilities();
 	        List<Capability> result = new ArrayList<Capability>(revisionCapabilities.size()
+ serviceCapabilities.size());
 	        result.addAll(revisionCapabilities);
 	        result.addAll(serviceCapabilities);
@@ -79,10 +51,11 @@ public class BundleRevisionResource impl
 	@Override
 	public List<Requirement> getRequirements(String namespace) {
 	    if (ServiceNamespace.SERVICE_NAMESPACE.equals(namespace)) {
-	        return Collections.unmodifiableList(serviceRequirements);
+	        return Collections.unmodifiableList(getServiceRequirements());
 	    }
 	    List<Requirement> revisionRequirements = revision.getRequirements(namespace);
 	    if (namespace == null) {
+	    	List<Requirement> serviceRequirements = getServiceRequirements();
 	        List<Requirement> result = new ArrayList<Requirement>(revisionRequirements.size()
+ serviceRequirements.size());
             result.addAll(revisionRequirements);
             result.addAll(serviceRequirements);
@@ -105,4 +78,53 @@ public class BundleRevisionResource impl
                 new BundleDirectory(revision.getBundle()));
 	    return model;
 	}
+	
+	private boolean initialized;
+	private List<Capability> serviceCapabilities;
+	private List<Requirement> serviceRequirements;
+	
+	private synchronized void computeServiceCapabilitiesAndRequirements() {
+		ServiceModeller.ServiceModel model = null;
+		boolean gotModel = false;
+        List<Capability> capabilities = revision.getCapabilities(ServiceNamespace.SERVICE_NAMESPACE);
+        // OSGi RFC 201 for R6: The presence of any Provide-Capability clauses
+        // in the osgi.service namespace overrides any service related
+        // capabilities that might have been found by other means.
+        if (capabilities.isEmpty()) {
+            model = getModel();
+            gotModel = true;
+            if (model != null) {
+                capabilities = model.getServiceCapabilities();
+            }
+        }
+        serviceCapabilities = capabilities;
+        List<Requirement> requirements = revision.getRequirements(ServiceNamespace.SERVICE_NAMESPACE);
+        // OSGi RFC 201 for R6: The presence of any Require-Capability clauses
+        // in the osgi.service namespace overrides any service related
+        // requirements that might have been found by other means.
+        if (requirements.isEmpty()) {
+            if (model == null && !gotModel) {
+                model = getModel();
+            }
+            if (model != null) {
+                requirements = model.getServiceRequirements();
+            }
+        }
+        serviceRequirements = requirements;
+		initialized = true;
+	}
+	
+	private synchronized List<Capability> getServiceCapabilities() {
+		if (!initialized) {
+			computeServiceCapabilitiesAndRequirements();
+		}
+		return serviceCapabilities;
+	}
+	
+	private synchronized List<Requirement> getServiceRequirements() {
+		if (!initialized) {
+			computeServiceCapabilitiesAndRequirements();
+		}
+		return serviceRequirements;
+	}
 }



Mime
View raw message