You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/04/09 20:29:52 UTC

svn commit: r646475 - /servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/FlowRegistryImpl.java

Author: gnodet
Date: Wed Apr  9 11:29:51 2008
New Revision: 646475

URL: http://svn.apache.org/viewvc?rev=646475&view=rev
Log:
Refactor the dispatching code a bit

Modified:
    servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/FlowRegistryImpl.java

Modified: servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/FlowRegistryImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/FlowRegistryImpl.java?rev=646475&r1=646474&r2=646475&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/FlowRegistryImpl.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/FlowRegistryImpl.java Wed Apr  9 11:29:51 2008
@@ -46,33 +46,44 @@
             if (exchange.getDestination() == null) {
                 InternalReference target = (InternalReference) exchange.getTarget();
                 assert target != null;
+                boolean match = false;
                 for (InternalEndpoint endpoint : target.choose()) {
-                    for (Flow flow : getServices()) {
-                        if (flow.canDispatch(exchange, endpoint)) {
-                            exchange.setDestination(endpoint);
-                            flow.dispatch(exchange);
-                            return;
-                        }
+                    match = true;
+                    if (internalDispatch(exchange, endpoint, true)) {
+                        return;
                     }
                 }
-                throw new ServiceMixException("Could not dispatch exchange. No flow can handle it.");
+                if (!match) {
+                    throw new ServiceMixException("Could not dispatch exchange. No matching endpoints.");
+                } else {
+                    throw new ServiceMixException("Could not dispatch exchange. No flow can handle it.");
+                }
             } else {
-                for (Flow flow : getServices()) {
-                    if (flow.canDispatch(exchange, exchange.getDestination())) {
-                        flow.dispatch(exchange);
-                        return;
-                    }
+                if (!internalDispatch(exchange, exchange.getDestination())) {
+                    throw new ServiceMixException("Could not dispatch exchange. No flow can handle it.");
                 }
-                throw new ServiceMixException("Could not dispatch exchange. No flow can handle it.");
             }
         } else {
-            for (Flow flow : getServices()) {
-                if (flow.canDispatch(exchange, exchange.getSource())) {
-                    flow.dispatch(exchange);
-                    return;
+            if (!internalDispatch(exchange, exchange.getSource())) {
+                throw new ServiceMixException("Could not dispatch exchange. No flow can handle it.");
+            }
+        }
+    }
+
+    protected boolean internalDispatch(InternalExchange exchange, InternalEndpoint endpoint) {
+        return internalDispatch(exchange, endpoint, false);
+    }
+
+    protected boolean internalDispatch(InternalExchange exchange, InternalEndpoint endpoint, boolean setDestination) {
+        for (Flow flow : getServices()) {
+            if (flow.canDispatch(exchange, endpoint)) {
+                if (setDestination) {
+                    exchange.setDestination(endpoint);
                 }
+                flow.dispatch(exchange);
+                return true;
             }
-            throw new ServiceMixException("Could not dispatch exchange. No flow can handle it.");
         }
+        return false;
     }
 }