You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jean Francois LE BESCONT <jf...@gmail.com> on 2013/04/25 10:48:22 UTC

Detect is a route is started

Hey Folks !

Just a little post to say that it sound tricky to detect if a route is
started or not, the only way I have found is to do :

        Route route = camelContext.getRoute(...);
boolean isRouteStarted =
((org.apache.camel.support.ServiceSupport)route).isStarted();

Bye

Jeff

Re: Detect is a route is started

Posted by Jean Francois LE BESCONT <jf...@gmail.com>.
Thanks Claus for the link  !





2013/4/25 Claus Ibsen <cl...@gmail.com>

> Hi
>
> There is a getRouteStatus method
>
> http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/CamelContext.html#getRouteStatus(java.lang.String)
>
> On Thu, Apr 25, 2013 at 10:48 AM, Jean Francois LE BESCONT
> <jf...@gmail.com> wrote:
> > Hey Folks !
> >
> > Just a little post to say that it sound tricky to detect if a route is
> > started or not, the only way I have found is to do :
> >
> >         Route route = camelContext.getRoute(...);
> > boolean isRouteStarted =
> > ((org.apache.camel.support.ServiceSupport)route).isStarted();
> >
> > Bye
> >
> > Jeff
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cibsen@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>

Re: Detect is a route is started

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

There is a getRouteStatus method
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/CamelContext.html#getRouteStatus(java.lang.String)

On Thu, Apr 25, 2013 at 10:48 AM, Jean Francois LE BESCONT
<jf...@gmail.com> wrote:
> Hey Folks !
>
> Just a little post to say that it sound tricky to detect if a route is
> started or not, the only way I have found is to do :
>
>         Route route = camelContext.getRoute(...);
> boolean isRouteStarted =
> ((org.apache.camel.support.ServiceSupport)route).isStarted();
>
> Bye
>
> Jeff



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Detect is a route is started

Posted by Jean Francois LE BESCONT <jf...@gmail.com>.
I am using it because camel looks to have a strange behavior.

I would like to execute code at the end of (spring/camel) context loading
and if the code execution is OK then start an other route.
( First I download referential data and load it )
( Secondly start route which process file and enrich it with data load
previously).

 For that  I do :

// This route is not started at the begining
from("file://C:/Temp/camel/?noop=true") .routeId("ROUTE_1")
.id("ROUTE_1") .autoStartup(false)
.log("file => ${file:name}") .end();
// This route is executed once and call a processor which load data and
start route 1 from("timer://runOnce?repeatCount=1&delay=1000")
.autoStartup(true)
.process(new MyProcessor()) .end();

And MyProcessor :

public class MyProcessor implements Processor {

static Logger LOG = LoggerFactory.getLogger(MyProcessor.class);


public void process(Exchange exchange) throws Exception {

  LOG.info("start MyProcessor");
  CamelContext camelContext = exchange.getContext();

  Route route = camelContext.getRoute("ROUTE_1");

  boolean isStarted =
((org.apache.camel.support.ServiceSupport)route).isStarted();
  if(isStarted) {
    camelContext.suspendRoute("ROUTE_1", 1,TimeUnit.HOURS);
 }

  LOG.info("resume route 1 ");
  camelContext.resumeRoute("ROUTE_1");

  LOG.info("end MyProcessor");

}
}

 IF I do a test if route is started then the resume (start) really start :

[1) thread #0 - timer://runOnce] MyProcessor                    INFO  start
MyProcessor
[1) thread #0 - timer://runOnce] MyProcessor                    INFO
 resume route 1
[1) thread #0 - timer://runOnce] SpringCamelContext             INFO
 Route: ROUTE_1 started and consuming from:
Endpoint[file://C:/Temp/camel/?noop=true]
[1) thread #0 - timer://runOnce] MyProcessor                    INFO  end
MyProcessor
[ead #2 - file://C:/Temp/camel/] ROUTE_1                        INFO  file
=> AED_20130208122307_00006 - Copy.recycle
[ead #2 - file://C:/Temp/camel/] ROUTE_1                        INFO  file
=> AED_20130208122307_00006.recycle
[ead #2 - file://C:/Temp/camel/] ROUTE_1                        INFO  file
=> AS_20130508122307_73dee092-7.csv

But If I suspend in all case :

public class MyProcessor implements Processor {
[...]
  Route route = camelContext.getRoute("ROUTE_1");
  camelContext.suspendRoute("ROUTE_1", 1,TimeUnit.HOURS);
  LOG.info("resume route 1 ");
  camelContext.resumeRoute("ROUTE_1");
[...]

Then the route is not really started :

[1) thread #0 - timer://runOnce] MyProcessor                    INFO
 resume route 1
[1) thread #0 - timer://runOnce] SpringCamelContext             INFO
 Route: ROUTE_1 resumed and consuming from:
Endpoint[file://C:/Temp/camel/?noop=true]
[1) thread #0 - timer://runOnce] MyProcessor                    INFO  end
MyProcessor
<nothing after >



I am using camel 2.11 / JRE 1.7

Bye

Jeff


2013/4/25 Jean Francois LE BESCONT <jf...@gmail.com>

>
> Hey Folks !
>
> Just a little post to say that it sound tricky to detect if a route is
> started or not, the only way I have found is to do :
>
>         Route route = camelContext.getRoute(...);
> boolean isRouteStarted =
> ((org.apache.camel.support.ServiceSupport)route).isStarted();
>
> Bye
>
> Jeff
>
>