You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Chris Wolf <cw...@gmail.com> on 2013/03/22 17:23:10 UTC

How can I perform immediate shutdown of a context and all it's routes and services, etc.?

I am implementing some unit tests and if things go wrong I just want
to shutdown ASAP without regard for inconsistent
states, etc.  There's no easy hook in DefaultShutDownStrategy to do
that because you need to know the route
startup order, so I ended up with this convoluted code (that I kick
off in a separate thread). It doesn't work, BTW.

                    DefaultRouteStartupOrder rsuo = null;
                    int startOrder = 0;
                    List<RouteStartupOrder> suo = new
ArrayList<RouteStartupOrder>();
                    List<Route> routes = context.getRoutes();
                    for (Route route : routes) {
                        List<Service> services = route.getServices();
                        for (Service service : services) {
                            if (service instanceof RouteService) {
                                rsuo = new
DefaultRouteStartupOrder(startOrder, route, (RouteService) service);
                                suo.add(rsuo);
                            }
                        }
                        startOrder++;
                    }
                    ShutdownStrategy sds = context.getShutdownStrategy();
                    sds.shutdownForced(context, suo);

I know there must be an easier way, but I haven't found such.  Any ideas?

Thanks,

Chris

Re: How can I perform immediate shutdown of a context and all it's routes and services, etc.?

Posted by Chris Wolf <cw...@gmail.com>.
On Thu, Mar 28, 2013 at 3:36 AM, Claus Ibsen <cl...@gmail.com> wrote:
[...]
>> have expected.  Is there a way to restart
>> the route from the top upon resuming?  Or do you recommend any other
>> "busy work" kind of route to use
>> for RoutePolicy testing?
>>
>
> The route only runs if there is messages available on the seda queue.
> So send a message to the "seda:foo" queue to have it route that
> message.
[...]

I'm new to this, but by now, I should have known that - sorry and
thanks again for the help!

Re: How can I perform immediate shutdown of a context and all it's routes and services, etc.?

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Mar 25, 2013 at 4:50 PM, Chris Wolf <cw...@gmail.com> wrote:
> Claus,
>
> Ok, that worked - thanks a lot.
>
> BTW, the unit test is for testing custom RoutePolicy.  The route in
> the test looks like:
>
> from("seda:foo").routeId("foo").noAutoStartup().routePolicy(policy)
>     .loop(10).copy().delay(1000)
>     .log("*** loop ${property.CamelLoopIndex}")
>     .to("mock:foo");
>
>
> The RoutePolicy suspends the route, then resume it after a period of
> time - it performs this suspend/resume
> cycle in a loop.  I notice that this route, using the loop() method
> only does the 10 iterations and does not
> start from the top again after being resumed, which I guess I should
> have expected.  Is there a way to restart
> the route from the top upon resuming?  Or do you recommend any other
> "busy work" kind of route to use
> for RoutePolicy testing?
>

The route only runs if there is messages available on the seda queue.
So send a message to the "seda:foo" queue to have it route that
message.


> Thanks,
>
>
> Chris
>
> On Sat, Mar 23, 2013 at 4:02 AM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> Just set the shutdown timeout to 1 milli second (or 1 sec) etc. And
>> just call stop on CamelContext.
>>
>> And if you extend the CamelTestSupport classes for your unit tests.
>> There may be a method you can override and return 1 to indiciate 1 sec
>> timeout.
>>
>>
>>
>> On Fri, Mar 22, 2013 at 5:23 PM, Chris Wolf <cw...@gmail.com> wrote:
>>> I am implementing some unit tests and if things go wrong I just want
>>> to shutdown ASAP without regard for inconsistent
>>> states, etc.  There's no easy hook in DefaultShutDownStrategy to do
>>> that because you need to know the route
>>> startup order, so I ended up with this convoluted code (that I kick
>>> off in a separate thread). It doesn't work, BTW.
>>>
>>>                     DefaultRouteStartupOrder rsuo = null;
>>>                     int startOrder = 0;
>>>                     List<RouteStartupOrder> suo = new
>>> ArrayList<RouteStartupOrder>();
>>>                     List<Route> routes = context.getRoutes();
>>>                     for (Route route : routes) {
>>>                         List<Service> services = route.getServices();
>>>                         for (Service service : services) {
>>>                             if (service instanceof RouteService) {
>>>                                 rsuo = new
>>> DefaultRouteStartupOrder(startOrder, route, (RouteService) service);
>>>                                 suo.add(rsuo);
>>>                             }
>>>                         }
>>>                         startOrder++;
>>>                     }
>>>                     ShutdownStrategy sds = context.getShutdownStrategy();
>>>                     sds.shutdownForced(context, suo);
>>>
>>> I know there must be an easier way, but I haven't found such.  Any ideas?
>>>
>>> Thanks,
>>>
>>> Chris
>>
>>
>>
>> --
>> 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



