From 560e6a5073634a19a76f66f9d923e4be2b4ec641 Mon Sep 17 00:00:00 2001 From: slaws Date: Tue, 8 Dec 2009 15:23:07 +0000 Subject: Add code to repeat endpoint reference matching in the failure case only. Gives the distributed map a chance to settle down and means less arbitrary pauses in test cases. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@888442 13f79535-47bb-0310-9956-ffa450edef68 --- .../tribes/ReplicatedEndpointRegistry.java | 49 +++++++++++++++------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'sca-java-2.x/trunk/modules/endpoint-tribes/src/main') diff --git a/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java b/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java index 9dd98dedfb..9ca5c00d34 100644 --- a/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java +++ b/sca-java-2.x/trunk/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java @@ -293,24 +293,45 @@ public class ReplicatedEndpointRegistry implements EndpointRegistry, LifeCycleLi if (endpointReference.getReference() != null) { Endpoint targetEndpoint = endpointReference.getTargetEndpoint(); - for (Object v : map.values()) { - Endpoint endpoint = (Endpoint)v; - // TODO: implement more complete matching - logger.fine("Matching against - " + endpoint); - if (matches(targetEndpoint.getURI(), endpoint.getURI())) { - MapEntry entry = map.getInternal(endpoint.getURI()); - if (!isLocal(entry)) { - endpoint.setRemote(true); + + // in the failure case we repeat the look up after a short + // delay to take account of tribes replication delays + int repeat = 2; + + while (repeat > 0){ + for (Object v : map.values()) { + Endpoint endpoint = (Endpoint)v; + // TODO: implement more complete matching + logger.fine("Matching against - " + endpoint); + if (matches(targetEndpoint.getURI(), endpoint.getURI())) { + MapEntry entry = map.getInternal(endpoint.getURI()); + if (!isLocal(entry)) { + endpoint.setRemote(true); + } + // if (!entry.isPrimary()) { + ((RuntimeEndpoint) endpoint).bind(registry, this); + // } + foundEndpoints.add(endpoint); + logger.fine("Found endpoint with matching service - " + endpoint); + repeat = 0; + } + // else the service name doesn't match + } + + if (foundEndpoints.size() == 0) { + // the service name doesn't match any endpoints so wait a little and try + // again in case this is caused by tribes synch delays + logger.info("Repeating endpoint reference match - " + endpointReference); + repeat--; + try { + Thread.sleep(1000); + } catch(Exception ex){ + // do nothing } - // if (!entry.isPrimary()) { - ((RuntimeEndpoint) endpoint).bind(registry, this); - // } - foundEndpoints.add(endpoint); - logger.fine("Found endpoint with matching service - " + endpoint); } - // else the service name doesn't match } } + return foundEndpoints; } -- cgit v1.2.3