You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2007/07/04 13:02:10 UTC
svn commit: r553167 - in
/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi:
invocation/ xml/
Author: antelder
Date: Wed Jul 4 04:02:09 2007
New Revision: 553167
URL: http://svn.apache.org/viewvc?view=rev&rev=553167
Log:
TUSCANY-1409, apply patch from Rajini Sivaram making osgi mpl thread-safe, and support @EagerInit
Modified:
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiInstanceWrapper.java
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
Modified: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java?view=diff&rev=553167&r1=553166&r2=553167
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java Wed Jul 4 04:02:09 2007
@@ -98,6 +98,7 @@
private RuntimeComponent runtimeComponent;
private Bundle osgiBundle;
+ private ArrayList<Bundle> dependentBundles = new ArrayList<Bundle>();
private OSGiServiceListener osgiServiceListener;
private PackageAdmin packageAdmin;
@@ -123,23 +124,14 @@
// Install and start all dependent bundles
String[] imports = implementation.getImports();
- ArrayList<Bundle>bundles = new ArrayList<Bundle>();
for (int i = 0; i < imports.length; i++) {
String location = imports[i].trim();
if (location.length() > 0) {
Bundle bundle = bundleContext.installBundle(location);
- bundles.add(bundle);
+ dependentBundles.add(bundle);
}
}
- for (int i = 0; i < bundles.size(); i++) {
- Bundle bundle = bundles.get(i);
- try {
- bundle.start();
- } catch (BundleException e) {
- if (bundle.getHeaders().get("Fragment-Host") == null)
- throw e;
- }
- }
+
// PackageAdmin is used to resolve bundles
org.osgi.framework.ServiceReference packageAdminReference =
@@ -332,6 +324,17 @@
configurePropertiesUsingConfigAdmin();
resolveBundle();
+
+ for (Bundle bundle : dependentBundles) {
+ try {
+ if (bundle.getState() != Bundle.ACTIVE && bundle.getState() != Bundle.STARTING) {
+ bundle.start();
+ }
+ } catch (BundleException e) {
+ if (bundle.getHeaders().get("Fragment-Host") == null)
+ throw e;
+ }
+ }
if (osgiBundle.getState() != Bundle.ACTIVE && osgiBundle.getState() != Bundle.STARTING) {
@@ -362,7 +365,7 @@
protected org.osgi.framework.ServiceReference getOSGiServiceReference(
- RuntimeComponentService service)
+ ComponentService service)
throws ObjectCreationException {
try {
Modified: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiInstanceWrapper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiInstanceWrapper.java?view=diff&rev=553167&r1=553166&r2=553167
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiInstanceWrapper.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiInstanceWrapper.java Wed Jul 4 04:02:09 2007
@@ -20,10 +20,13 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.util.Hashtable;
+import java.util.List;
import java.util.Random;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
-import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.scope.InstanceWrapper;
import org.apache.tuscany.sca.scope.Scope;
import org.apache.tuscany.sca.scope.TargetDestructionException;
@@ -47,10 +50,8 @@
private OSGiImplementationProvider provider;
private BundleContext bundleContext;
- private T osgiInstance;
- private ServiceReference osgiServiceReference;
- private Bundle dummyBundle;
- private BundleContext refBundleContext;
+ private Hashtable<ComponentService,InstanceInfo<T>> instanceInfoList =
+ new Hashtable<ComponentService,InstanceInfo<T>>();
public OSGiInstanceWrapper(OSGiImplementationProvider provider,
BundleContext bundleContext) {
@@ -59,22 +60,28 @@
this.bundleContext = bundleContext;
}
- public T getInstance(RuntimeComponentService service) throws TargetInitializationException {
+ public synchronized T getInstance(ComponentService service) throws TargetInitializationException {
+
+ if (instanceInfoList.get(service) != null)
+ return instanceInfoList.get(service).osgiInstance;
Bundle refBundle = provider.startBundle();
- if (provider.getImplementation().getScope() != Scope.COMPOSITE) {
+ if (!provider.getImplementation().getScope().equals(Scope.COMPOSITE)) {
refBundle = getDummyReferenceBundle();
}
+
+ InstanceInfo<T> instanceInfo = new InstanceInfo<T>();
+ instanceInfoList.put(service, instanceInfo);
- osgiServiceReference = provider.getOSGiServiceReference(service);
+ instanceInfo.osgiServiceReference = provider.getOSGiServiceReference(service);
- refBundleContext = refBundle.getBundleContext();
- osgiInstance = (T)refBundleContext.getService(osgiServiceReference);
+ instanceInfo.refBundleContext = refBundle.getBundleContext();
+ instanceInfo.osgiInstance = (T)instanceInfo.refBundleContext.getService(instanceInfo.osgiServiceReference);
- provider.injectProperties(osgiInstance);
+ provider.injectProperties(instanceInfo.osgiInstance);
- return osgiInstance;
+ return instanceInfo.osgiInstance;
}
// This method is provided purely to implement InstanceWrapper interface, and is never called.
@@ -84,29 +91,40 @@
}
public void start() throws TargetInitializationException {
-
+
+ if (provider.isEagerInit()) {
+ List<ComponentService> services = provider.getRuntimeComponent().getServices();
+ for (ComponentService service : services) {
+ getInstance(service);
+ }
+ }
}
- public void stop() throws TargetDestructionException {
- if (osgiInstance != null && osgiServiceReference != null) {
-
- refBundleContext.ungetService(osgiServiceReference);
+ public synchronized void stop() throws TargetDestructionException {
+
+ for (InstanceInfo<T> instanceInfo : instanceInfoList.values()) {
+ if (instanceInfo.osgiInstance != null && instanceInfo.osgiServiceReference != null) {
- osgiInstance = null;
- osgiServiceReference = null;
+ instanceInfo.refBundleContext.ungetService(instanceInfo.osgiServiceReference);
- try {
- if (dummyBundle != null) {
- dummyBundle.uninstall();
- }
- } catch (Exception e) {
- throw new TargetDestructionException(e);
- }
+ instanceInfo.osgiInstance = null;
+ instanceInfo.osgiServiceReference = null;
+
+ try {
+ if (instanceInfo.dummyBundle != null) {
+ instanceInfo.dummyBundle.uninstall();
+ }
+ } catch (Exception e) {
+ throw new TargetDestructionException(e);
+ }
+ }
}
+ instanceInfoList.clear();
}
private Bundle getDummyReferenceBundle() throws TargetInitializationException {
+ Bundle dummyBundle = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
String EOL = System.getProperty("line.separator");
@@ -148,6 +166,14 @@
return dummyBundle;
+ }
+
+ private static class InstanceInfo<T> {
+ private T osgiInstance;
+ private ServiceReference osgiServiceReference;
+ private Bundle dummyBundle;
+ private BundleContext refBundleContext;
+
}
}
Modified: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java?view=diff&rev=553167&r1=553166&r2=553167
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java Wed Jul 4 04:02:09 2007
@@ -24,8 +24,6 @@
import java.util.List;
import org.apache.tuscany.sca.assembly.ComponentProperty;
-import org.apache.tuscany.sca.assembly.ComponentType;
-import org.apache.tuscany.sca.assembly.Implementation;
import org.apache.tuscany.sca.assembly.impl.ComponentTypeImpl;
import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationInterface;
import org.apache.tuscany.sca.scope.Scope;
@@ -42,6 +40,7 @@
private String bundleLocation;
private String[] imports;
private Scope scope;
+ private boolean isEagerInit;
private String[] allowsPassByRef;
private boolean needsPropertyInjection;
private Hashtable<String, List<ComponentProperty>> referenceProperties;
@@ -52,6 +51,7 @@
String bundleLocation,
String[] imports,
String scopeName,
+ boolean isEagerInit,
String[] allowsPassByRef,
Hashtable<String, List<ComponentProperty>> refProperties,
Hashtable<String, List<ComponentProperty>> serviceProperties,
@@ -62,6 +62,7 @@
this.bundleLocation = bundleLocation;
this.imports = imports;
this.scope = new Scope(scopeName == null?"COMPOSITE":scopeName);
+ this.isEagerInit = isEagerInit;
this.allowsPassByRef = allowsPassByRef;
this.referenceProperties = refProperties;
this.serviceProperties = serviceProperties;
@@ -119,7 +120,7 @@
public boolean isEagerInit() {
- return false;
+ return isEagerInit;
}
public long getMaxAge() {
Modified: incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java?view=diff&rev=553167&r1=553166&r2=553167
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java Wed Jul 4 04:02:09 2007
@@ -77,9 +77,11 @@
private static final String BUNDLE = "bundle";
private static final String BUNDLE_LOCATION = "bundleLocation";
private static final String SCOPE = "scope";
+ private static final String EAGER_INIT = "eagerInit";
private static final String IMPORTS = "imports";
private static final String ALLOWS_PASS_BY_REF = "allowsPassByReference";
private static final String INJECT_PROPERTIES = "injectProperties";
+
private static final QName PROPERTIES_QNAME = new QName(SCA_NS, "properties");
private static final QName PROPERTY_QNAME = new QName(SCA_NS, "property");
@@ -145,6 +147,7 @@
allowsPassByRefList = new String[0];
boolean injectProperties = !"false".equalsIgnoreCase(reader.getAttributeValue(null, INJECT_PROPERTIES));
+ boolean eagerInit = "true".equalsIgnoreCase(reader.getAttributeValue(null, EAGER_INIT));
Hashtable<String, List<ComponentProperty>> refProperties =
@@ -181,11 +184,13 @@
bundleLocation,
importList,
scope,
+ eagerInit,
allowsPassByRefList,
refProperties,
serviceProperties,
injectProperties);
+
implementation.setUnresolved(true);
return implementation;
@@ -204,6 +209,7 @@
String bundleName = impl.getBundleName();
String ctURI = bundleName.replaceAll("\\.", "/") + ".componentType";
+
impl.setURI(ctURI);
ComponentType componentType = resolver.resolveModel(ComponentType.class, impl);
if (componentType.isUnresolved()) {
@@ -291,7 +297,7 @@
public void write(OSGiImplementation model, XMLStreamWriter outputSource) throws ContributionWriteException {
}
-
+
private QName getQNameValue(XMLStreamReader reader, String value) {
if (value != null) {
int index = value.indexOf(':');
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org