public class DefaultShutdownStrategy
extends org.apache.camel.support.service.ServiceSupport
implements org.apache.camel.spi.ShutdownStrategy, org.apache.camel.CamelContextAware
ShutdownStrategy which uses graceful shutdown.
Graceful shutdown ensures that any inflight and pending messages will be taken into account
and it will wait until these exchanges has been completed.
This strategy will perform graceful shutdown in two steps:
setTimeout(long) and
setShutdownNowOnTimeout(boolean) methods.
Routes will by default be shutdown in the reverse order of which they where started.
You can customize this using the setShutdownRoutesInReverseOrder(boolean) method.
After route consumers have been shutdown, then any ShutdownPrepared services on the routes
is being prepared for shutdown, by invoking ShutdownPrepared.prepareShutdown(boolean,boolean) which
force=false.
Then if a timeout occurred and the strategy has been configured with shutdown-now on timeout, then
the strategy performs a more aggressive forced shutdown, by forcing all consumers to shutdown
and then invokes ShutdownPrepared.prepareShutdown(boolean,boolean) with force=true
on the services. This allows the services to know they should force shutdown now.
When timeout occurred and a forced shutdown is happening, then there may be threads/tasks which are
still inflight which may be rejected continued being routed. By default this can cause WARN and ERRORs
to be logged. The option setSuppressLoggingOnTimeout(boolean) can be used to suppress these
logs, so they are logged at TRACE level instead.
Also when a timeout occurred then information about the inflight exchanges is logged, if isLogInflightExchangesOnTimeout()
is enabled (is by default). This allows end users to known where these inflight exchanges currently are in the route(s),
and how long time they have been inflight.
This information can also be obtained from the InflightRepository
at all time during runtime.| Constructor and Description |
|---|
DefaultShutdownStrategy() |
DefaultShutdownStrategy(org.apache.camel.CamelContext camelContext) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doShutdown() |
protected boolean |
doShutdown(org.apache.camel.CamelContext context,
List<org.apache.camel.spi.RouteStartupOrder> routes,
long timeout,
TimeUnit timeUnit,
boolean suspendOnly,
boolean abortAfterTimeout,
boolean forceShutdown) |
protected void |
doStart() |
protected void |
doStop() |
boolean |
forceShutdown(org.apache.camel.Service service) |
org.apache.camel.CamelContext |
getCamelContext() |
Future<?> |
getCurrentShutdownTaskFuture() |
protected static int |
getPendingInflightExchanges(org.apache.camel.spi.RouteStartupOrder order)
Calculates the total number of inflight exchanges for the given route
|
long |
getTimeout() |
TimeUnit |
getTimeUnit() |
boolean |
hasTimeoutOccurred() |
boolean |
isLogInflightExchangesOnTimeout() |
boolean |
isShutdownNowOnTimeout() |
boolean |
isShutdownRoutesInReverseOrder() |
boolean |
isSuppressLoggingOnTimeout() |
protected void |
logInflightExchanges(org.apache.camel.CamelContext camelContext,
List<org.apache.camel.spi.RouteStartupOrder> routes,
boolean infoLevel)
Logs information about the inflight exchanges
|
void |
setCamelContext(org.apache.camel.CamelContext camelContext) |
void |
setLogInflightExchangesOnTimeout(boolean logInflightExchangesOnTimeout) |
void |
setShutdownNowOnTimeout(boolean shutdownNowOnTimeout) |
void |
setShutdownRoutesInReverseOrder(boolean shutdownRoutesInReverseOrder) |
void |
setSuppressLoggingOnTimeout(boolean suppressLoggingOnTimeout) |
void |
setTimeout(long timeout) |
void |
setTimeUnit(TimeUnit timeUnit) |
void |
shutdown(org.apache.camel.CamelContext context,
List<org.apache.camel.spi.RouteStartupOrder> routes) |
void |
shutdown(org.apache.camel.CamelContext context,
List<org.apache.camel.spi.RouteStartupOrder> routes,
long timeout,
TimeUnit timeUnit) |
boolean |
shutdown(org.apache.camel.CamelContext context,
org.apache.camel.spi.RouteStartupOrder route,
long timeout,
TimeUnit timeUnit,
boolean abortAfterTimeout) |
void |
shutdownForced(org.apache.camel.CamelContext context,
List<org.apache.camel.spi.RouteStartupOrder> routes) |
protected void |
shutdownNow(String routeId,
org.apache.camel.Consumer consumer)
Shutdown the consumer immediately.
|
protected void |
shutdownNow(String routeId,
List<org.apache.camel.Consumer> consumers)
Shutdown all the consumers immediately.
|
protected void |
shutdownRoutesNow(List<org.apache.camel.spi.RouteStartupOrder> routes)
Shutdown all the consumers immediately.
|
void |
suspend(org.apache.camel.CamelContext context,
List<org.apache.camel.spi.RouteStartupOrder> routes) |
void |
suspend(org.apache.camel.CamelContext context,
List<org.apache.camel.spi.RouteStartupOrder> routes,
long timeout,
TimeUnit timeUnit) |
protected void |
suspendNow(String routeId,
org.apache.camel.Consumer consumer)
Suspends/stops the consumer immediately.
|
build, doBuild, doInit, doResume, doSuspend, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspendpublic DefaultShutdownStrategy()
public DefaultShutdownStrategy(org.apache.camel.CamelContext camelContext)
public void shutdown(org.apache.camel.CamelContext context,
List<org.apache.camel.spi.RouteStartupOrder> routes)
throws Exception
shutdown in interface org.apache.camel.spi.ShutdownStrategyExceptionpublic void shutdownForced(org.apache.camel.CamelContext context,
List<org.apache.camel.spi.RouteStartupOrder> routes)
throws Exception
shutdownForced in interface org.apache.camel.spi.ShutdownStrategyExceptionpublic void suspend(org.apache.camel.CamelContext context,
List<org.apache.camel.spi.RouteStartupOrder> routes)
throws Exception
suspend in interface org.apache.camel.spi.ShutdownStrategyExceptionpublic void shutdown(org.apache.camel.CamelContext context,
List<org.apache.camel.spi.RouteStartupOrder> routes,
long timeout,
TimeUnit timeUnit)
throws Exception
shutdown in interface org.apache.camel.spi.ShutdownStrategyExceptionpublic boolean shutdown(org.apache.camel.CamelContext context,
org.apache.camel.spi.RouteStartupOrder route,
long timeout,
TimeUnit timeUnit,
boolean abortAfterTimeout)
throws Exception
shutdown in interface org.apache.camel.spi.ShutdownStrategyExceptionpublic void suspend(org.apache.camel.CamelContext context,
List<org.apache.camel.spi.RouteStartupOrder> routes,
long timeout,
TimeUnit timeUnit)
throws Exception
suspend in interface org.apache.camel.spi.ShutdownStrategyExceptionprotected boolean doShutdown(org.apache.camel.CamelContext context,
List<org.apache.camel.spi.RouteStartupOrder> routes,
long timeout,
TimeUnit timeUnit,
boolean suspendOnly,
boolean abortAfterTimeout,
boolean forceShutdown)
throws Exception
Exceptionpublic boolean forceShutdown(org.apache.camel.Service service)
forceShutdown in interface org.apache.camel.spi.ShutdownStrategypublic boolean hasTimeoutOccurred()
hasTimeoutOccurred in interface org.apache.camel.spi.ShutdownStrategypublic void setTimeout(long timeout)
setTimeout in interface org.apache.camel.spi.ShutdownStrategypublic long getTimeout()
getTimeout in interface org.apache.camel.spi.ShutdownStrategypublic void setTimeUnit(TimeUnit timeUnit)
setTimeUnit in interface org.apache.camel.spi.ShutdownStrategypublic TimeUnit getTimeUnit()
getTimeUnit in interface org.apache.camel.spi.ShutdownStrategypublic void setShutdownNowOnTimeout(boolean shutdownNowOnTimeout)
setShutdownNowOnTimeout in interface org.apache.camel.spi.ShutdownStrategypublic boolean isShutdownNowOnTimeout()
isShutdownNowOnTimeout in interface org.apache.camel.spi.ShutdownStrategypublic boolean isShutdownRoutesInReverseOrder()
isShutdownRoutesInReverseOrder in interface org.apache.camel.spi.ShutdownStrategypublic void setShutdownRoutesInReverseOrder(boolean shutdownRoutesInReverseOrder)
setShutdownRoutesInReverseOrder in interface org.apache.camel.spi.ShutdownStrategypublic boolean isSuppressLoggingOnTimeout()
isSuppressLoggingOnTimeout in interface org.apache.camel.spi.ShutdownStrategypublic void setSuppressLoggingOnTimeout(boolean suppressLoggingOnTimeout)
setSuppressLoggingOnTimeout in interface org.apache.camel.spi.ShutdownStrategypublic boolean isLogInflightExchangesOnTimeout()
isLogInflightExchangesOnTimeout in interface org.apache.camel.spi.ShutdownStrategypublic void setLogInflightExchangesOnTimeout(boolean logInflightExchangesOnTimeout)
setLogInflightExchangesOnTimeout in interface org.apache.camel.spi.ShutdownStrategypublic org.apache.camel.CamelContext getCamelContext()
getCamelContext in interface org.apache.camel.CamelContextAwarepublic void setCamelContext(org.apache.camel.CamelContext camelContext)
setCamelContext in interface org.apache.camel.CamelContextAwarepublic Future<?> getCurrentShutdownTaskFuture()
protected void shutdownRoutesNow(List<org.apache.camel.spi.RouteStartupOrder> routes)
routes - the routes to shutdownprotected void shutdownNow(String routeId, List<org.apache.camel.Consumer> consumers)
routeId - the route id to suspendconsumers - the consumers to shutdownprotected void shutdownNow(String routeId, org.apache.camel.Consumer consumer)
routeId - the route id to suspendconsumer - the consumer to shutdownprotected void suspendNow(String routeId, org.apache.camel.Consumer consumer)
routeId - the route id to suspendconsumer - the consumer to suspendprotected void doStart()
throws Exception
doStart in class org.apache.camel.support.service.ServiceSupportExceptionprotected void doStop()
throws Exception
doStop in class org.apache.camel.support.service.ServiceSupportExceptionprotected void doShutdown()
throws Exception
doShutdown in class org.apache.camel.support.service.ServiceSupportExceptionprotected static int getPendingInflightExchanges(org.apache.camel.spi.RouteStartupOrder order)
order - the routeprotected void logInflightExchanges(org.apache.camel.CamelContext camelContext,
List<org.apache.camel.spi.RouteStartupOrder> routes,
boolean infoLevel)
infoLevel - true to log at INFO level, false to log at DEBUG levelApache Camel