On Tue, Dec 14, 2010 at 7:05 PM, kaoru <[email protected]> wrote:
>
> Hi guys,
>
>  from the dynamic-router webpage, there is an example:
>
>
> /**
>  * Use this method to compute dynamic where we should route next.
>  *
>  * @param body the message body
>  * @return endpoints to go, or <tt>null</tt> to indicate the end
>  */
> public String slip(String body) {
>    bodies.add(body);
>    invoked++;
>
>    if (invoked == 1) {
>        return "mock:a";
>    } else if (invoked == 2) {
>        return "mock:b,mock:c";
>    } else if (invoked == 3) {
>        return "direct:foo";
>    } else if (invoked == 4) {
>        return "mock:result";
>    }
>
>    // no more so return null
>    return null;
> }
>
>
> But if there are multiple messages, that 'invoked' variable won't be thread
> safe. How can we solve this?
>

The Exchange contains a header with the last endpoint that was
returned/selected. So you can use that to know where you are.
Also you can store the state on the Exchange, which is per Exchange,
and thus thread safe.

But well spotted the example is not thread safe. We should add a note
about it, or improve it :)



>
>
> Thanks
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/dynamicRouter-Thread-safe-issue-tp3305007p3305007.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: [email protected]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Reply via email to