org.apache.camel.spi
Interface ShutdownStrategy

All Superinterfaces:
Service
All Known Implementing Classes:
DefaultShutdownStrategy

public interface ShutdownStrategy
extends Service

Pluggable shutdown strategy executed during shutdown of routes.

Shutting down routes in a reliable and graceful manner is not a trivial task. Therefore Camel provides a pluggable strategy allowing 3rd party to use their own strategy if needed.

The key problem is to stop the input consumers for the routes such that no new messages is coming into Camel. But at the same time still keep the routes running so the existing in flight exchanges can still be run to completion. On top of that there are some in memory components (such as SEDA) which may have pending messages on its in memory queue which we want to run to completion as well, otherwise they will get lost.

Camel provides a default strategy which supports all that that can be used as inspiration for your own strategy.

Version:
See Also:
ShutdownAware

Method Summary
 boolean forceShutdown(Service service)
          Whether a service is forced to shutdown.
 long getTimeout()
          Gets the timeout.
 TimeUnit getTimeUnit()
          Gets the time unit used
 boolean isShutdownNowOnTimeout()
          Whether to force shutdown of all consumers when a timeout occurred.
 boolean isShutdownRoutesInReverseOrder()
          Whether to shutdown routes in reverse order than they where started.
 void setShutdownNowOnTimeout(boolean shutdownNowOnTimeout)
          Sets whether to force shutdown of all consumers when a timeout occurred and thus not all consumers was shutdown within that period.
 void setShutdownRoutesInReverseOrder(boolean shutdownRoutesInReverseOrder)
          Sets whether routes should be shutdown in reverse or the same order as they where started.
 void setTimeout(long timeout)
          Set an timeout to wait for the shutdown to complete.
 void setTimeUnit(TimeUnit timeUnit)
          Set the time unit to use
 void shutdown(CamelContext context, List<RouteStartupOrder> routes)
          Shutdown the routes
 void shutdown(CamelContext context, List<RouteStartupOrder> routes, long timeout, TimeUnit timeUnit)
          Shutdown the routes using a specified timeout instead of the default timeout values
 boolean shutdown(CamelContext context, RouteStartupOrder route, long timeout, TimeUnit timeUnit, boolean abortAfterTimeout)
          Shutdown the route using a specified timeout instead of the default timeout values and supports abortAfterTimeout mode
 void shutdownForced(CamelContext context, List<RouteStartupOrder> routes)
          Shutdown the routes, forcing shutdown being more aggressive, if timeout occurred.
 void suspend(CamelContext context, List<RouteStartupOrder> routes)
          Suspends the routes
 void suspend(CamelContext context, List<RouteStartupOrder> routes, long timeout, TimeUnit timeUnit)
          Suspends the routes using a specified timeout instead of the default timeout values
 
Methods inherited from interface org.apache.camel.Service
start, stop
 

Method Detail

shutdownForced

void shutdownForced(CamelContext context,
                    List<RouteStartupOrder> routes)
                    throws Exception
Shutdown the routes, forcing shutdown being more aggressive, if timeout occurred.

This operation is used when CamelContext is shutting down, to ensure Camel will shutdown if messages seems to be stuck.

Parameters:
context - the camel context
routes - the routes, ordered by the order they was started
Throws:
Exception - is thrown if error shutting down the consumers, however its preferred to avoid this

shutdown

void shutdown(CamelContext context,
              List<RouteStartupOrder> routes)
              throws Exception
Shutdown the routes

Parameters:
context - the camel context
routes - the routes, ordered by the order they was started
Throws:
Exception - is thrown if error shutting down the consumers, however its preferred to avoid this

suspend

void suspend(CamelContext context,
             List<RouteStartupOrder> routes)
             throws Exception
Suspends the routes

Parameters:
context - the camel context
routes - the routes, ordered by the order they was started
Throws:
Exception - is thrown if error suspending the consumers, however its preferred to avoid this

shutdown

void shutdown(CamelContext context,
              List<RouteStartupOrder> routes,
              long timeout,
              TimeUnit timeUnit)
              throws Exception
Shutdown the routes using a specified timeout instead of the default timeout values

Parameters:
context - the camel context
routes - the routes, ordered by the order they was started
timeout - timeout
timeUnit - the unit to use
Throws:
Exception - is thrown if error shutting down the consumers, however its preferred to avoid this

shutdown

boolean shutdown(CamelContext context,
                 RouteStartupOrder route,
                 long timeout,
                 TimeUnit timeUnit,
                 boolean abortAfterTimeout)
                 throws Exception
Shutdown the route using a specified timeout instead of the default timeout values and supports abortAfterTimeout mode

Parameters:
context - the camel context
route - the route
timeout - timeout
timeUnit - the unit to use
abortAfterTimeout - should abort shutdown after timeout
Returns:
true if the route is stopped before the timeout
Throws:
Exception - is thrown if error shutting down the consumer, however its preferred to avoid this

suspend

void suspend(CamelContext context,
             List<RouteStartupOrder> routes,
             long timeout,
             TimeUnit timeUnit)
             throws Exception
Suspends the routes using a specified timeout instead of the default timeout values

Parameters:
context - the camel context
routes - the routes, ordered by the order they was started
timeout - timeout
timeUnit - the unit to use
Throws:
Exception - is thrown if error suspending the consumers, however its preferred to avoid this

setTimeout

void setTimeout(long timeout)
Set an timeout to wait for the shutdown to complete.

Setting a value of 0 or negative will disable timeout and wait until complete (potential blocking forever)

The default timeout unit is SECONDS

Parameters:
timeout - timeout

getTimeout

long getTimeout()
Gets the timeout.

Use 0 or a negative value to disable timeout

The default timeout unit is SECONDS

Returns:
the timeout

setTimeUnit

void setTimeUnit(TimeUnit timeUnit)
Set the time unit to use

Parameters:
timeUnit - the unit to use

getTimeUnit

TimeUnit getTimeUnit()
Gets the time unit used

Returns:
the time unit

setShutdownNowOnTimeout

void setShutdownNowOnTimeout(boolean shutdownNowOnTimeout)
Sets whether to force shutdown of all consumers when a timeout occurred and thus not all consumers was shutdown within that period.

You should have good reasons to set this option to false as it means that the routes keep running and is halted abruptly when CamelContext has been shutdown.

Parameters:
shutdownNowOnTimeout - true to force shutdown, false to leave them running

isShutdownNowOnTimeout

boolean isShutdownNowOnTimeout()
Whether to force shutdown of all consumers when a timeout occurred.

Returns:
force shutdown or not

setShutdownRoutesInReverseOrder

void setShutdownRoutesInReverseOrder(boolean shutdownRoutesInReverseOrder)
Sets whether routes should be shutdown in reverse or the same order as they where started.

Parameters:
shutdownRoutesInReverseOrder - true to shutdown in reverse order

isShutdownRoutesInReverseOrder

boolean isShutdownRoutesInReverseOrder()
Whether to shutdown routes in reverse order than they where started.

This option is by default set to true.

Returns:
true if routes should be shutdown in reverse order.

forceShutdown

boolean forceShutdown(Service service)
Whether a service is forced to shutdown.

Can be used to signal to services that they are no longer allowed to run, such as if a forced shutdown is currently in progress.

For example the Camel RedeliveryErrorHandler uses this information to know if a forced shutdown is in progress, and then break out of redelivery attempts.

Parameters:
service - the service
Returns:
true indicates the service is to be forced to shutdown, false the service can keep running.


Apache CAMEL