camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From william sundberg <william.sundb...@gmail.com>
Subject Starting and Suspending routes
Date Wed, 19 Sep 2012 06:42:55 GMT
Hi,

after I stop an route it continues to run...
Can someone help me.

ServiceSuspender is the class from: 
http://camel.465427.n5.nabble.com/Starting-and-Suspending-routes-td472016.html
<http://camel.465427.n5.nabble.com/Starting-and-Suspending-routes-td472016.html>  

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-tp5719569.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message