Hi

The FAQ
http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html

We should probably add a note to that given FAQ, that stopping a route
from a route is further complicated if you use the current thread
doing so. Its best practice to just flip a flag or some sort of
signals that the route should be stopped. And then continue routing,
to let Camel do its business.

Then the 3rd part can check the flag, and then commence a route stop.

For example using a CountdownLatch

final CountdownLatch latch = new CountdownLatch(1);


camelContext.start();
// wait for latch before stopping
latch.await();
camelContext.stop();


and then from the route you can countdown the latch when you are done
with the routing.



On Fri, Feb 3, 2012 at 10:15 PM, Larry Meadors <larry.mead...@gmail.com> wrote:
> I have what I think is a simple route:
>
>
> public void configure() throws Exception {
>  from(sourceUri)
>  .setHeader(S3Constants.KEY, simple("${header.CamelFileNameOnly}"))
>  .setHeader(S3Constants.CONTENT_LENGTH, simple("${header.CamelFileLength}"))
>  .to(destinationUri);
> }
>
>
> It's just taking files from a directory and copying them to an s3 bucket.
>
> What I'm seeing is that when I start it up, it stops immediately, so I
> end up doing this:
>
>
> // create the route - the parameters are the source, then the destination
> DirectCopyRoute directCopyRoute = new DirectCopyRoute(arg[0], arg[1]);
>
> // create the camel context and start it
> CamelContext camelContext = new DefaultCamelContext();
> camelContext.addRoutes(directCopyRoute);
> camelContext.start();
>
> // give it time to realize it has work to do
> Thread.sleep(1000);
>
>
> If I remove the Thread.sleep call, it just starts and stops.
>
> Adding that seems to make it work, but I'm wondering why?
>
> I'm guessing the "why" is that it takes a bit of time to create the
> list of files to process, and since there is nothing pending to
> process, camel figures it's done what it was supposed to, and shuts
> down - adding the delay gives the file consumer time to create the
> list of files to process, and once it's started, it goes until it's
> done.
>
> It that's the case, it leads to a second question: Will 1 second be
> long enough to work if the source directory contains a LOT of files?
>
> Normally, the directory will only have a few hundred files, but it may
> have a few thousand, and it may be accessing a shared directory over a
> network, so the time required to get a directory listing may vary.
>
> Is there a smarter way to do this?
>
> Larry



-- 
Claus Ibsen
-----------------
FuseSource
Email: cib...@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Reply via email to