summaryrefslogtreecommitdiffstats
path: root/java/sca/modules
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-10-31 06:03:33 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-10-31 06:03:33 +0000
commit6971e1e526541f475e3a2adf5992f3486b4f6b70 (patch)
treeed9808246f85f9b20ec60d976acec00f179af050 /java/sca/modules
parentef25a099e9ea2064b9523ec33a15f114ee52ce45 (diff)
Resolve interfaces from the remote endpoints (tribes based discovery is now working)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@831516 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules')
-rw-r--r--java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java3
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java19
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java2
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java18
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java256
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java59
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java14
-rw-r--r--java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java4
8 files changed, 211 insertions, 164 deletions
diff --git a/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java b/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
index 1d0d0a1d99..ac2933564e 100644
--- a/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
+++ b/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
@@ -354,10 +354,11 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleLi
public void entryAdded(Object key, Object value) {
MapEntry entry = (MapEntry)value;
+ Endpoint newEp = (Endpoint)entry.getValue();
if (!isLocal(entry)) {
logger.info(id + " Remote endpoint added: " + entry.getValue());
+ newEp.setRemote(true);
}
- Endpoint newEp = (Endpoint)entry.getValue();
newEp.setExtensionPointRegistry(registry);
for (EndpointListener listener : listeners) {
listener.endpointAdded(newEp);
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
index 1cf17c6356..5744d7336f 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
+++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
@@ -97,8 +97,8 @@ public class OSGiImplementationProvider implements ImplementationProvider {
for (ComponentReference ref : component.getReferences()) {
RuntimeComponentReference reference = (RuntimeComponentReference)ref;
InterfaceContract interfaceContract = reference.getInterfaceContract();
- JavaInterface javaInterface = (JavaInterface)interfaceContract.getInterface();
- final Class<?> interfaceClass = javaInterface.getJavaClass();
+ final JavaInterface javaInterface = (JavaInterface)interfaceContract.getInterface();
+ // final Class<?> interfaceClass = javaInterface.getJavaClass();
// final Hashtable<String, Object> props = new Hashtable<String, Object>();
// props.put(FILTER_MATCH_CRITERIA, "");
@@ -113,14 +113,14 @@ public class OSGiImplementationProvider implements ImplementationProvider {
osgiProps.put(SERVICE_IMPORTED_CONFIGS, new String[] {REMOTE_CONFIG_SCA});
for (RuntimeWire wire : reference.getRuntimeWires()) {
- final OSGiServiceFactory serviceFactory = new OSGiServiceFactory(interfaceClass.getName(), wire);
+ final OSGiServiceFactory serviceFactory = new OSGiServiceFactory(javaInterface.getName(), wire);
ServiceRegistration registration =
AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>() {
public ServiceRegistration run() {
// Register the proxy as OSGi service
BundleContext context = osgiBundle.getBundleContext();
ServiceRegistration registration =
- context.registerService(interfaceClass.getName(), serviceFactory, osgiProps);
+ context.registerService(javaInterface.getName(), serviceFactory, osgiProps);
return registration;
}
});
@@ -130,6 +130,17 @@ public class OSGiImplementationProvider implements ImplementationProvider {
// Set the OSGi service reference properties into the SCA service
for (ComponentService service : component.getServices()) {
+ // The properties might have been set by the export service
+ boolean found = false;
+ for (Object ext : service.getExtensions()) {
+ if (ext instanceof OSGiProperty) {
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ continue;
+ }
ServiceReference serviceReference = getServiceReference(osgiBundle.getBundleContext(), service);
if (serviceReference != null) {
service.getExtensions().addAll(implementationFactory.createOSGiProperties(serviceReference));
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java
index 595547f9e7..84734b88db 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java
@@ -96,7 +96,7 @@ public class OSGiPropertyProcessor implements StAXArtifactProcessor<OSGiProperty
public void write(OSGiProperty model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
writer.writeStartElement(PROPERTY_QNAME.getNamespaceURI(), PROPERTY_QNAME.getLocalPart());
writer.writeAttribute(NAME, model.getName());
- writer.writeAttribute(TYPE, model.getName());
+ writer.writeAttribute(TYPE, model.getType());
writer.writeCharacters(model.getStringValue());
writer.writeEndElement();
}
diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java
index 748f835859..d50d1ef9f9 100644
--- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointHelper.java
@@ -23,7 +23,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
@@ -38,7 +37,6 @@ import org.osgi.framework.Constants;
* Implementation of {@link EndpointDescription}
*/
public class EndpointHelper {
- private final static String FRAMEWORK_UUID = "org.osgi.framework.uuid";
private EndpointHelper() {
}
@@ -56,7 +54,7 @@ public class EndpointHelper {
Map<String, Object> props = new HashMap<String, Object>();
if (!endpoint.isRemote()) {
- String uuid = getFrameworkUUID(bundleContext);
+ String uuid = OSGiHelper.getFrameworkUUID(bundleContext);
props.put(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID, uuid);
}
@@ -77,20 +75,6 @@ public class EndpointHelper {
return props;
}
- public synchronized static String getFrameworkUUID(BundleContext bundleContext) {
- String uuid = null;
- if (bundleContext != null) {
- uuid = bundleContext.getProperty(FRAMEWORK_UUID);
- } else {
- uuid = System.getProperty(FRAMEWORK_UUID);
- }
- if (uuid == null) {
- uuid = UUID.randomUUID().toString();
- }
- System.setProperty(FRAMEWORK_UUID, uuid);
- return uuid;
- }
-
public static Endpoint getEndpoint(EndpointDescription endpointDescription) {
return (Endpoint)endpointDescription.getProperties().get(Endpoint.class.getName());
}
diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
index c88632407c..a649dac357 100644
--- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/EndpointIntrospector.java
@@ -24,6 +24,7 @@ import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SCA_BINDIN
import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTENTS;
import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTENTS_EXTRA;
import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTERFACES;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper.getStringArray;
import static org.osgi.framework.Constants.OBJECTCLASS;
import static org.osgi.framework.Constants.SERVICE_ID;
@@ -55,17 +56,17 @@ import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
-import org.apache.tuscany.sca.deployment.Deployer;
import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
import org.apache.tuscany.sca.implementation.osgi.OSGiImplementationFactory;
import org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
import org.apache.tuscany.sca.implementation.osgi.SCAConfig;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
@@ -86,16 +87,17 @@ import org.osgi.util.tracker.ServiceTracker;
* implementation.osgi
*/
public class EndpointIntrospector {
- private BundleContext context;
+ // private BundleContext context;
private AssemblyFactory assemblyFactory;
private ContributionFactory contributionFactory;
private OSGiImplementationFactory implementationFactory;
private PolicyFactory policyFactory;
- private ExtensionPointRegistry registry;
+ // private ExtensionPointRegistry registry;
private FactoryExtensionPoint factories;
private ModelResolverExtensionPoint modelResolvers;
+ // private StAXArtifactProcessor<Composite> compositeProcessor;
private JavaInterfaceFactory javaInterfaceFactory;
- private Deployer deployer;
+ // private Deployer deployer;
private ServiceTracker discoveryTracker;
/**
@@ -124,17 +126,19 @@ public class EndpointIntrospector {
*/
public EndpointIntrospector(BundleContext context, ExtensionPointRegistry registry, ServiceTracker discoveryTracker) {
super();
- this.context = context;
+ // this.context = context;
this.discoveryTracker = discoveryTracker;
- this.registry = registry;
+ // this.registry = registry;
this.factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
this.modelResolvers = registry.getExtensionPoint(ModelResolverExtensionPoint.class);
+// this.compositeProcessor =
+// registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class).getProcessor(Composite.class);
this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
this.contributionFactory = factories.getFactory(ContributionFactory.class);
this.policyFactory = factories.getFactory(PolicyFactory.class);
this.implementationFactory = factories.getFactory(OSGiImplementationFactory.class);
this.javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
- this.deployer = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Deployer.class);
+ // this.deployer = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Deployer.class);
}
private Intent getIntent(String intent) {
@@ -232,54 +236,79 @@ public class EndpointIntrospector {
* @throws Exception
*/
public Contribution introspect(ServiceReference reference, Map<String, Object> props) throws Exception {
+ Bundle bundle = reference.getBundle();
Map<String, Object> properties = getProperties(reference, props);
+ Long sid = (Long)reference.getProperty(SERVICE_ID);
- OSGiProperty serviceID = implementationFactory.createOSGiProperty();
- serviceID.setName(SERVICE_ID);
- // The service.id is Long
- serviceID.setValue(String.valueOf(reference.getProperty(SERVICE_ID)));
+ String[] requiredIntents = getStringArray(properties.get(SERVICE_EXPORTED_INTENTS));
+ List<Intent> intents = getIntents(requiredIntents);
+ String[] requiredIntentsExtra = getStringArray(properties.get(SERVICE_EXPORTED_INTENTS_EXTRA));
+ List<Intent> extraIntents = getIntents(requiredIntentsExtra);
+ Set<Intent> allIntents = new HashSet<Intent>(intents);
+ allIntents.addAll(extraIntents);
+
+ String[] bindingNames = getStringArray(properties.get(SCA_BINDINGS));
+ Collection<Binding> bindings = loadBindings(bindingNames);
+
+ String[] remoteInterfaces = getStringArray(reference.getProperty(SERVICE_EXPORTED_INTERFACES));
+ if (remoteInterfaces == null || remoteInterfaces.length > 0 && "*".equals(remoteInterfaces[0])) {
+ remoteInterfaces = getStringArray(reference.getProperty(OBJECTCLASS));
+ } else {
+ remoteInterfaces = parse(remoteInterfaces);
+ String[] objectClasses = getStringArray(reference.getProperty(OBJECTCLASS));
+ Set<String> objectClassSet = new HashSet<String>(Arrays.asList(objectClasses));
+ if (!objectClassSet.containsAll(Arrays.asList(remoteInterfaces))) {
+ throw new IllegalArgumentException(
+ "The exported interfaces are not a subset of the types" + " listed in the objectClass service property from the Service Reference");
+ }
+ }
+
+ Contribution contribution = generateContribution(bundle, sid, remoteInterfaces, bindings, allIntents);
+ return contribution;
+ }
+ /**
+ * Generate a contribution that contains the composite for the exported service
+ * @param bundle The OSGi bundle
+ * @param sid The service id
+ * @param remoteInterfaces
+ * @param bindings
+ * @param allIntents
+ * @return
+ * @throws ClassNotFoundException
+ * @throws InvalidInterfaceException
+ */
+ private Contribution generateContribution(Bundle bundle,
+ Long sid,
+ String[] remoteInterfaces,
+ Collection<Binding> bindings,
+ Set<Intent> allIntents) throws ClassNotFoundException,
+ InvalidInterfaceException {
String id = "osgi.service." + UUID.randomUUID();
Composite composite = assemblyFactory.createComposite();
composite.setName(new QName(SCA11_TUSCANY_NS, id));
Component component = assemblyFactory.createComponent();
component.setName(id);
- component.setAutowire(Boolean.TRUE);
composite.getComponents().add(component);
- Bundle bundle = reference.getBundle();
OSGiImplementation implementation = implementationFactory.createOSGiImplementation();
implementation.setBundle(bundle);
component.setImplementation(implementation);
implementation.setUnresolved(false);
- String[] remoteInterfaces = getStrings(reference.getProperty(SERVICE_EXPORTED_INTERFACES));
- if (remoteInterfaces == null || remoteInterfaces.length > 0 && "*".equals(remoteInterfaces[0])) {
- remoteInterfaces = getStrings(reference.getProperty(OBJECTCLASS));
- } else {
- remoteInterfaces = parse(remoteInterfaces);
- String[] objectClasses = getStrings(reference.getProperty(OBJECTCLASS));
- Set<String> objectClassSet = new HashSet<String>(Arrays.asList(objectClasses));
- if (!objectClassSet.containsAll(Arrays.asList(remoteInterfaces))) {
- throw new IllegalArgumentException(
- "The exported interfaces are not a subset of the types" + " listed in the objectClass service property from the Service Reference");
- }
- }
+ OSGiProperty serviceID = implementationFactory.createOSGiProperty();
+ serviceID.setName(SERVICE_ID);
+ // The service.id is Long
+ serviceID.setValue(String.valueOf(sid));
+
for (String intf : remoteInterfaces) {
Service service = assemblyFactory.createService();
- JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
- Class<?> interfaceClass = bundle.loadClass(intf);
- JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface(interfaceClass);
- interfaceContract.setInterface(javaInterface);
- if (javaInterface.getCallbackClass() != null) {
- interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(javaInterface
- .getCallbackClass()));
- }
-
- service.setName(interfaceClass.getSimpleName());
+ JavaInterfaceContract interfaceContract = createJavaInterfaceContract(bundle, intf);
+ String name = intf.substring(intf.lastIndexOf('.') + 1);
+ service.setName(name);
service.setInterfaceContract(interfaceContract);
service.getExtensions().add(serviceID);
@@ -292,39 +321,63 @@ public class EndpointIntrospector {
componentService.setService(service);
}
- String[] requiredIntents = getStrings(properties.get(SERVICE_EXPORTED_INTENTS));
- List<Intent> intents = getIntents(requiredIntents);
- String[] requiredIntentsExtra = getStrings(properties.get(SERVICE_EXPORTED_INTENTS_EXTRA));
- List<Intent> extraIntents = getIntents(requiredIntentsExtra);
-
- String[] bindingNames = getStrings(properties.get(SCA_BINDINGS));
- Collection<Binding> bindings = loadBindings(bindingNames);
-
for (ComponentService componentService : component.getServices()) {
- componentService.getRequiredIntents().addAll(intents);
- componentService.getRequiredIntents().addAll(extraIntents);
+ componentService.getRequiredIntents().addAll(allIntents);
componentService.getBindings().addAll(bindings);
}
// FIXME: Should we scan the owning bundle to create the SCA contribution?
+ Contribution contribution = createContribution(bundle, id, composite);
+ return contribution;
+ }
+
+ private Contribution createContribution(Bundle bundle, String id, Composite composite) {
Contribution contribution = contributionFactory.createContribution();
+ contribution.setClassLoader(OSGiHelper.createBundleClassLoader(bundle));
contribution.setURI("urn:" + id);
contribution.setLocation(bundle.getEntry("/").toString());
contribution.getDeployables().add(composite);
ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories);
contribution.setModelResolver(modelResolver);
+ // compositeProcessor.resolve(composite, modelResolver, new ProcessorContext(registry));
contribution.setUnresolved(true);
return contribution;
}
+ /**
+ * @param bundle
+ * @param endpoint
+ * @return
+ * @throws Exception
+ */
public Contribution introspect(Bundle bundle, EndpointDescription endpoint) throws Exception {
+ Collection<Binding> bindings = Collections.emptyList();
+ Collection<String> interfaces = Collections.emptyList();
+ Collection<Intent> intents = Collections.emptyList();
Endpoint ep = (Endpoint)endpoint.getProperties().get(Endpoint.class.getName());
if (ep != null) {
- return introspect(bundle, ep);
+ bindings = Collections.singletonList(ep.getBinding());
+ interfaces = Collections.singletonList(((JavaInterface)ep.getInterfaceContract().getInterface()).getName());
+ intents = ep.getRequiredIntents();
+ } else {
+ Map<String, Object> properties = endpoint.getProperties();
+ interfaces = endpoint.getInterfaces();
+ String[] requiredIntents = getStringArray(properties.get(SERVICE_EXPORTED_INTENTS));
+ intents = getIntents(requiredIntents);
+
+ String[] bindingNames = getStringArray(properties.get(SCA_BINDINGS));
+ bindings = loadBindings(bindingNames);
}
- Map<String, Object> properties = endpoint.getProperties();
- List<String> remoteInterfaces = endpoint.getInterfaces();
+ Contribution contribution = generateContribution(bundle, interfaces, bindings, intents);
+ return contribution;
+ }
+
+ private Contribution generateContribution(Bundle bundle,
+ Collection<String> remoteInterfaces,
+ Collection<Binding> bindings,
+ Collection<Intent> intents) throws ClassNotFoundException,
+ InvalidInterfaceException, ContributionResolveException {
String id = "osgi.reference." + UUID.randomUUID();
Composite composite = assemblyFactory.createComposite();
composite.setName(new QName(Base.SCA11_TUSCANY_NS, id));
@@ -344,14 +397,7 @@ public class EndpointIntrospector {
int count = 0;
for (String intf : remoteInterfaces) {
Reference reference = assemblyFactory.createReference();
- JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
- Class<?> interfaceClass = bundle.loadClass(intf);
- JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface(interfaceClass);
- interfaceContract.setInterface(javaInterface);
- if (javaInterface.getCallbackClass() != null) {
- interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(javaInterface
- .getCallbackClass()));
- }
+ JavaInterfaceContract interfaceContract = createJavaInterfaceContract(bundle, intf);
reference.setName("ref" + (count++));
reference.setInterfaceContract(interfaceContract);
@@ -365,77 +411,30 @@ public class EndpointIntrospector {
componentReference.setWiredByImpl(true);
}
- String[] requiredIntents = getStrings(properties.get(SERVICE_EXPORTED_INTENTS));
- List<Intent> intents = getIntents(requiredIntents);
-
- String[] bindingNames = getStrings(properties.get(SCA_BINDINGS));
- Collection<Binding> bindings = loadBindings(bindingNames);
-
for (ComponentReference componentReference : component.getReferences()) {
componentReference.getRequiredIntents().addAll(intents);
componentReference.getBindings().addAll(bindings);
}
- // FIXME: Should we scan the owning bundle to create the SCA contribution?
- Contribution contribution = contributionFactory.createContribution();
- contribution.setURI("urn:" + id);
- contribution.setLocation(bundle.getEntry("/").toString());
- contribution.getDeployables().add(composite);
- ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories);
- contribution.setModelResolver(modelResolver);
- contribution.setUnresolved(true);
+
+ Contribution contribution = createContribution(bundle, id, composite);
return contribution;
}
- public Contribution introspect(Bundle bundle, Endpoint endpoint) throws Exception {
- String id = "osgi.reference." + UUID.randomUUID();
- Composite composite = assemblyFactory.createComposite();
- composite.setName(new QName(Base.SCA11_TUSCANY_NS, id));
-
- Component component = assemblyFactory.createComponent();
- component.setName(id);
- // component.setAutowire(Boolean.TRUE);
-
- composite.getComponents().add(component);
-
- OSGiImplementation implementation = implementationFactory.createOSGiImplementation();
-
- implementation.setBundle(bundle);
- component.setImplementation(implementation);
- implementation.setUnresolved(false);
-
- Reference reference = assemblyFactory.createReference();
- Service service = endpoint.getService().getService();
- reference.setInterfaceContract(service.getInterfaceContract());
- reference.setName("ref");
-
- reference.getBindings().add(endpoint.getBinding());
-
- /*
- reference.getRequiredIntents().addAll(service.getRequiredIntents());
- reference.getPolicySets().addAll(service.getPolicySets());
- */
-
- implementation.getReferences().add(reference);
-
- ComponentReference componentReference = assemblyFactory.createComponentReference();
- component.getReferences().add(componentReference);
- componentReference.setReference(reference);
- componentReference.setName(reference.getName());
- componentReference.setWiredByImpl(true);
-
- // FIXME: Should we scan the owning bundle to create the SCA contribution?
- Contribution contribution = contributionFactory.createContribution();
- contribution.setURI("urn:" + id);
- contribution.setLocation(bundle.getEntry("/").toString());
- contribution.getDeployables().add(composite);
- ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories);
- contribution.setModelResolver(modelResolver);
- contribution.setUnresolved(true);
- return contribution;
+ private JavaInterfaceContract createJavaInterfaceContract(Bundle bundle, String intf)
+ throws ClassNotFoundException, InvalidInterfaceException {
+ JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+ Class<?> interfaceClass = bundle.loadClass(intf);
+ JavaInterface javaInterface = javaInterfaceFactory.createJavaInterface(interfaceClass);
+ interfaceContract.setInterface(javaInterface);
+ if (javaInterface.getCallbackClass() != null) {
+ interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(javaInterface
+ .getCallbackClass()));
+ }
+ return interfaceContract;
}
- private Collection<Binding> loadBindings(String[] qnames) throws IOException,
- ContributionReadException, XMLStreamException {
+ private Collection<Binding> loadBindings(String[] qnames) throws IOException, ContributionReadException,
+ XMLStreamException {
if (qnames == null || qnames.length == 0) {
return Collections.emptyList();
}
@@ -472,23 +471,4 @@ public class EndpointIntrospector {
return bindingMap.values();
}
- /**
- * In OSGi, the value of String+ can be a single String, String[] or Collection<String>
- * @param value
- * @return
- */
- private String[] getStrings(Object value) {
- if (value == null) {
- return null;
- }
- if (value instanceof String) {
- return new String[] {(String)value};
- } else if (value instanceof Collection) {
- Collection<String> collection = (Collection)value;
- return collection.toArray(new String[collection.size()]);
- }
- return (String[])value;
-
- }
-
}
diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java
index 52abef059c..a4b51d9d0c 100644
--- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiHelper.java
@@ -19,12 +19,15 @@
package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
+import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
+import java.util.List;
+import java.util.UUID;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
@@ -40,6 +43,8 @@ import org.osgi.framework.ServiceReference;
*
*/
public class OSGiHelper {
+ public final static String FRAMEWORK_UUID = "org.osgi.framework.uuid";
+
private OSGiHelper() {
}
@@ -140,6 +145,60 @@ public class OSGiHelper {
FactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(FactoryExtensionPoint.class);
OSGiImplementationFactory implementationFactory= factoryExtensionPoint.getFactory(OSGiImplementationFactory.class);
return implementationFactory.createOSGiProperties(reference);
+ }
+
+ public static OSGiProperty createOSGiProperty(ExtensionPointRegistry registry, String name, Object value) {
+ FactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ OSGiImplementationFactory implementationFactory= factoryExtensionPoint.getFactory(OSGiImplementationFactory.class);
+ return implementationFactory.createOSGiProperty(name, value);
+ }
+
+
+ public synchronized static String getFrameworkUUID(BundleContext bundleContext) {
+ String uuid = null;
+ if (bundleContext != null) {
+ uuid = bundleContext.getProperty(FRAMEWORK_UUID);
+ } else {
+ uuid = System.getProperty(FRAMEWORK_UUID);
+ }
+ if (uuid == null) {
+ uuid = UUID.randomUUID().toString();
+ }
+ System.setProperty(FRAMEWORK_UUID, uuid);
+ return uuid;
+ }
+
+ public static ClassLoader createBundleClassLoader(Bundle bundle) {
+ return new BundleClassLoader(bundle);
+ }
+
+ private static class BundleClassLoader extends ClassLoader {
+ private Bundle bundle;
+ public BundleClassLoader(Bundle bundle) {
+ super(null);
+ this.bundle = bundle;
+ }
+
+ @Override
+ protected Class<?> findClass(String name) throws ClassNotFoundException {
+ return bundle.loadClass(name);
+ }
+
+ @Override
+ protected URL findResource(String name) {
+ return bundle.getResource(name);
+ }
+
+ @Override
+ protected Enumeration<URL> findResources(String name) throws IOException {
+ Enumeration<URL> urls = bundle.getResources(name);
+ if (urls == null) {
+ List<URL> list = Collections.emptyList();
+ return Collections.enumeration(list);
+ } else {
+ return urls;
+ }
+ }
}
}
diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
index 21950d9d59..479ae54e42 100644
--- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/OSGiServiceExporter.java
@@ -19,7 +19,13 @@
package org.apache.tuscany.sca.osgi.remoteserviceadmin.impl;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteConstants.SERVICE_REMOTE_ID;
import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.EndpointHelper.createEndpointDescription;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper.createOSGiProperty;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper.getFrameworkUUID;
+import static org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper.getOSGiProperties;
+import static org.osgi.framework.Constants.SERVICE_ID;
import java.util.ArrayList;
import java.util.Collections;
@@ -77,7 +83,13 @@ public class OSGiServiceExporter extends AbstractOSGiServiceHandler implements S
configuration.getExtensions().add(reference.getBundle());
Component component = contribution.getDeployables().get(0).getComponents().get(0);
ComponentService service = component.getServices().get(0);
- service.getExtensions().addAll(OSGiHelper.getOSGiProperties(registry, reference));
+ service.getExtensions().addAll(getOSGiProperties(registry, reference));
+ service.getExtensions().add(createOSGiProperty(registry,
+ SERVICE_REMOTE_FRAMEWORK_UUID,
+ getFrameworkUUID(reference.getBundle()
+ .getBundleContext())));
+ service.getExtensions().add(createOSGiProperty(registry, SERVICE_REMOTE_ID, reference
+ .getProperty(SERVICE_ID)));
// FIXME: Configure the domain and node URI
NodeImpl node = new NodeImpl(nodeFactory, configuration, Collections.singletonList(contribution));
diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java
index 594fe32e54..11dcd56272 100644
--- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java
+++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java
@@ -38,7 +38,7 @@ import org.apache.tuscany.sca.implementation.osgi.ServiceDescription;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions;
import org.apache.tuscany.sca.osgi.remoteserviceadmin.EndpointDescription;
import org.apache.tuscany.sca.osgi.remoteserviceadmin.RemoteConstants;
-import org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.EndpointHelper;
+import org.apache.tuscany.sca.osgi.remoteserviceadmin.impl.OSGiHelper;
import org.oasisopen.sca.ServiceRuntimeException;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -92,7 +92,7 @@ public class LocalDiscoveryService extends AbstractDiscoveryService implements B
props.put(RemoteConstants.SERVICE_REMOTE_ID, String.valueOf(System.currentTimeMillis()));
}
if (!props.containsKey(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID)) {
- props.put(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID, EndpointHelper.getFrameworkUUID(context));
+ props.put(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID, OSGiHelper.getFrameworkUUID(context));
}
if (!props.containsKey(RemoteConstants.SERVICE_REMOTE_URI)) {
props.put(RemoteConstants.SERVICE_REMOTE_URI, UUID.randomUUID().toString());