You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2009/06/25 02:17:16 UTC
svn commit: r788223 - in
/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery:
AbstractDiscoveryService.java DomainDiscoveryService.java
LocalDiscoveryService.java
Author: rfeng
Date: Thu Jun 25 00:17:16 2009
New Revision: 788223
URL: http://svn.apache.org/viewvc?rev=788223&view=rev
Log:
Add more logic to handle the Endpoint publication and discovery
Modified:
tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java
tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java
tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java
Modified: tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java?rev=788223&r1=788222&r2=788223&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java Thu Jun 25 00:17:16 2009
@@ -41,6 +41,7 @@
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.discovery.DiscoveredServiceTracker;
import org.osgi.service.discovery.Discovery;
import org.osgi.service.discovery.ServiceEndpointDescription;
@@ -103,7 +104,7 @@
ServiceTracker tracker = new ServiceTracker(context, ExtensionPointRegistry.class.getName(), null);
tracker.open();
// tracker.waitForService(1000);
- ExtensionPointRegistry extensionPointRegistry = (ExtensionPointRegistry) tracker.getService();
+ ExtensionPointRegistry extensionPointRegistry = (ExtensionPointRegistry)tracker.getService();
tracker.close();
return extensionPointRegistry;
}
@@ -315,9 +316,13 @@
}
}
- protected void localServicePublished(ServiceReference ref, Endpoint endpoint) {
+ protected ServiceRegistration localServicePublished(ServiceReference ref, Endpoint endpoint) {
EndpointPublication publication = new EndpointPublication(ref, endpoint);
- ref.getBundle().getBundleContext().registerService(ServicePublication.class.getName(), publication, publication.getProperties());
+ ServiceRegistration registration =
+ ref.getBundle().getBundleContext().registerService(ServicePublication.class.getName(),
+ publication,
+ publication.getProperties());
+ return registration;
}
}
Modified: tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java?rev=788223&r1=788222&r2=788223&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java Thu Jun 25 00:17:16 2009
@@ -22,6 +22,11 @@
import static org.osgi.service.discovery.DiscoveredServiceNotification.AVAILABLE;
import static org.osgi.service.discovery.DiscoveredServiceNotification.UNAVAILABLE;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.assembly.Implementation;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
@@ -34,7 +39,9 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.discovery.ServiceEndpointDescription;
+import org.osgi.service.discovery.ServicePublication;
/**
* Discovery service based on the distributed SCA domain
@@ -42,6 +49,9 @@
public class DomainDiscoveryService extends AbstractDiscoveryService implements EndpointListener {
private EndpointRegistry endpointRegistry;
+ private Map<String, ServiceRegistration> endpointRegistrations =
+ new ConcurrentHashMap<String, ServiceRegistration>();
+
public DomainDiscoveryService(BundleContext context) {
super(context);
@@ -60,8 +70,7 @@
OSGiImplementation osgiImpl = (OSGiImplementation)impl;
BundleContext bundleContext = osgiImpl.getBundle().getBundleContext();
- boolean local = true;
- if (local) {
+ if (!endpoint.isRemote()) {
Interface intf = endpoint.getService().getInterfaceContract().getInterface();
JavaInterface javaInterface = (JavaInterface)intf;
@@ -76,7 +85,8 @@
// Ignore
}
if (ref != null) {
- localServicePublished(ref, endpoint);
+ ServiceRegistration registration = localServicePublished(ref, endpoint);
+ endpointRegistrations.put(endpoint.getURI(), registration);
}
} else {
// Remote endpoints
@@ -85,14 +95,13 @@
}
}
- private boolean isLocal(Endpoint endpoint) {
- // FIXME: To be implemented
- return true;
- }
-
public void endpointRemoved(Endpoint endpoint) {
- if (isLocal(endpoint)) {
+ if (!endpoint.isRemote()) {
// unregister the ServicePublication here
+ ServiceRegistration registration = endpointRegistrations.get(endpoint.getURI());
+ if (registration != null) {
+ registration.unregister();
+ }
} else {
// Remote endpoints
ServiceEndpointDescription description = getServiceEndpointDescription(endpoint);
@@ -101,6 +110,9 @@
}
public void endpointUpdated(Endpoint oldEndpoint, Endpoint newEndpoint) {
+ // FIXME: This is a quick and dirty way for the update
+ endpointRemoved(oldEndpoint);
+ endpointAdded(newEndpoint);
}
public void stop() {
@@ -108,7 +120,19 @@
super.stop();
}
+ public Map<String, Object> getServiceProperties(Endpoint endpoint) {
+ Map<String, Object> serviceProps = new HashMap<String, Object>();
+ serviceProps.put(ServicePublication.ENDPOINT_LOCATION, endpoint.getURI());
+ // TODO: Populate the properties from the Endpoint object
+ return serviceProps;
+ }
+
private ServiceEndpointDescription getServiceEndpointDescription(Endpoint endpoint) {
- return null;
+ Interface interface1 = endpoint.getService().getInterfaceContract().getInterface();
+ JavaInterface javaInterface = (JavaInterface)interface1;
+ ServiceEndpointDescription description =
+ new ServiceEndpointDescriptionImpl(Collections.singleton(javaInterface.getName()),
+ getServiceProperties(endpoint));
+ return description;
}
}
Modified: tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java?rev=788223&r1=788222&r2=788223&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/LocalDiscoveryService.java Thu Jun 25 00:17:16 2009
@@ -25,12 +25,14 @@
import static org.osgi.service.discovery.DiscoveredServiceNotification.UNAVAILABLE;
import java.util.Collections;
+import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
@@ -72,6 +74,16 @@
}
private void discover(Bundle b) {
+ String path = (String)b.getHeaders().get(ServiceDescriptions.REMOTE_SERVICE_HEADER);
+ if (path == null) {
+ Enumeration files = b.findEntries(ServiceDescriptions.REMOTE_SERVICE_FOLDER, "*.xml", false);
+ if (files == null || !files.hasMoreElements()) {
+ return;
+ }
+ }
+
+ ServiceDescriptions descriptions = null;
+
// TODO: Use SCA contribution to load the service discription files
List<ServiceEndpointDescription> refs = Collections.emptyList();
for (ServiceEndpointDescription sed : refs) {