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: Starting and Suspending routes
Date Wed, 19 Sep 2012 07:30:18 GMT
Hi

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

On Wed, Sep 19, 2012 at 8:38 AM, william sundberg
<william.sundberg@gmail.com> wrote:
> Hi,
>
> I tried to use the provided code to stop an Route, but it continues to
> execute even after it have been stopped.
>
> Could someone look at this and something that is wrong?
>
> br/William
>
> Test class:
> package com.ServerWatcher;
>
> import com.ServerWatcher.impl.ServiceSuspender;
> import org.apache.camel.Exchange;
> import org.apache.camel.Processor;
> import org.apache.camel.ServiceStatus;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.test.junit4.CamelTestSupport;
> import org.junit.Test;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> /**
>  */
> public class ServerWatcherTest extends CamelTestSupport {
>
>     Logger logger = LoggerFactory.getLogger(ServerWatcherTest.class);
>
>     private void logInfo(final String methodA, final String infoA) {
>         logger.info("[" + methodA + "] " + infoA);
>     }
>
>     public static String ROUTE_ID = "test-server";
>
>    @Override
>     protected RouteBuilder createRouteBuilder() throws Exception {
>         final String METHOD = "createRouteBuilder";
>         logInfo(METHOD, " ***** start *****");
>
>         return new RouteBuilder() {
>
>             @Override
>             public void configure() throws Exception {
>             from("timer://foo?fixedRate=true&period=1000")
>                     .routeId(ROUTE_ID)
>                     .noAutoStartup()
>                     .process(new Processor() {
>                         public void process(final Exchange exchangeA) throws
> Exception {
>                             logProcInfo(exchangeA, 1000);
>                             stopIfStopped(exchangeA);
>                         }})
>                     .log("###runit.1000.done##");
>
>             from("timer://foo?fixedRate=true&period=4000")
>                 .routeId("ROUTE_ID_2")
>                 .process(new Processor() {
>                     public void process(final Exchange exchangeA) throws
> Exception {
>                         logProcInfo(exchangeA, 4000);
>                         ServiceSuspender ss = new
> ServiceSuspender(exchangeA.getContext());
>                         if ( ServiceStatus.Started ==
> ss.getStatusForRoute(ROUTE_ID) ) {
>                             logInfo(METHOD, " ---ROUTE---STOP---" );
>                             ss.suspendOrStopRoute(ROUTE_ID);
>                             logInfo(METHOD, " RouteStatus.After:" +
> ss.getStatusForRoute(ROUTE_ID));
>                         }
>                     }});
>
>             from("timer://foo2?fixedRate=true&period=7000")
>                 .routeId("ROUTE_ID_3")
>                 .process(new Processor() {
>                     public void process(final Exchange exchangeA) throws
> Exception {
>                         logProcInfo(exchangeA, 7000);
>                         ServiceSuspender ss = new
> ServiceSuspender(exchangeA.getContext());
>                         if ( ServiceStatus.Started !=
> ss.getStatusForRoute(ROUTE_ID) ) {
>                             logInfo(METHOD, " ---ROUTE---START---");
>                             ss.resumeRoute(ROUTE_ID);
>                             logInfo(METHOD, " RouteStatus.After:" +
> ss.getStatusForRoute(ROUTE_ID));
>                         }
>                     }});
>
>             }
>
>         };
>     }
>
>     /**
>      *
>      * @param exchangeA
>      */
>     private void stopIfStopped(Exchange exchangeA) throws Exception {
>         ServiceSuspender ss = new ServiceSuspender(exchangeA.getContext());
>         if ( ServiceStatus.Stopped == ss.getStatusForRoute(ROUTE_ID) ) {
>             final String METHOD = "logProcInfo";
>             logInfo(METHOD, "THIS SHOULD NOT HAPPEN!!!");
>             new Exception().printStackTrace();
>
>             exchangeA.getContext().stop();
>         }
>
>     }
>
>     /**
>      *
>      * @param exchangeA
>      */
>     private void logProcInfo(final Exchange exchangeA, int perA) {
>         final String METHOD = "logProcInfo";
>         ServiceSuspender ss = new ServiceSuspender(exchangeA.getContext());
>
>         logInfo(METHOD,
>                 "\n\tCtx:" + exchangeA.getContext() +
>                 ", RouteId:" + ROUTE_ID +
>                 ", RouteStatus:" + ss.getStatusForRoute(ROUTE_ID) +
>                 ", Period:" + perA +
>                 "\n\tRoutes:" + exchangeA.getContext().getRoutes()
>
>         );
>
>     }
>
>     private final int NUM_SEC       = 10;
>     @Test
>     public void testValidateSleeper() throws Exception {
>         final String METHOD = "testValidateSleeper";
>         logInfo(METHOD, " ***** start *****");
>
>         template.sendBody("vm:runit", "starter kicked");
>         Thread.sleep(NUM_SEC * 99000);
>         logInfo(METHOD, " ***** done *****");
>     }
>
>
> } // class: ServerWatcherTest
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Starting-and-Suspending-routes-tp472016p5719568.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



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

Mime
View raw message