INT-2515 More Orderly Shutdown

* Add beginShutdown() and endShutdown() to OrderlyShutdownCapable
* JMS/AMQP stop listener containers
* TCP (server side)
** after beginShutdown() disallow new connections, drop (log) new messages
** after endShutdown() close server socket
* HTTP (server side)
** after beginShutdown() disallow any new requests (503 Service Unavailable)

* Docbook updates
** What's new section
** Orderly Shutdown section.
This commit is contained in:
Gary Russell
2012-06-19 15:21:53 -04:00
committed by Gunnar Hillert
parent da858b7451
commit ae0abc4f6c
17 changed files with 516 additions and 140 deletions

View File

@@ -421,6 +421,19 @@
seconds).
</para>
</section>
<section id="jmx-mbean-shutdown">
<title>Orderly Shutdown Managed Operation</title>
<para>
The MBean exporter provides a JMX operation to shut down the application
in an orderly manner, intended for use before terminating the JVM.
</para>
<programlisting language="java"><![CDATA[public void stopActiveComponents(boolean force, long howLong)
]]></programlisting>
<para>
Its use and operation are described in <xref linkend="jmx-shutdown"/>.
</para>
</section>
</section>
</section>

View File

@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<section version="5.0" xml:id="jmx-shutdown"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ns5="http://www.w3.org/1999/xhtml"
xmlns:ns4="http://www.w3.org/1998/Math/MathML"
xmlns:ns3="http://www.w3.org/2000/svg"
xmlns:ns="http://docbook.org/ns/docbook">
<title>Orderly Shutdown</title>
<para>
As described in <xref linkend="jmx-mbean-exporter"/>, the MBean exporter provides a JMX operation
<emphasis>stopActiveComponents</emphasis>, which is used to stop the application in an orderly manner. The operation
has two parameters, a boolean and a long. The boolean indicates whether attempts will be made
to stop (interrupt) active threads; in most cases this will be set to <emphasis>false</emphasis> for orderly
shutdown. The long parameter indicates how long (in milliseconds) the operation will wait to allow
in-flight messages to complete. The operation works as follows:
</para>
<para>
The first step calls <classname>beforeShutdown()</classname> on all beans that implement
<classname>OrderlyShutdownCapable</classname>. This allows such components to prepare for shutdown.
Examples of components that implement this interface, and what they do with this call include: JMS and
AMQP message-driven adapters stop their listener containers; TCP server connection factories stop
accepting new connections (while keeping existing connections open); TCP inbound endpoints drop (log)
any new messages received; http inbound endpoints return <emphasis>503 - Service Unavailable</emphasis> for any new
requests.
</para>
<para>
The second step stops any active channels, such as JMS- or AMQP-backed channels.
</para>
<para>
The third step stops all <classname>TaskScheduler</classname>s, preventing any new
scheduled operations (polling etc).
</para>
<para>
The fourth step stops all <classname>TaskExecutor</classname>s, preventing any new
tasks from running.
</para>
<note>
If the shutdown is running from a Spring-managed <classname>TaskExecutor</classname>, shutting down that
executor would cause all the timeout time to be consumed by this step, because the thread won't terminate).
For this reason, either use a dedicated executor (via the shutdownExecutor property on the MBean exporter),
or do not use a Spring-managed executor to invoke this operation.
</note>
<para>
The fifth step stops all <classname>MessageSource</classname>s.
</para>
<para>
The sixth step waits for any remaining time left, as defined by the value of the long parameter passed
in to the operation. This is intended to allow any in-flight messages to complete their journeys. It is
therefore important to select an appropriate timeout when invoking this operation.
</para>
<para>
The seventh step calls <classname>afterShutdown()</classname> on all OrderlyShutdownCapable components.
This allows such components to perform final shutdown tasks (closing all open sockets, for example).
</para>
<note>
If no time is left when we get to step 6, it probably means some thread is hung; in which case, the
operation attempts a forced shutdown on all schedulers and executors before exiting.
</note>
</section>

View File

@@ -8,5 +8,6 @@
<xi:include href="./message-history.xml"/>
<xi:include href="./message-store.xml"/>
<xi:include href="./control-bus.xml"/>
<xi:include href="./shutdown.xml"/>
</chapter>

View File

