camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Question about Dynamic Router
Date Wed, 27 Apr 2011 18:01:01 GMT
It keep going back until it gets a null.

Regardless if you return a single endpoint or multiple endpoints
separated by comma.

eg 1st return is "a,b"
eg 2nd return is "c"
eg 3rd return is null

To stop you must return null.


On Wed, Apr 27, 2011 at 7:25 PM, adutra <alexdut@gmail.com> wrote:
> According to the documentation, the Dynamic Router should return null to
> indicate no more routings for a given message. But also according to the
> docs, it can alternatively return a comma-separated list of endpoints, in
> which case the router should iterate over them and send a copy of the
> message to each one.
>
> In fact, I was wondering whether those two different situations (no more
> endpoints vs. multiple endpoints) could have been erroneously mixed together
> in the code:
>
> The DynamicRoutingSlipIterator class is used to iterate over the
> comma-separated list of endpoints returned by the dynamic router invocation.
> But in this class, we have this piece of code:
>
> public boolean hasNext(Exchange exchange) {
>    if (current != null && current.hasNext()) {
>        return true;
>    }
>    // evaluate next slip
>    Object routingSlip = slip.evaluate(exchange, Object.class);
>    if (routingSlip == null) {
>        return false;
>    }
>    current = ObjectHelper.createIterator(routingSlip, uriDelimiter);
>    return current != null && current.hasNext();
> }
>
> This behavior does not seem natural. This iterator actually keeps "renewing"
> itself by reinvoking the same condition on the same exchange, instead of
> iterating over the comma-separated list of endpoints returned by one single
> evaluation of the condition. It can only stop if the condition suddenly
> changes and returns null, which in most common situations won't necessarily
> happen. I was rather expecting this:
>
> public boolean hasNext(Exchange exchange) {
>    if (current == null) {
>        // evaluate next slip
>        Object routingSlip = slip.evaluate(exchange, Object.class);
>        if (routingSlip == null) {
>            return false;
>        }
>        current = ObjectHelper.createIterator(routingSlip, uriDelimiter);
>    }
>    return current.hasNext();
> }
>
> Here, the condition is evaluated only once and we have only two possible
> situations:
>
> -it returns null, and it's over;
> -it returns a list of endpoints, and then we iterate over the endpoints
> returned; but once these endpoints have been processed (i.e. a copy of the
> message has been sent to them), everything is over.
>
> Moreover, this would explain why some people have expressed concerns about
> the way the dynamic router treats null values; see for instance this thread:
>
> http://camel.465427.n5.nabble.com/Custom-Router-td3212534.html
>
> I would love to have some opinions on this matter.
>
> Thanks in advance.
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Question-about-Dynamic-Router-tp4344271p4344271.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Mime
View raw message