summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/endpoint-tribes/src/main
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-06-11 05:29:44 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-06-11 05:29:44 +0000
commit846b8fa2a3853c426f98d42fc49d9bbbd1d92dee (patch)
treebfb66dd29f67a609eb4f95cf1772466991ffaae2 /java/sca/modules/endpoint-tribes/src/main
parent6ecd6c5f7101ca2d127bbde07206f08df5f9e995 (diff)
Use uri for Endpoint/EndpointReference
Defer the deserilization of Endpoint to later point to avoid NPE git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@783634 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/endpoint-tribes/src/main')
-rw-r--r--java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java58
-rw-r--r--java/sca/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry2
2 files changed, 49 insertions, 11 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 330c22d4e9..f7dac1ff33 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
@@ -128,6 +128,50 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry {
listeners.add(listener);
}
+ /**
+ * Parse the component/service/binding URI into an array of parts (componentURI, serviceName, bindingName)
+ * @param uri
+ * @return
+ */
+ private String[] parse(String uri) {
+ String[] names = new String[3];
+ int index = uri.lastIndexOf('#');
+ if (index == -1) {
+ names[0] = uri;
+ } else {
+ names[0] = uri.substring(0, index);
+ String str = uri.substring(index + 1);
+ if (str.startsWith("service-binding(") && str.endsWith(")")) {
+ str = str.substring("service-binding(".length(), str.length() - 1);
+ String[] parts = str.split("/");
+ if (parts.length != 2) {
+ throw new IllegalArgumentException("Invalid service-binding URI: " + uri);
+ }
+ names[1] = parts[0];
+ names[2] = parts[1];
+ } else if (str.startsWith("service(") && str.endsWith(")")) {
+ str = str.substring("service(".length(), str.length() - 1);
+ names[1] = str;
+ } else {
+ throw new IllegalArgumentException("Invalid component/service/binding URI: " + uri);
+ }
+ }
+ return names;
+ }
+
+ private boolean matches(String target, String uri) {
+ String[] parts1 = parse(target);
+ String[] parts2 = parse(uri);
+ for (int i = 0; i < parts1.length; i++) {
+ if (parts1[i] == null || parts1[i].equals(parts2[i])) {
+ continue;
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
public List<Endpoint2> findEndpoint(EndpointReference2 endpointReference) {
List<Endpoint2> foundEndpoints = new ArrayList<Endpoint2>();
@@ -138,17 +182,11 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry {
for (Object v : map.values()) {
Endpoint2 endpoint = (Endpoint2)v;
// TODO: implement more complete matching
- if (endpoint.getComponentName().equals(targetEndpoint.getComponentName())) {
- if ((targetEndpoint.getServiceName() == null) || (targetEndpoint.getServiceName().equals(endpoint
- .getServiceName()))) {
- foundEndpoints.add(endpoint);
- logger.info("EndpointRegistry: Found endpoint with matching service - " + endpoint);
- } else if (targetEndpoint.getServiceName() == null) {
- foundEndpoints.add(endpoint);
- logger.info("EndpointRegistry: Found endpoint with matching component - " + endpoint);
- }
- // else the service name doesn't match
+ if (matches(targetEndpoint.getURI(), endpoint.getURI())) {
+ foundEndpoints.add(endpoint);
+ logger.info("EndpointRegistry: Found endpoint with matching service - " + endpoint);
}
+ // else the service name doesn't match
}
}
return foundEndpoints;
diff --git a/java/sca/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry b/java/sca/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
index 5a7bafd7f6..f23acf5010 100644
--- a/java/sca/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
+++ b/java/sca/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
@@ -14,4 +14,4 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpointRegistry;ranking=100,address=228.0.0.100,port=50000,timeout=50 \ No newline at end of file
+org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpointRegistry;ranking=50,address=228.0.0.100,port=50000,timeout=50 \ No newline at end of file