@@ -1,37 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<chapter xmlns="http://docbook.org/ns/docbook" version="5.0" xml:id="whats-new"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xlink="http://www.w3.org/1999/xlink">
<title>What's new in Spring Integration 2.2?</title>
<para>
This chapter provides an overview of the new features and improvements
that have been introduced with Spring Integration 2.2 If you are interested
in even more detail, please take a look at the Issue Tracker tickets that
were resolved as part of the 2.2 development process:
</para>
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xlink="http://www.w3.org/1999/xlink">
<title>What's new in Spring Integration 2.2?</title>
<para>
This chapter provides an overview of the new features and improvements
that have been introduced with Spring Integration 2.2 If you are interested
in even more detail, please take a look at the Issue Tracker tickets that
were resolved as part of the 2.2 development process:
</para>
<section id="2.2-general">
<title>General</title>
<section id="2.2-spring-31">
<title>Spring 3.1</title>
<para>
Spring Integration now uses Spring 3.1.
</para>
</section>
<section id="2.2-amqp-11">
<title>Spring-AMQP 1.1</title>
<para>
Spring Integration now uses Spring AMQP 1.1. This enables several features
to be used within a Spring Integration application, including...
</para>
<itemizedlist>
<listitem>A fixed reply queue for the outbound gateway</listitem>
<listitem>HA (mirrored) queues</listitem>
<listitem>Publisher Confirms</listitem>
<listitem>Returned Messages</listitem>
<listitem>Support for Dead Letter Exchanges/Dead Letter Queues</listitem>
</itemizedlist>
</section>
<section id="2.2-general">
<title>General</title>
<section id="2.2-spring-31">
<title>Spring 3.1</title>
<para>
Spring Integration now uses Spring 3.1.
</para>
</section>
<section id="2.2-amqp-11">
<title>Spring-AMQP 1.1</title>
<para>
Spring Integration now uses Spring AMQP 1.1. This enables several features
to be used within a Spring Integration application, including...
</para>
<itemizedlist>
<listitem>A fixed reply queue for the outbound gateway</listitem>
<listitem>HA (mirrored) queues</listitem>
<listitem>Publisher Confirms</listitem>
<listitem>Returned Messages</listitem>
<listitem>Support for Dead Letter Exchanges/Dead Letter Queues</listitem>
</itemizedlist>
</section>
<section id="2.2-jdbc-11">
<title>JDBC Adapter - Stored Procedures Components</title>
<para><emphasis>SpEL Support</emphasis></para>
@@ -51,24 +51,34 @@
The Stored Procedure components now provide basic JMX support,
exposing some of their properties as MBeans:
</para>
<itemizedlist>
<listitem>Stored Procedure Name</listitem>
<listitem>Stored Procedure Name Expression</listitem>
<listitem>JdbcCallOperations Cache Statistics</listitem>
</itemizedlist>
</section>
<section id="2.2-tx">
<title>Transaction Synchronization</title>
<para>
When running from a transactional poller,
mail inbound adapters can be configured to update the mailbox only
if the transaction commits.
</para>
</section>
</section>
<itemizedlist>
<listitem>Stored Procedure Name</listitem>
<listitem>Stored Procedure Name Expression</listitem>
<listitem>JdbcCallOperations Cache Statistics</listitem>
</itemizedlist>
</section>
<section id="2.2-tx">
<title>Transaction Synchronization</title>
<para>
When running from a transactional poller,
mail inbound adapters can be configured to update the mailbox only
if the transaction commits.
</para>
</section>
<section id="2.2-shutdown">
<title>Orderly Shutdown</title>
<para>
A method <classname>stopActiveComponents()</classname> has been
added to the IntegrationMBeanExporter. This allows a Spring Integration
application to be shut down in an orderly manner, disallowing new inbound
messages to certain adapters and waiting for some time to allow in-flight
messages to complete.
</para>
</section>
</section>
<section id="2.2-new-components">
<title>New Components</title>
<section id="2.2-new-components">
<title>New Components</title>
<section id="2.2-jpa">
<title>JPA Endpoints</title>
<para>
@@ -94,9 +104,9 @@
For more information please see <xref linkend="jpa"/>
</para>
</section>
</section>
<section id="2.2-framework-refactorings">
<title>Framework Refactoring</title>
</section>
<section id="2.2-framework-refactorings">
<title>Framework Refactoring</title>
</section>
</section>
</chapter>