diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-26 00:03:12 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-26 00:03:12 +0000 |
commit | 7e3cc953eb4a9cc95acd48d3c3548112f882b9b0 (patch) | |
tree | a9fe69c29dad19bcc7dd209987121ec8854e45dc /java/sca/modules/implementation-osgi-runtime | |
parent | 1b3a890cc41d865af96875e3984a4de82668136b (diff) |
Some refactoring on the discovery
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@788553 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-osgi-runtime')
-rw-r--r-- | java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/AbstractDiscoveryService.java | 8 | ||||
-rw-r--r-- | java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveredServiceNotificationImpl.java (renamed from java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointNotification.java) | 4 | ||||
-rw-r--r-- | java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java | 22 | ||||
-rw-r--r-- | java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointDescription.java | 69 | ||||
-rw-r--r-- | java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointPublication.java | 7 |
5 files changed, 82 insertions, 28 deletions
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 22c0e5bc7d..7f0b128bd0 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 @@ -42,6 +42,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.DiscoveredServiceNotification;
import org.osgi.service.discovery.DiscoveredServiceTracker;
import org.osgi.service.discovery.Discovery;
import org.osgi.service.discovery.ServiceEndpointDescription;
@@ -191,9 +192,10 @@ public abstract class AbstractDiscoveryService implements Discovery { + (isFilter ? " matches " : " contained by ")
+ sd.getProvidedInterfaces());
- EndpointNotification notification =
- isFilter ? (filterMatches(toMatch, sd) ? new EndpointNotification(sd, true, toMatch, type) : null) : (sd
- .getProvidedInterfaces().contains(toMatch) ? new EndpointNotification(sd, false, toMatch, type) : null);
+ DiscoveredServiceNotification notification =
+ isFilter ? (filterMatches(toMatch, sd) ? new DiscoveredServiceNotificationImpl(sd, true, toMatch, type)
+ : null) : (sd.getProvidedInterfaces().contains(toMatch)
+ ? new DiscoveredServiceNotificationImpl(sd, false, toMatch, type) : null);
if (notification != null) {
tracker.serviceChanged(notification);
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointNotification.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveredServiceNotificationImpl.java index 659a683089..a110fa9528 100644 --- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointNotification.java +++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DiscoveredServiceNotificationImpl.java @@ -27,14 +27,14 @@ import java.util.HashSet; import org.osgi.service.discovery.DiscoveredServiceNotification;
import org.osgi.service.discovery.ServiceEndpointDescription;
-class EndpointNotification implements DiscoveredServiceNotification {
+public class DiscoveredServiceNotificationImpl implements DiscoveredServiceNotification {
private ServiceEndpointDescription discription;
private Collection<String> interfaces;
private Collection<String> filters;
private int type;
- EndpointNotification(ServiceEndpointDescription sd, boolean isFilter, String match, int type) {
+ public DiscoveredServiceNotificationImpl(ServiceEndpointDescription sd, boolean isFilter, String match, int type) {
this.discription = sd;
if (isFilter) {
filters = new ArrayList<String>();
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java index acd112395e..97eddfa9e5 100644 --- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java +++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/DomainDiscoveryService.java @@ -22,8 +22,6 @@ package org.apache.tuscany.sca.dosgi.discovery; 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;
@@ -41,7 +39,6 @@ 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
@@ -90,7 +87,7 @@ public class DomainDiscoveryService extends AbstractDiscoveryService implements }
} else {
// Remote endpoints
- ServiceEndpointDescription description = getServiceEndpointDescription(endpoint);
+ ServiceEndpointDescription description = new EndpointDescription(endpoint);
discoveredServiceChanged(description, AVAILABLE);
}
}
@@ -104,7 +101,7 @@ public class DomainDiscoveryService extends AbstractDiscoveryService implements }
} else {
// Remote endpoints
- ServiceEndpointDescription description = getServiceEndpointDescription(endpoint);
+ ServiceEndpointDescription description = new EndpointDescription(endpoint);
discoveredServiceChanged(description, UNAVAILABLE);
}
}
@@ -120,19 +117,4 @@ public class DomainDiscoveryService extends AbstractDiscoveryService implements 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) {
- Interface interface1 = endpoint.getService().getInterfaceContract().getInterface();
- JavaInterface javaInterface = (JavaInterface)interface1;
- ServiceEndpointDescription description =
- new ServiceEndpointDescriptionImpl(Collections.singleton(javaInterface.getName()),
- getServiceProperties(endpoint));
- return description;
- }
}
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointDescription.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointDescription.java new file mode 100644 index 0000000000..3f47183a56 --- /dev/null +++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointDescription.java @@ -0,0 +1,69 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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.
+ */
+
+package org.apache.tuscany.sca.dosgi.discovery;
+
+import static org.osgi.service.discovery.ServicePublication.ENDPOINT_ID;
+import static org.osgi.service.discovery.ServicePublication.ENDPOINT_LOCATION;
+
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+
+/**
+ *
+ */
+public class EndpointDescription extends ServiceEndpointDescriptionImpl {
+ public EndpointDescription(Endpoint endpoint) {
+ super(Collections.singleton(getInterfaceName(endpoint)), getServiceProperties(endpoint));
+ }
+
+ static String getInterfaceName(Endpoint endpoint) {
+ ComponentService service = endpoint.getService();
+ if (service == null) {
+ return null;
+ }
+ InterfaceContract contract = service.getInterfaceContract();
+ if (contract == null) {
+ return null;
+ }
+ Interface intf = contract.getInterface();
+ if (intf instanceof JavaInterface) {
+ JavaInterface javaInterface = (JavaInterface)intf;
+ return javaInterface.getName();
+ }
+
+ return null;
+ }
+
+ static Map<String, Object> getServiceProperties(Endpoint endpoint) {
+ Map<String, Object> serviceProps = new HashMap<String, Object>();
+ serviceProps.put(ENDPOINT_ID, endpoint.getURI());
+ serviceProps.put(ENDPOINT_LOCATION, URI.create(endpoint.getBinding().getURI()));
+ // TODO: Populate the properties from the Endpoint object
+ return serviceProps;
+ }
+}
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointPublication.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointPublication.java index 82080a2dc1..184d3a12bf 100644 --- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointPublication.java +++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/dosgi/discovery/EndpointPublication.java @@ -19,8 +19,8 @@ package org.apache.tuscany.sca.dosgi.discovery;
+import java.util.Collections;
import java.util.Dictionary;
-import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
@@ -52,10 +52,11 @@ public class EndpointPublication implements ServicePublication { public Dictionary<String, Object> getProperties() {
Dictionary<String, Object> props = new Hashtable<String, Object>();
- Map<String, Object> serviceProps = new HashMap<String, Object>();
- serviceProps.put(ENDPOINT_LOCATION, endpoint.getURI());
+ Map<String, Object> serviceProps = EndpointDescription.getServiceProperties(endpoint);
props.put(SERVICE_PROPERTIES, serviceProps);
// TODO: Populate the properties from the Endpoint object
+ String name = EndpointDescription.getInterfaceName(endpoint);
+ props.put(ENDPOINT_INTERFACE_NAME, Collections.singleton(name));
return props;
}
|