-- 
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: How can I perform immediate shutdown of a context and all it's routes and services, etc.?

Posted by Chris Wolf <cw...@gmail.com>.
Claus,

Ok, that worked - thanks a lot.

BTW, the unit test is for testing custom RoutePolicy.  The route in
the test looks like:

from("seda:foo").routeId("foo").noAutoStartup().routePolicy(policy)
    .loop(10).copy().delay(1000)
    .log("*** loop ${property.CamelLoopIndex}")
    .to("mock:foo");


The RoutePolicy suspends the route, then resume it after a period of
time - it performs this suspend/resume
cycle in a loop.  I notice that this route, using the loop() method
only does the 10 iterations and does not
start from the top again after being resumed, which I guess I should
have expected.  Is there a way to restart
the route from the top upon resuming?  Or do you recommend any other
"busy work" kind of route to use
for RoutePolicy testing?

Thanks,


Chris

On Sat, Mar 23, 2013 at 4:02 AM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> Just set the shutdown timeout to 1 milli second (or 1 sec) etc. And
> just call stop on CamelContext.
>
> And if you extend the CamelTestSupport classes for your unit tests.
> There may be a method you can override and return 1 to indiciate 1 sec
> timeout.
>
>
>
> On Fri, Mar 22, 2013 at 5:23 PM, Chris Wolf <cw...@gmail.com> wrote:
>> I am implementing some unit tests and if things go wrong I just want
>> to shutdown ASAP without regard for inconsistent
>> states, etc.  There's no easy hook in DefaultShutDownStrategy to do
>> that because you need to know the route
>> startup order, so I ended up with this convoluted code (that I kick
>> off in a separate thread). It doesn't work, BTW.
>>
>>                     DefaultRouteStartupOrder rsuo = null;
>>                     int startOrder = 0;
>>                     List<RouteStartupOrder> suo = new
>> ArrayList<RouteStartupOrder>();
>>                     List<Route> routes = context.getRoutes();
>>                     for (Route route : routes) {
>>                         List<Service> services = route.getServices();
>>                         for (Service service : services) {
>>                             if (service instanceof RouteService) {
>>                                 rsuo = new
>> DefaultRouteStartupOrder(startOrder, route, (RouteService) service);
>>                                 suo.add(rsuo);
>>                             }
>>                         }
>>                         startOrder++;
>>                     }
>>                     ShutdownStrategy sds = context.getShutdownStrategy();
>>                     sds.shutdownForced(context, suo);
>>
>> I know there must be an easier way, but I haven't found such.  Any ideas?
>>
>> Thanks,
>>
>> Chris
>
>
>
> --
> 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: How can I perform immediate shutdown of a context and all it's routes and services, etc.?

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

Just set the shutdown timeout to 1 milli second (or 1 sec) etc. And
just call stop on CamelContext.

And if you extend the CamelTestSupport classes for your unit tests.
There may be a method you can override and return 1 to indiciate 1 sec
timeout.



On Fri, Mar 22, 2013 at 5:23 PM, Chris Wolf <cw...@gmail.com> wrote:
> I am implementing some unit tests and if things go wrong I just want
> to shutdown ASAP without regard for inconsistent
> states, etc.  There's no easy hook in DefaultShutDownStrategy to do
> that because you need to know the route
> startup order, so I ended up with this convoluted code (that I kick
> off in a separate thread). It doesn't work, BTW.
>
>                     DefaultRouteStartupOrder rsuo = null;
>                     int startOrder = 0;
>                     List<RouteStartupOrder> suo = new
> ArrayList<RouteStartupOrder>();
>                     List<Route> routes = context.getRoutes();
>                     for (Route route : routes) {
>                         List<Service> services = route.getServices();
>                         for (Service service : services) {
>                             if (service instanceof RouteService) {
>                                 rsuo = new
> DefaultRouteStartupOrder(startOrder, route, (RouteService) service);
>                                 suo.add(rsuo);
>                             }
>                         }
>                         startOrder++;
>                     }
>                     ShutdownStrategy sds = context.getShutdownStrategy();
>                     sds.shutdownForced(context, suo);
>
> I know there must be an easier way, but I haven't found such.  Any ideas?
>
> Thanks,
>
> Chris



-- 
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