Package org.apache.camel.spi
Interface ShutdownStrategy
-
- All Superinterfaces:
AutoCloseable
,Service
,StaticService
public interface ShutdownStrategy extends StaticService
Pluggable shutdown strategy executed during shutdown of Camel and the active 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 shutdown strategy is not intended for Camel end users to use for stopping routes. Instead, useRouteController
viaCamelContext
. 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.- See Also:
ShutdownAware
,RouteController
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description LoggingLevel
getLoggingLevel()
Gets the logging level used for logging shutdown activity (such as starting and stopping routes).long
getTimeout()
Gets the timeout.TimeUnit
getTimeUnit()
Gets the time unit usedboolean
hasTimeoutOccurred()
Whether a timeout has occurred during a shutdown.boolean
isForceShutdown()
Whether the shutdown strategy is forcing to shutdownboolean
isLogInflightExchangesOnTimeout()
Whether to log information about the inflightExchange
s which are still running during a shutdown which didn't complete without the given timeout.boolean
isShutdownNowOnTimeout()
Whether to force shutdown of all consumers when a timeout occurred.boolean
isShutdownRoutesInReverseOrder()
Whether to shutdown routes in reverse order than they were started.boolean
isSuppressLoggingOnTimeout()
Whether Camel should try to suppress logging during shutdown and timeout was triggered, meaning forced shutdown is happening.void
setLoggingLevel(LoggingLevel loggingLevel)
Sets the logging level used for logging shutdown activity (such as starting and stopping routes).void
setLogInflightExchangesOnTimeout(boolean logInflightExchangesOnTimeout)
Sets whether to log information about the inflightExchange
s which are still running during a shutdown which didn't complete without the given timeout.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 were started.void
setSuppressLoggingOnTimeout(boolean suppressLoggingOnTimeout)
Whether Camel should try to suppress logging during shutdown and timeout was triggered, meaning forced shutdown is happening.void
setTimeout(long timeout)
Set a timeout to wait for the shutdown to complete.void
setTimeUnit(TimeUnit timeUnit)
Set the time unit to usevoid
shutdown(CamelContext context, List<RouteStartupOrder> routes)
Shutdown the routesvoid
shutdown(CamelContext context, List<RouteStartupOrder> routes, long timeout, TimeUnit timeUnit)
Shutdown the routes using a specified timeout instead of the default timeout valuesboolean
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 modevoid
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 routesvoid
suspend(CamelContext context, List<RouteStartupOrder> routes, long timeout, TimeUnit timeUnit)
Suspends the routes using a specified timeout instead of the default timeout values
-
-
-
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 whenCamelContext
is shutting down, to ensure Camel will shutdown if messages seems to be stuck.- Parameters:
context
- the camel contextroutes
- the routes, ordered by the order they were 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 contextroutes
- the routes, ordered by the order they were 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 contextroutes
- the routes, ordered by the order they are 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 contextroutes
- the routes, ordered by the order they are startedtimeout
- timeouttimeUnit
- 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 contextroute
- the routetimeout
- timeouttimeUnit
- the unit to useabortAfterTimeout
- 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 contextroutes
- the routes, ordered by the order they were startedtimeout
- timeouttimeUnit
- 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 a timeout to wait for the shutdown to complete. You must set a positive value. If you want to wait (forever) then use a very high value such asLong.MAX_VALUE
The default timeout unit is SECONDS- Parameters:
timeout
- timeout- Throws:
IllegalArgumentException
- if the timeout value is 0 or negative
-
getTimeout
long getTimeout()
Gets the 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
-
setSuppressLoggingOnTimeout
void setSuppressLoggingOnTimeout(boolean suppressLoggingOnTimeout)
Whether Camel should try to suppress logging during shutdown and timeout was triggered, meaning forced shutdown is happening. And during forced shutdown we want to avoid logging errors/warnings et al. in the logs as a side effect of the forced timeout. By default this is false Notice the suppression is a best effort as there may still be some logs coming from 3rd party libraries and whatnot, which Camel cannot control.- Parameters:
suppressLoggingOnTimeout
- true to suppress logging, false to log as usual.
-
isSuppressLoggingOnTimeout
boolean isSuppressLoggingOnTimeout()
Whether Camel should try to suppress logging during shutdown and timeout was triggered, meaning forced shutdown is happening. And during forced shutdown we want to avoid logging errors/warnings et al. in the logs as a side effect of the forced timeout. By default this is false Notice the suppression is a best effort as there may still be some logs coming from 3rd party libraries and whatnot, which Camel cannot control.
-
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 whenCamelContext
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 were started.- Parameters:
shutdownRoutesInReverseOrder
- true to shutdown in reverse order
-
isShutdownRoutesInReverseOrder
boolean isShutdownRoutesInReverseOrder()
Whether to shutdown routes in reverse order than they were started. This option is by default set to true.- Returns:
- true if routes should be shutdown in reverse order.
-
setLogInflightExchangesOnTimeout
void setLogInflightExchangesOnTimeout(boolean logInflightExchangesOnTimeout)
Sets whether to log information about the inflightExchange
s which are still running during a shutdown which didn't complete without the given timeout.- Parameters:
logInflightExchangesOnTimeout
- true to log information about the inflight exchanges, false to not log
-
isLogInflightExchangesOnTimeout
boolean isLogInflightExchangesOnTimeout()
Whether to log information about the inflightExchange
s which are still running during a shutdown which didn't complete without the given timeout.
-
isForceShutdown
boolean isForceShutdown()
Whether the shutdown strategy is forcing to shutdown
-
hasTimeoutOccurred
boolean hasTimeoutOccurred()
Whether a timeout has occurred during a shutdown.
-
getLoggingLevel
LoggingLevel getLoggingLevel()
Gets the logging level used for logging shutdown activity (such as starting and stopping routes). The default logging level is DEBUG.
-
setLoggingLevel
void setLoggingLevel(LoggingLevel loggingLevel)
Sets the logging level used for logging shutdown activity (such as starting and stopping routes). The default logging level is DEBUG.
-
-