camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Lifecycle
Date Wed, 04 Aug 2010 06:37:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Lifecycle">Lifecycle</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (4)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >- {{suspend}} <br>- {{resume}}
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">-
{{shutdown}} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">-
{{remove}} (previously named shutdown) <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >The <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">{{shutdown}}</span>
<span class="diff-added-words"style="background-color: #dfd;">{{remove}}</span>
operation will <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">also</span>
*remove* the route, for example in [JMX|Camel JMX] the route will then be unregistered and
its gone. So only use <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">shutdown</span>
<span class="diff-added-words"style="background-color: #dfd;">remove</span> if
you really want to remove the route. <span class="diff-added-words"style="background-color:
#dfd;">The route must have been stopped before you can remove.</span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">The
{{start}} and {{resume}} operations in [JMX|Camel JMX] checks the state beforehand. So if
a route is stopped and you click {{resume}}, it will know to invoke {{start}}. And likewise
if a route has been suspended and you click {{start}} it knows to {{resume}} instead. This
makes management a bit easier. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >If a route consumer does not support
suspension, it will fallback and stop the route instead. <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Lifecycle-CamelLifecycle"></a>Camel Lifecycle</h2>

<p>Camel uses a simple <em>lifecycle</em> interface called <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/Service.html"
class="external-link" rel="nofollow">Service</a> which has a single start() and stop()
method.</p>

<p>Various classes implement Service such as <a href="/confluence/display/CAMEL/CamelContext"
title="CamelContext">CamelContext</a> along with a number of <a href="/confluence/display/CAMEL/Component"
title="Component">Component</a> and <a href="/confluence/display/CAMEL/Endpoint"
title="Endpoint">Endpoint</a> classes.</p>

<p>When you use Camel you typically have to start the <a href="/confluence/display/CAMEL/CamelContext"
title="CamelContext">CamelContext</a> which will start all the various components
and endpoints and activate the routing rules until the context is stopped again.</p>

<p>If you are working with Spring you may wish to read the <a href="/confluence/display/CAMEL/Spring"
title="Spring">Camel Spring documentation</a>.</p>

<h3><a name="Lifecycle-CamelContextLifecycle"></a>CamelContext Lifecycle</h3>

<p>The <tt>CamelContext</tt> provides methods to control its lifecycle:</p>
<ul class="alternate" type="square">
	<li><tt>start</tt></li>
	<li><tt>stop</tt></li>
	<li><tt>suspend</tt> <b>Camel 2.5</b></li>
	<li><tt>resume</tt> <b>Camel 2.5</b></li>
</ul>


<p>The operations is paired: start/stop and suspend/resume.</p>

<p>Stop is performing a <a href="/confluence/display/CAMEL/Graceful+Shutdown" title="Graceful
Shutdown">Graceful Shutdown</a> which means all its internal state, cache, etc is
cleared. And the routes is being stopped in a graceful manner to ensure messages is given
time to complete. If you start a <tt>CamelContext</tt> after a stop, then its
performing a <em>cold</em> start, recreating all the state, cache etc. again.
</p>

<p>Instead you can use the suspend/resume operations. They will keep the <tt>CamelContext</tt>
<em>warm</em> and only suspend/stop routes using the same <a href="/confluence/display/CAMEL/Graceful+Shutdown"
title="Graceful Shutdown">Graceful Shutdown</a> feature. This ensures messages is
given time to complete.</p>

<p>End users is encouraged to use suspend/resume if you are temporary stopping a Camel
application.</p>

<p>All these operations is available in <a href="/confluence/display/CAMEL/Camel+JMX"
title="Camel JMX">JMX</a> as well, so you can control Camel from a management console.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>If you write unit tests and perform
<em>cold</em> restarts using stop/start then any previously looked up <a href="/confluence/display/CAMEL/Endpoint"
title="Endpoint">Endpoint</a>s etc. is obsolete, and therefore you need to re-lookup
those endpoints again.

<p>Instead use suspend/resume which keeps these <a href="/confluence/display/CAMEL/Endpoint"
title="Endpoint">Endpoint</a>s and therefore you can still use them after resuming.</p></td></tr></table></div>

<h3><a name="Lifecycle-Servicelifecycle"></a>Service lifecycle</h3>

<p>A service (<tt>org.apache.camel.Service</tt>) in Camel adheres to the
following lifecycle states as illustrated in the diagram below:</p>

<p><span class="image-wrap" style=""><img src="/confluence/download/attachments/52927/service_lifecycle.png?version=1&amp;modificationDate=1280729985000"
style="border: 0px solid black" /></span></p>

<p><b>Notice:</b> A service can optimally support suspend/resume by the
<tt>org.apache.camel.SuspendableService</tt>. This means not all services in Camel
supports suspension. It's encouraged that consumers support suspension which allows to suspend/resume
routes.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>The <tt>org.apache.camel.impl.ServiceSupport</tt>
is a good base class to extend for custom services as it offers the basic functionally to
keep track of state. You implement your custom logic in the <tt>doStart</tt>,
<tt>doStop</tt>, <tt>doSuspend</tt>, <tt>doResume</tt>
methods.</td></tr></table></div>

<h3><a name="Lifecycle-Routeslifecycle"></a>Routes lifecycle</h3>

<p>Routes in Camel have the following operations to control its lifecycle</p>

<ul class="alternate" type="square">
	<li><tt>start</tt></li>
	<li><tt>stop</tt></li>
	<li><tt>suspend</tt></li>
	<li><tt>resume</tt></li>
	<li><tt>remove</tt> (previously named shutdown)</li>
</ul>


<p>The <tt>remove</tt> operation will <b>remove</b> the route,
for example in <a href="/confluence/display/CAMEL/Camel+JMX" title="Camel JMX">JMX</a>
the route will then be unregistered and its gone. So only use remove if you really want to
remove the route. The route must have been stopped before you can remove.</p>

<p>The <tt>start</tt> and <tt>resume</tt> operations in <a
href="/confluence/display/CAMEL/Camel+JMX" title="Camel JMX">JMX</a> checks the state
beforehand. So if a route is stopped and you click <tt>resume</tt>, it will know
to invoke <tt>start</tt>. And likewise if a route has been suspended and you click
<tt>start</tt> it knows to <tt>resume</tt> instead. This makes management
a bit easier.</p>

<p>If a route consumer does not support suspension, it will fallback and stop the route
instead.</p>

<h3><a name="Lifecycle-SeeAlso"></a>See Also</h3>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a></li>
	<li><a href="/confluence/display/CAMEL/Architecture" title="Architecture">Architecture</a></li>
	<li><a href="/confluence/display/CAMEL/Camel+JMX" title="Camel JMX">JMX</a></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Lifecycle">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=52927&revisedVersion=4&originalVersion=3">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Lifecycle?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message