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 Mon, 02 Aug 2010 06:17: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 (3)</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" >h3. Service lifecycle <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >A service <span class="diff-added-words"style="background-color:
#dfd;">({{org.apache.camel.Service}})</span> in Camel adheres to the following lifecycle
states as illustrated in the diagram below: <br></td></tr>
            <tr><td class="diff-unchanged" > <br>!service_lifecycle.png!
<br> <br></td></tr>
            <tr><td class="diff-changed-lines" >*Notice:* A service can optimally
support suspend/resume by the <span class="diff-changed-words">{{<span class="diff-added-chars"style="background-color:
#dfd;">org.apache.camel.</span>SuspendableService}}.</span> This means not
all services in Camel supports suspension. It&#39;s encouraged that consumers support
suspension which allows to suspend/resume routes. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{tip:extend
ServiceSupport} <br>The {{org.apache.camel.impl.ServiceSupport}} 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 {{doStart}}, {{doStop}}, {{doSuspend}}, {{doResume}}
methods. <br>{tip} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Routes lifecycle <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=1280657076012"
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>shutdown</tt></li>
</ul>


<p>The <tt>shutdown</tt> operation will also <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 shutdown if you really want
to remove the route.</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=3&originalVersion=2">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