Stop+intererupt an existing route

222 views Asked by At

I have a Camel route which is waiting on a lock. Let's simulate it as following:

context.addRoutes(new RouteBuilder() {
    @Override
    public void configure() throws Exception {
        from("timer://foo?period=100")
                .to("direct:bar");
        from("direct:bar")
                .routeId("test")
                .to("log:receive")
                .process(new Processor() {
                    @Override
                    public void process(final Exchange exchange) throws Exception {
                        System.out.println("sleeping indefinitely");
                        try {
                            Thread.sleep(Long.MAX_VALUE);
                        } catch (final InterruptedException exception) {
                            exception.printStackTrace();
                        }
                        System.out.println("not sleeping indefinitely");
                    }
                });
    }
});

At a certain point in time, I want to stop this test route as soon as possible. Is there a way to stop this route while interrupting the thread currently processing this route? I tried stopRoute as below, but this does not seem to interrupt the thread.

context.getRouteController().stopRoute("test", 1, TimeUnit.NANOSECONDS);

I am using Camel version 3.4.x.

0

There are 0 answers