org.apache.camel.impl
Class DefaultShutdownStrategy

java.lang.Object
  extended by org.apache.camel.impl.ServiceSupport
      extended by org.apache.camel.impl.DefaultShutdownStrategy
All Implemented Interfaces:
Service, ShutdownStrategy

public class DefaultShutdownStrategy
extends ServiceSupport
implements ShutdownStrategy

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

As this strategy will politely wait until all exchanges has been completed it can potential wait for a long time, and hence why a timeout value can be set. When the timeout triggers you can also specify whether the remainder consumers should be shutdown now or ignore.

Will by default use a timeout of 300 seconds (5 minutes) by which it will shutdown now the remaining consumers. This ensures that when shutting down Camel it at some point eventually will shutdown. This behavior can of course be configured using the setTimeout(long) and setShutdownNowOnTimeout(boolean) methods.

Version:
$Revision: 17192 $

Constructor Summary
DefaultShutdownStrategy()
           
 
Method Summary
protected  void doStart()
           
protected  void doStop()
           
 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.
 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 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
protected  void shutdownNow(Consumer consumer)
          Shutdown the consumer immediately.
protected  void shutdownNow(List<Consumer> consumers)
          Shutdown all the consumers immediately.
protected  void shutdownRoutesNow(List<RouteStartupOrder> routes)
          Shutdown all the consumers immediately.
protected  void suspendNow(SuspendableService service, Consumer consumer)
          Suspends the consumer immediately.
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, removeChildService, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.camel.Service
start, stop
 

Constructor Detail

DefaultShutdownStrategy

public DefaultShutdownStrategy()
Method Detail

shutdown

public void shutdown(CamelContext context,
                     List<RouteStartupOrder> routes)
              throws Exception
Description copied from interface: ShutdownStrategy
Shutdown the routes

Specified by:
shutdown in interface ShutdownStrategy
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

setTimeout

public void setTimeout(long timeout)
Description copied from interface: ShutdownStrategy
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)

Specified by:
setTimeout in interface ShutdownStrategy
Parameters:
timeout - timeout in millis

getTimeout

public long getTimeout()
Description copied from interface: ShutdownStrategy
Gets the timeout.

Use 0 or a negative value to disable timeout

Specified by:
getTimeout in interface ShutdownStrategy
Returns:
the timeout

setTimeUnit

public void setTimeUnit(TimeUnit timeUnit)
Description copied from interface: ShutdownStrategy
Set the time unit to use

Specified by:
setTimeUnit in interface ShutdownStrategy
Parameters:
timeUnit - the unit to use

getTimeUnit

public TimeUnit getTimeUnit()
Description copied from interface: ShutdownStrategy
Gets the time unit used

Specified by:
getTimeUnit in interface ShutdownStrategy
Returns:
the time unit

setShutdownNowOnTimeout

public void setShutdownNowOnTimeout(boolean shutdownNowOnTimeout)
Description copied from interface: ShutdownStrategy
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.

Specified by:
setShutdownNowOnTimeout in interface ShutdownStrategy
Parameters:
shutdownNowOnTimeout - true to force shutdown, false to leave them running

isShutdownNowOnTimeout

public boolean isShutdownNowOnTimeout()
Description copied from interface: ShutdownStrategy
whether to force shutdown of all consumers when a timeout occurred.

Specified by:
isShutdownNowOnTimeout in interface ShutdownStrategy
Returns:
force shutdown or not

shutdownRoutesNow

protected void shutdownRoutesNow(List<RouteStartupOrder> routes)
Shutdown all the consumers immediately.

Parameters:
routes - the routes to shutdown

shutdownNow

protected void shutdownNow(List<Consumer> consumers)
Shutdown all the consumers immediately.

Parameters:
consumers - the consumers to shutdown

shutdownNow

protected void shutdownNow(Consumer consumer)
Shutdown the consumer immediately.

Parameters:
consumer - the consumer to shutdown

suspendNow

protected void suspendNow(SuspendableService service,
                          Consumer consumer)
Suspends the consumer immediately.

Parameters:
service - the suspendable consumer
consumer - the consumer to suspend

doStart

protected void doStart()
                throws Exception
Specified by:
doStart in class ServiceSupport
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Specified by:
doStop in class ServiceSupport
Throws:
Exception


Copyright © 2007-2010 IONA Open Source Community. All Rights Reserved.