summaryrefslogtreecommitdiffstats
path: root/java/sca
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-06-30 18:08:11 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-06-30 18:08:11 +0000
commite43a2126d8ff5d8ed6a9e47f2bbc15d157a53e0a (patch)
tree4062be0623bafafdff2c32b1b1c3b7f0e463276f /java/sca
parent18c8b44a86b649c56d11a2fb736a19f29dd2fb32 (diff)
Starting to hook distribution/discovery services
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@789859 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca')
-rw-r--r--java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF3
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java8
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java6
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java2
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiDistributionProvider.java102
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java22
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java16
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/distribution/DistributionProvider.java102
8 files changed, 178 insertions, 83 deletions
diff --git a/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF b/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF
index d428c8ce54..b2e1c16707 100644
--- a/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF
+++ b/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF
@@ -29,4 +29,5 @@ Import-Package: org.apache.tuscany.sca.assembly;version="2.0.0",
org.osgi.util.tracker
Bundle-DocURL: http://www.apache.org/
Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
-Export-Package: org.osgi.service.discovery;version="1.0"
+Export-Package: org.osgi.service.discovery;version="1.0",
+ org.osgi.service.distribution;version="1.0"
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java
index 7f0b128bd0..75c5bc39f9 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java
+++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java
@@ -318,6 +318,14 @@ public abstract class AbstractDiscoveryService implements Discovery {
}
}
+ /**
+ * Publish the OSGi services that are exposed to SCA. For SCA, the replicated endpoint registry
+ * serves are the discovery protocol. The OSGi services are added to endpoint registry first before
+ * the ServicePublication services are registered so that othe Discovery services can see them.
+ * @param ref
+ * @param endpoint
+ * @return
+ */
protected ServiceRegistration localServicePublished(ServiceReference ref, Endpoint endpoint) {
EndpointPublication publication = new EndpointPublication(ref, endpoint);
ServiceRegistration registration =
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java
index 7dd605dd8e..9497619b5b 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java
+++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveryActivator.java
@@ -37,8 +37,12 @@ public class DiscoveryActivator implements BundleActivator {
discoveryServices.add(new DomainDiscoveryService(context));
for (AbstractDiscoveryService service : discoveryServices) {
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put(Discovery.PRODUCT_NAME, "Apache Tuscany SCA");
+ props.put(Discovery.PRODUCT_VERSION, "2.0.0");
+ props.put(Discovery.VENDOR_NAME, "Apache Software Foundation");
ServiceRegistration registration =
- context.registerService(Discovery.class.getName(), service, new Hashtable<String, Object>());
+ context.registerService(Discovery.class.getName(), service, props);
discoveryServiceRegistrations.add(registration);
}
}
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java
index 2a04a80426..d39ee4712f 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java
+++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java
@@ -90,7 +90,7 @@ public class LocalDiscoveryService extends AbstractDiscoveryService implements B
servicesInfo.put(sed, b);
serviceDescriptionAdded(sed);
}
- throw new RuntimeException("To be implemented");
+ // throw new RuntimeException("To be implemented");
}
private void removeServicesDeclaredInBundle(Bundle bundle) {
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiDistributionProvider.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiDistributionProvider.java
index ff30730c78..b471d645dc 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiDistributionProvider.java
+++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiDistributionProvider.java
@@ -6,94 +6,60 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.implementation.osgi.runtime;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Hashtable;
import java.util.Map;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.distribution.DistributionProvider;
/**
- * Every Distribution Provider registers exactly one Service in the
- * ServiceRegistry implementing this interface. The service is registered with
- * extra properties identified at the beginning of this interface to denote the
- * Distribution Provider product name, version, vendor and supported intents.
+ * OSGi distribution provider
*/
-public interface OSGiDistributionProvider {
+public class OSGiDistributionProvider implements DistributionProvider {
+ private BundleContext bundleContext;
+ private Collection<ServiceReference> exposedServices = new ArrayList<ServiceReference>();
+ private Collection<ServiceReference> remoteServices = new ArrayList<ServiceReference>();
- /**
- * Service Registration property for the name of the Distribution Provider
- * product.
- */
- static final String PROP_KEY_PRODUCT_NAME = "osgi.remote.distribution.product";
+ public OSGiDistributionProvider(BundleContext bundleContext) {
+ super();
+ this.bundleContext = bundleContext;
+ }
- /**
- * Service Registration property for the version of the Distribution
- * Provider product.
- */
- static final String PROP_KEY_PRODUCT_VERSION = "osgi.remote.distribution.product.version";
+ public Map<String, String> getExposedProperties(ServiceReference sr) {
+ return Collections.emptyMap();
+ }
- /**
- * Service Registration property for the Distribution Provider product
- * vendor name.
- */
- static final String PROP_KEY_VENDOR_NAME = "osgi.remote.distribution.vendor";
+ public Collection<ServiceReference> getExposedServices() {
+ return exposedServices;
+ }
- /**
- * Service Registration property that lists the intents supported by this
- * DistributionProvider. Value of this property is of type
- * Collection (<? extends String>).
- */
- static final String PROP_KEY_SUPPORTED_INTENTS = "osgi.remote.distribition.supported_intents";
-
- /**
- * @return ServiceReferences of services registered in the local Service
- * Registry that are proxies to remote services. If no proxies are
- * registered, then an empty collection is returned.
- */
- Collection<ServiceReference> getRemoteServices();
-
- /**
- * @return ServiceReferences of local services that are exposed remotely
- * using this DisitributionProvider. Note that certain services may be
- * exposed and without being published to a discovery service. This
- * API returns all the exposed services. If no services are exposed an
- * empty collection is returned.
- */
- Collection<ServiceReference> getExposedServices();
-
- /**
- * Provides access to extra properties set by the DistributionProvider on
- * endpoints, as they will appear on client side proxies given an exposed
- * ServiceReference.
- * These properties are not always available on the server-side
- * ServiceReference of the exposed
- * service but will be on the remote client side proxy to this service.
- * This API provides access to these extra properties from the exposing
- * side.
- * E.g. a service is exposed remotely, the distribution software is configured
- * to add transactionality to the remote service. Because of this, on the
- * client-side proxy the property service.intents=”transactionality” is set.
- * However, these intents are *not* always set on the original
- * ServiceRegistration on the server-side since on the server side the service
- * object is a local pojo which doesn’t provide transactionality by itself.
- * This QoS is added by the distribution.
- * This API provides access to these extra properties from the server-side.
- *
- * @param sr A ServiceReference of an exposed service.
- * @return The map of extra properties.
- */
- Map<String, String> getExposedProperties(ServiceReference sr);
+ public Collection<ServiceReference> getRemoteServices() {
+ return remoteServices;
+ }
+ public Dictionary<String, Object> getProperties() {
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+ props.put(PRODUCT_NAME, "Apache Tuscany SCA");
+ props.put(PRODUCT_VERSION, "2.0.0");
+ props.put(VENDOR_NAME, "Apache Software Foundation");
+ return props;
+ }
}
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java
index f3d59cc513..9138a0147f 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java
+++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationRuntimeActivator.java
@@ -6,33 +6,49 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.implementation.osgi.runtime;
+import org.apache.tuscany.sca.dosgi.discovery.DiscoveryActivator;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.distribution.DistributionProvider;
/**
* Bundle activator to receive the BundleContext
*/
public class OSGiImplementationRuntimeActivator implements BundleActivator {
private static BundleContext bundleContext;
+ private DiscoveryActivator discoveryActivator;
+ private ServiceRegistration distributionProvider;
public void start(BundleContext context) throws Exception {
bundleContext = context;
+ discoveryActivator = new DiscoveryActivator();
+ discoveryActivator.start(context);
+ OSGiDistributionProvider provider = new OSGiDistributionProvider(bundleContext);
+ distributionProvider = bundleContext.registerService(DistributionProvider.class.getName(), provider, provider.getProperties());
}
public void stop(BundleContext context) throws Exception {
+ if (discoveryActivator != null) {
+ discoveryActivator.stop(context);
+ }
+ if (distributionProvider != null) {
+ distributionProvider.unregister();
+ }
+ discoveryActivator = null;
bundleContext = null;
}
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java
index 52313a84e7..1814ab928c 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java
+++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.implementation.osgi.runtime;
@@ -26,7 +26,6 @@ import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
-import org.apache.tuscany.sca.core.factory.InstanceWrapper;
import org.apache.tuscany.sca.interfacedef.DataType;
import org.apache.tuscany.sca.interfacedef.Interface;
import org.apache.tuscany.sca.interfacedef.Operation;
@@ -42,13 +41,12 @@ import org.osgi.framework.ServiceReference;
/**
* The Invoker looks up the corresponding OSGi service from the OSGi service registry
* and delegate the call to it.
- *
+ *
* @version $Rev$ $Date$
*/
-public class OSGiTargetInvoker<T> implements Invoker {
+public class OSGiTargetInvoker implements Invoker {
private Operation operation;
- protected InstanceWrapper<T> target;
private final OSGiImplementationProvider provider;
private final RuntimeComponent component;
@@ -175,7 +173,7 @@ public class OSGiTargetInvoker<T> implements Invoker {
/**
* Return the method on the implementation class that matches the operation.
- *
+ *
* @param implClass the implementation class or interface
* @param operation the operation to match
* @return the method described by the operation
@@ -197,7 +195,7 @@ public class OSGiTargetInvoker<T> implements Invoker {
}
}
- // TUSCANY-2180 If there is only one method then we just match on the name
+ // TUSCANY-2180 If there is only one method then we just match on the name
// (this is the same as the existing behaviour)
if (matchingMethods.size() == 1) {
return matchingMethods.get(0);
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/distribution/DistributionProvider.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/distribution/DistributionProvider.java
new file mode 100644
index 0000000000..43783e5e53
--- /dev/null
+++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/osgi/service/distribution/DistributionProvider.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) OSGi Alliance (2000, 2008). All Rights Reserved.
+ *
+ * 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
+ *
+ * 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.osgi.service.distribution;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Every Distribution Provider registers exactly one Service in the
+ * ServiceRegistry implementing this interface. The service is registered with
+ * extra properties identified at the beginning of this interface to denote the
+ * Distribution Provider product name, version, vendor and supported intents.
+ *
+ * @ThreadSafe
+ * @version $Revision$
+ */
+public interface DistributionProvider {
+ /**
+ * Service Registration property for the name of the Distribution Provider
+ * product.
+ * <p>
+ * The value of this property is of type String.
+ */
+ static final String PRODUCT_NAME = "osgi.remote.distribution.product";
+
+ /**
+ * Service Registration property for the version of the Distribution
+ * Provider product.
+ * <p>
+ * The value of this property is of type String.
+ */
+ static final String PRODUCT_VERSION = "osgi.remote.distribution.product.version";
+
+ /**
+ * Service Registration property for the Distribution Provider product
+ * vendor name.
+ * <p>
+ * The value of this property is of type String.
+ */
+ static final String VENDOR_NAME = "osgi.remote.distribution.vendor";
+
+ /**
+ * Service Registration property that lists the intents supported by this
+ * DistributionProvider.
+ * <p>
+ * The value of this property is of type String, String[] or Collection of
+ * String.
+ */
+ static final String SUPPORTED_INTENTS = "osgi.remote.distribition.supported_intents";
+
+ /**
+ * @return ServiceReferences of services registered in the local Service
+ * Registry that are proxies to remote services. If no proxies are
+ * registered, then an empty collection is returned.
+ */
+ Collection /*<? extends ServiceReference>*/getRemoteServices();
+
+ /**
+ * @return ServiceReferences of local services that are exposed remotely
+ * using this DisitributionProvider. Note that certain services may be
+ * exposed and without being published to a discovery service. This
+ * API returns all the exposed services. If no services are exposed an
+ * empty collection is returned.
+ */
+ Collection /*<? extends ServiceReference>*/getExposedServices();
+
+ /**
+ * Provides access to extra properties set by the DistributionProvider on
+ * endpoints, as they will appear on client side proxies given an exposed
+ * ServiceReference. These properties are not always available on the
+ * server-side ServiceReference of the exposed service but will be on the
+ * remote client side proxy to this service. This API provides access to
+ * these extra properties from the exposing side. E.g. a service is exposed
+ * remotely, the distribution software is configured to add transactionality
+ * to the remote service. Because of this, on the client-side proxy the
+ * property serviceosgi.intents="transactionality" is set. However, these
+ * intents are <i>not</i> always set on the original ServiceRegistration on
+ * the server-side since on the server side the service object is a local
+ * pojo which doesn't provide transactionality by itself. This QoS is added
+ * by the distribution. This API provides access to these extra properties
+ * from the server-side.
+ *
+ * @param sr A ServiceReference of an exposed service.
+ * @return The map of extra properties.
+ */
+ Map /*<String, String>*/getExposedProperties(ServiceReference sr);
+}