From 846b8fa2a3853c426f98d42fc49d9bbbd1d92dee Mon Sep 17 00:00:00 2001 From: rfeng Date: Thu, 11 Jun 2009 05:29:44 +0000 Subject: 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 --- .../tribes/ReplicatedEndpointRegistry.java | 58 ++++++++++++++++++---- ...org.apache.tuscany.sca.runtime.EndpointRegistry | 2 +- 2 files changed, 49 insertions(+), 11 deletions(-) (limited to 'java/sca/modules/endpoint-tribes/src/main') 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 findEndpoint(EndpointReference2 endpointReference) { List foundEndpoints = new ArrayList(); @@ -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 -- cgit v1.2.3