You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by bu...@apache.org on 2012/11/15 14:10:46 UTC

svn commit: r838430 [8/12] - in /websites/staging/mina/trunk/content: ./ mina-project/ mina-project/userguide/ mina-project/userguide/ch1-getting-started/ mina-project/userguide/ch10-executor-filter/ mina-project/userguide/ch11-ssl-filter/ mina-project...

Added: websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/ch3-service.html
==============================================================================
--- websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/ch3-service.html (added)
+++ websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/ch3-service.html Thu Nov 15 13:10:37 2012
@@ -0,0 +1,178 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+	<title>Chapter 3 - Service &mdash; Apache MINA</title>
+	
+		<link href="./../../../css/common.css" rel="stylesheet" type="text/css">
+		<link href="./../../../css/mina.css" rel="stylesheet" type="text/css">
+	
+</head>
+  <body>
+    <div id="container">
+      <div id="header">
+        <div id="subProjectsNavBar">
+          <a href="./../../../">
+            
+              <strong>Apache MINA Project</strong>
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../mina/index.html">
+            
+              MINA
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../asyncweb/index.html">
+            
+              AsyncWeb
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../ftpserver/index.html">
+            
+              FtpServer
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../sshd/index.html">
+            
+              SSHD
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../vysper/index.html">
+            
+              Vysper
+            
+          </a>
+        </div><!-- subProjectsNavBar -->
+      </div><!-- header -->
+      <div id="content">
+        <div id="leftColumn">
+                              
+          
+          
+          
+          
+          
+            <div id="navigation">
+
+    <h5>Latest Downloads</h5>
+    <ul>
+        <li><a href="./../../../downloads-mina.html">Mina 2.0.7</a></li>
+        <li><a href="./../../../downloads-ftpserver.html">FtpServer 1.0.6</a></li>
+        <li><a href="./../../../downloads-sshd.html">SSHD 0.8.0</a></li>
+        <li><a href="./../../../downloads-vysper.html">Vysper 0.7</a></li>
+    </ul>
+    <h5>Projects</h5>
+    <ul>
+        <li><a href="./../../../mina/index.html">MINA</a></li>
+        <li><a href="./../../../asyncweb/index.html">AsyncWeb</a></li>
+        <li><a href="./../../../ftpserver/index.html">FtpServer</a></li>
+        <li><a href="./../../../sshd/index.html">SSHD</a></li>
+        <li><a href="./../../../vysper/index.html">Vysper</a></li>
+    </ul>
+
+    <h5>Community</h5>
+    <ul>
+      <li><a href="./../../../contributors.html" class="external-link" rel="nofollow">Team</a></li>
+      <li><a href="http://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a></li>
+      <li><a href="http://www.apache.org/foundation/contributing.html" class="external-link" rel="nofollow">Contributing</a></li>
+      <li><a href="http://www.apache.org/" title="Apache Software Foundation" class="external-link" rel="nofollow">ASF main site</a></li>
+      <li><a href="http://www.apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a></li>
+      <li><a href="http://www.apache.org/foundation/sponsorship.html" title="The ASF sponsorship program" class="external-link" rel="nofollow">Sponsorship program</a></li>
+      <li><a href="http://www.apache.org/security/" class="external-link" rel="nofollow">Security</a></li>
+    </ul>
+
+    <h3><a name="Navigation-Upcoming"></a>Upcoming</h3>
+
+</div>
+
+<!-- navigation -->
+          
+        </div><!-- leftColumn -->
+      <div id="rightColumn">
+
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="../ch2-basics/ch2-basics.html">Chapter 2 - Basics</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="../user-guide-toc.html">User Guide</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="../ch4-session/ch4-session.html">Chapter 4 - Session</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+<h1 id="chapter-3-ioservice">Chapter 3 - IoService</h1>
+<p>A <strong>MINA</strong> <em>IoService</em> - as seen in the <a href="../ch2-basics/application-architecture.html">application architecture</a> chapter, is the base class supporting all the <strong>IO</strong> services, either from the server side or the client side. </p>
+<p>It will handle all the interaction with your application, and with the remote peer, send and receive messages, manage sessions, conections, etc.</p>
+<p>It's an interface, which is implemented as an <em>IoAcceptor</em> for the server side, and <em>IoConnector</em> for the client side.</p>
+<p>We will expose the interface in those chapters :</p>
+<ul>
+<li><a href="io-service.html">IoService Introduction</a></li>
+<li><a href="io-service-details.html">IoService Details</a></li>
+<li><a href="acceptor.html">IoAcceptor</a></li>
+<li><a href="connector.html">IoConnector</a></li>
+</ul>
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="../ch2-basics/ch2-basics.html">Chapter 2 - Basics</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="../user-guide-toc.html">User Guide</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="../ch4-session/ch4-session.html">Chapter 4 - Session</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+                </div><!-- rightColumn -->
+                <div id="endContent"></div>
+            </div><!-- content -->
+            <div id="footer">&copy; 2003-2012, <a href="http://www.apache.org">The Apache Software Foundation</a> - <a href="./../../../privacy-policy.html">Privacy Policy</a><br />
+                Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
+                Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
+            </div>
+        </div><!-- container -->
+    </body>
+</html>
+

Added: websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/connector.html
==============================================================================
--- websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/connector.html (added)
+++ websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/connector.html Thu Nov 15 13:10:37 2012
@@ -0,0 +1,182 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+	<title>Chapter 9 - Connector &mdash; Apache MINA</title>
+	
+		<link href="./../../../css/common.css" rel="stylesheet" type="text/css">
+		<link href="./../../../css/mina.css" rel="stylesheet" type="text/css">
+	
+</head>
+  <body>
+    <div id="container">
+      <div id="header">
+        <div id="subProjectsNavBar">
+          <a href="./../../../">
+            
+              <strong>Apache MINA Project</strong>
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../mina/index.html">
+            
+              MINA
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../asyncweb/index.html">
+            
+              AsyncWeb
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../ftpserver/index.html">
+            
+              FtpServer
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../sshd/index.html">
+            
+              SSHD
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../vysper/index.html">
+            
+              Vysper
+            
+          </a>
+        </div><!-- subProjectsNavBar -->
+      </div><!-- header -->
+      <div id="content">
+        <div id="leftColumn">
+                              
+          
+          
+          
+          
+          
+            <div id="navigation">
+
+    <h5>Latest Downloads</h5>
+    <ul>
+        <li><a href="./../../../downloads-mina.html">Mina 2.0.7</a></li>
+        <li><a href="./../../../downloads-ftpserver.html">FtpServer 1.0.6</a></li>
+        <li><a href="./../../../downloads-sshd.html">SSHD 0.8.0</a></li>
+        <li><a href="./../../../downloads-vysper.html">Vysper 0.7</a></li>
+    </ul>
+    <h5>Projects</h5>
+    <ul>
+        <li><a href="./../../../mina/index.html">MINA</a></li>
+        <li><a href="./../../../asyncweb/index.html">AsyncWeb</a></li>
+        <li><a href="./../../../ftpserver/index.html">FtpServer</a></li>
+        <li><a href="./../../../sshd/index.html">SSHD</a></li>
+        <li><a href="./../../../vysper/index.html">Vysper</a></li>
+    </ul>
+
+    <h5>Community</h5>
+    <ul>
+      <li><a href="./../../../contributors.html" class="external-link" rel="nofollow">Team</a></li>
+      <li><a href="http://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a></li>
+      <li><a href="http://www.apache.org/foundation/contributing.html" class="external-link" rel="nofollow">Contributing</a></li>
+      <li><a href="http://www.apache.org/" title="Apache Software Foundation" class="external-link" rel="nofollow">ASF main site</a></li>
+      <li><a href="http://www.apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a></li>
+      <li><a href="http://www.apache.org/foundation/sponsorship.html" title="The ASF sponsorship program" class="external-link" rel="nofollow">Sponsorship program</a></li>
+      <li><a href="http://www.apache.org/security/" class="external-link" rel="nofollow">Security</a></li>
+    </ul>
+
+    <h3><a name="Navigation-Upcoming"></a>Upcoming</h3>
+
+</div>
+
+<!-- navigation -->
+          
+        </div><!-- leftColumn -->
+      <div id="rightColumn">
+
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="../ch8-acceptor/ch8-acceptor.html">Chapter 8 - Acceptor</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="../user-guide-toc.html">User Guide</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="../ch10-iobuffer/ch10-iobuffer.html">Chapter 10 - IoBuffer</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+<h1 id="chapter-9-connector">Chapter 9 - Connector</h1>
+<p>For client applications, you need to implement an implementation of the IoConnector interface.</p>
+<h2 id="ioconnector">IoConnector</h2>
+<p>As we have to use an IoAcceptor for servers, you have to implement the IoConnector. Again, we have many implementation classes :</p>
+<ul>
+<li><strong>NioSocketConnector</strong> : the non-blocking Socket transport Connector</li>
+<li><strong>NioDatagramConnector</strong> : the non-blocking UDP transport * Connector*</li>
+<li><strong>AprSocketConnector</strong> : the blocking Socket transport * Connector*, based on APR</li>
+<li><strong>ProxyConnector</strong> : a Connector providing proxy support</li>
+<li><strong>SerialConnector</strong> : a Connector for a serial transport</li>
+<li><strong>VmPipeConnector</strong> : the in-VM * Connector*</li>
+</ul>
+<p>Just pick the one that fit your need.</p>
+<p>Here is the class diagram for the IoConnector interfaces and classes :</p>
+<p><img alt="" src="../../../staticresources/images/mina/IoServiceConnector.png" /></p>
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="../ch8-acceptor/ch8-acceptor.html">Chapter 8 - Acceptor</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="../user-guide-toc.html">User Guide</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="../ch10-iobuffer/ch10-iobuffer.html">Chapter 10 - IoBuffer</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+                </div><!-- rightColumn -->
+                <div id="endContent"></div>
+            </div><!-- content -->
+            <div id="footer">&copy; 2003-2012, <a href="http://www.apache.org">The Apache Software Foundation</a> - <a href="./../../../privacy-policy.html">Privacy Policy</a><br />
+                Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
+                Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
+            </div>
+        </div><!-- container -->
+    </body>
+</html>
+

Added: websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/io-service-details.html
==============================================================================
--- websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/io-service-details.html (added)
+++ websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/io-service-details.html Thu Nov 15 13:10:37 2012
@@ -0,0 +1,201 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+	<title>IO Service &mdash; Apache MINA</title>
+	
+		<link href="./../../../css/common.css" rel="stylesheet" type="text/css">
+		<link href="./../../../css/mina.css" rel="stylesheet" type="text/css">
+	
+</head>
+  <body>
+    <div id="container">
+      <div id="header">
+        <div id="subProjectsNavBar">
+          <a href="./../../../">
+            
+              <strong>Apache MINA Project</strong>
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../mina/index.html">
+            
+              MINA
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../asyncweb/index.html">
+            
+              AsyncWeb
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../ftpserver/index.html">
+            
+              FtpServer
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../sshd/index.html">
+            
+              SSHD
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../vysper/index.html">
+            
+              Vysper
+            
+          </a>
+        </div><!-- subProjectsNavBar -->
+      </div><!-- header -->
+      <div id="content">
+        <div id="leftColumn">
+                              
+          
+          
+          
+          
+          
+            <div id="navigation">
+
+    <h5>Latest Downloads</h5>
+    <ul>
+        <li><a href="./../../../downloads-mina.html">Mina 2.0.7</a></li>
+        <li><a href="./../../../downloads-ftpserver.html">FtpServer 1.0.6</a></li>
+        <li><a href="./../../../downloads-sshd.html">SSHD 0.8.0</a></li>
+        <li><a href="./../../../downloads-vysper.html">Vysper 0.7</a></li>
+    </ul>
+    <h5>Projects</h5>
+    <ul>
+        <li><a href="./../../../mina/index.html">MINA</a></li>
+        <li><a href="./../../../asyncweb/index.html">AsyncWeb</a></li>
+        <li><a href="./../../../ftpserver/index.html">FtpServer</a></li>
+        <li><a href="./../../../sshd/index.html">SSHD</a></li>
+        <li><a href="./../../../vysper/index.html">Vysper</a></li>
+    </ul>
+
+    <h5>Community</h5>
+    <ul>
+      <li><a href="./../../../contributors.html" class="external-link" rel="nofollow">Team</a></li>
+      <li><a href="http://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a></li>
+      <li><a href="http://www.apache.org/foundation/contributing.html" class="external-link" rel="nofollow">Contributing</a></li>
+      <li><a href="http://www.apache.org/" title="Apache Software Foundation" class="external-link" rel="nofollow">ASF main site</a></li>
+      <li><a href="http://www.apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a></li>
+      <li><a href="http://www.apache.org/foundation/sponsorship.html" title="The ASF sponsorship program" class="external-link" rel="nofollow">Sponsorship program</a></li>
+      <li><a href="http://www.apache.org/security/" class="external-link" rel="nofollow">Security</a></li>
+    </ul>
+
+    <h3><a name="Navigation-Upcoming"></a>Upcoming</h3>
+
+</div>
+
+<!-- navigation -->
+          
+        </div><!-- leftColumn -->
+      <div id="rightColumn">
+
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="io-service.html">IoService Introduction</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="ch3-service.html">Chapter 3 - Service</a>
+		
+        </div>
+        <div class="nav_next">
+        
+			&nbsp;
+        
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+<h1 id="ioservice-details">IoService Details</h1>
+<p><em>IoService</em> is an interface that is implemented by the two most important classes in <strong>MINA</strong> :</p>
+<ul>
+<li>IoAcceptor</li>
+<li>IoConnector</li>
+</ul>
+<p>In order to build a server, you need to select an implementation of the <em>IoAcceptor</em> interface. For client applications, you need to implement an implementation of the <em>IoConnector</em> interface.</p>
+<h2 id="ioacceptor">IoAcceptor</h2>
+<p>Basically, this interface is named because of the <em>accept()</em> method, responsible for the creation of new connections between a client and the server. The server accepts incoming connection requests.</p>
+<p>At some point, we could have named this interface 'Server' (and this is the new name in the coming <strong>MINA 3.0</strong>).</p>
+<p>As we may deal with more than one kind of transport (TCP/UDP/...), we have more than one implementation for this interface. It would be very unlikely that you need to implement a new one.</p>
+<p>We have many of those implementing classes</p>
+<ul>
+<li><strong>NioSocketAcceptor</strong> : the non-blocking Socket transport <em>IoAcceptor</em></li>
+<li><strong>NioDatagramAcceptor</strong> : the non-blocking UDP transport <em>IoAcceptor</em></li>
+<li><strong>AprSocketAcceptor</strong> : the blocking Socket transport <em>IoAcceptor</em>, based on APR</li>
+<li><strong>VmPipeSocketAcceptor</strong> : the in-VM <em>IoAcceptor</em></li>
+</ul>
+<p>Just pick the one that fit your need.</p>
+<p>Here is the class diagram for the <em>IoAcceptor</em> interfaces and classes :</p>
+<p><img alt="" src="../../../staticresources/images/mina/IoServiceAcceptor.png" /></p>
+<h2 id="ioconnector">IoConnector</h2>
+<p>As we have to use an <em>IoAcceptor</em> for servers, you have to implement the <em>IoConnector</em> for clients. Again, we have many implementation classes :</p>
+<ul>
+<li><strong>NioSocketConnector</strong> : the non-blocking Socket transport <em>IoConnector</em></li>
+<li><strong>NioDatagramConnector</strong> : the non-blocking UDP transport <em>IoConnector</em></li>
+<li><strong>AprSocketConnector</strong> : the blocking Socket transport <em>IoConnector</em>, based on APR</li>
+<li><strong>ProxyConnector</strong> : a <em>IoConnector</em> providing proxy support</li>
+<li><strong>SerialConnector</strong> : a <em>IoConnector</em> for a serial transport</li>
+<li><strong>VmPipeConnector</strong> : the in-VM <em>IoConnector</em></li>
+</ul>
+<p>Just pick the one that fit your need.</p>
+<p>Here is the class diagram for the <em>IoConnector</em> interfaces and classes :</p>
+<p><img alt="" src="../../../staticresources/images/mina/IoServiceConnector.png" /></p>
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="io-service.html">IoService Introduction</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="ch3-service.html">Chapter 3 - Service</a>
+		
+        </div>
+        <div class="nav_next">
+        
+			&nbsp;
+        
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+                </div><!-- rightColumn -->
+                <div id="endContent"></div>
+            </div><!-- content -->
+            <div id="footer">&copy; 2003-2012, <a href="http://www.apache.org">The Apache Software Foundation</a> - <a href="./../../../privacy-policy.html">Privacy Policy</a><br />
+                Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
+                Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
+            </div>
+        </div><!-- container -->
+    </body>
+</html>
+

Added: websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/io-service.html
==============================================================================
--- websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/io-service.html (added)
+++ websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/io-service.html Thu Nov 15 13:10:37 2012
@@ -0,0 +1,252 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+	<title>IO Service &mdash; Apache MINA</title>
+	
+		<link href="./../../../css/common.css" rel="stylesheet" type="text/css">
+		<link href="./../../../css/mina.css" rel="stylesheet" type="text/css">
+	
+</head>
+  <body>
+    <div id="container">
+      <div id="header">
+        <div id="subProjectsNavBar">
+          <a href="./../../../">
+            
+              <strong>Apache MINA Project</strong>
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../mina/index.html">
+            
+              MINA
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../asyncweb/index.html">
+            
+              AsyncWeb
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../ftpserver/index.html">
+            
+              FtpServer
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../sshd/index.html">
+            
+              SSHD
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../vysper/index.html">
+            
+              Vysper
+            
+          </a>
+        </div><!-- subProjectsNavBar -->
+      </div><!-- header -->
+      <div id="content">
+        <div id="leftColumn">
+                              
+          
+          
+          
+          
+          
+            <div id="navigation">
+
+    <h5>Latest Downloads</h5>
+    <ul>
+        <li><a href="./../../../downloads-mina.html">Mina 2.0.7</a></li>
+        <li><a href="./../../../downloads-ftpserver.html">FtpServer 1.0.6</a></li>
+        <li><a href="./../../../downloads-sshd.html">SSHD 0.8.0</a></li>
+        <li><a href="./../../../downloads-vysper.html">Vysper 0.7</a></li>
+    </ul>
+    <h5>Projects</h5>
+    <ul>
+        <li><a href="./../../../mina/index.html">MINA</a></li>
+        <li><a href="./../../../asyncweb/index.html">AsyncWeb</a></li>
+        <li><a href="./../../../ftpserver/index.html">FtpServer</a></li>
+        <li><a href="./../../../sshd/index.html">SSHD</a></li>
+        <li><a href="./../../../vysper/index.html">Vysper</a></li>
+    </ul>
+
+    <h5>Community</h5>
+    <ul>
+      <li><a href="./../../../contributors.html" class="external-link" rel="nofollow">Team</a></li>
+      <li><a href="http://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a></li>
+      <li><a href="http://www.apache.org/foundation/contributing.html" class="external-link" rel="nofollow">Contributing</a></li>
+      <li><a href="http://www.apache.org/" title="Apache Software Foundation" class="external-link" rel="nofollow">ASF main site</a></li>
+      <li><a href="http://www.apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a></li>
+      <li><a href="http://www.apache.org/foundation/sponsorship.html" title="The ASF sponsorship program" class="external-link" rel="nofollow">Sponsorship program</a></li>
+      <li><a href="http://www.apache.org/security/" class="external-link" rel="nofollow">Security</a></li>
+    </ul>
+
+    <h3><a name="Navigation-Upcoming"></a>Upcoming</h3>
+
+</div>
+
+<!-- navigation -->
+          
+        </div><!-- leftColumn -->
+      <div id="rightColumn">
+
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+			&nbsp;
+        
+        </div>
+        <div class="nav_up">
+        
+            <a href="ch3-service.html">Chapter 3 - Service</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="io-service-details.html">IoService Details</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+<h1 id="ioservice-introduction">IoService Introduction</h1>
+<p><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/core/service/IoService.html">IoService</a> provides basic <strong>I/O</strong> Service and manages <strong>I/O</strong> Sessions within <strong>MINA</strong>. Its one of the most crucial part of <strong>MINA</strong> Architecture. The implementing classes of <em>IoService</em> and child interface, are where most of the low level <strong>I/O</strong> operations are handled.</p>
+<h1 id="ioservice-mind-map">IoService Mind Map</h1>
+<p>Let's try to see what are the responsibilities of the <em>IoService</em> and it implementing class <a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/core/service/AbstractIoService.html">AbstractIoService</a>. Let's take a slightly different approach of first using a <a href="http://en.wikipedia.org/wiki/Mind_map">Mind Map</a> and then jump into the inner working. The Mind Map was created using <a href="http://www.xmind.net/">XMind</a>.</p>
+<p><img alt="" src="../../../staticresources/images/mina/IoService_mindmap.png" /></p>
+<h2 id="responsabilities">Responsabilities</h2>
+<p>As seen in the previous graphic, The <em>IoService</em> has many responsabilities :</p>
+<ul>
+<li>sessions management : Creates and deletes sessions, detect idleness.</li>
+<li>filter chain management : Handles the filtr chain, allowing the user to change the chain on the fly</li>
+<li>handler invocation : Calls the handler when some new message is received, etc </li>
+<li>statistics management : Updates the number of messages sent, bytes sent, and many others</li>
+<li>listeners management : Manages the Listeners a suer can set up</li>
+<li>communication management : Handles the transmission of data, in both side</li>
+</ul>
+<p>All those aspects will be described in the following chapters.</p>
+<h2 id="interface-details">Interface Details</h2>
+<p><em>IoService</em> is the base interface for all the <em>IoConnector</em>'s and <em>IoAcceptor</em>'s that provides <strong>I/O</strong> services and manages <strong>I/O</strong> sessions. The interface has all the functions need to perform <strong>I/O</strong> related operations.</p>
+<p>Lets take a deep dive into the various methods in the interface</p>
+<ul>
+<li>getTransportMetadata()</li>
+<li>addListener()</li>
+<li>removeListener()</li>
+<li>isDisposing()</li>
+<li>isDisposed()</li>
+<li>dispose()</li>
+<li>getHandler()</li>
+<li>setHandler()</li>
+<li>getManagedSessions()</li>
+<li>getManagedSessionCount()</li>
+<li>getSessionConfig()</li>
+<li>getFilterChainBuilder()</li>
+<li>setFilterChainBuilder()</li>
+<li>getFilterChain()</li>
+<li>isActive()</li>
+<li>getActivationTime()</li>
+<li>broadcast()</li>
+<li>setSessionDataStructureFactory()</li>
+<li>getScheduledWriteBytes()</li>
+<li>getScheduledWriteMessages()</li>
+<li>getStatistics()</li>
+</ul>
+<h3 id="gettransportmetadata">getTransportMetadata()</h3>
+<p>This method returns the Transport meta-data the <em>IoAcceptor</em> or <em>IoConnector</em> is running. The typical details include provider name (nio, apr, rxtx), connection type (connectionless/connection oriented) etc.</p>
+<h3 id="addlistener">addListener</h3>
+<p>Allows to add a <em>IoServiceListener</em> to listen to specific events related to <em>IoService</em>.</p>
+<h3 id="removelistener">removeListener</h3>
+<p>Removes specified <em>IoServiceListener</em> attached to this <em>IoService</em>.</p>
+<h3 id="isdisposing">isDisposing</h3>
+<p>This method tells if the service is currently being disposed. As it can take a while, it's useful to know the current status of the service.</p>
+<h3 id="isdisposed">isDisposed</h3>
+<p>This method tells if the service has been disposed. A service will be considered as disposed only when all the resources it has allocated have been released.</p>
+<h3 id="dispose">dispose</h3>
+<p>This method releases all the resources the service has allocated. As it may take a while, the user should check the service status using the <em>isDisposing()</em> and <em>isDisposed()</em> to know if the service is now disposed completely.</p>
+<p>Always call <em>dispose()</em> when you shutdown a service !</p>
+<h3 id="gethandler">getHandler</h3>
+<p>Returns the <em>IoHandler</em> associated with the service.</p>
+<h3 id="sethandler">setHandler</h3>
+<p>Sets the <em>IoHandler</em> that will be responsible for handling all the events for the service. The handler contains your application logic !</p>
+<h3 id="getmanagedsessions">getManagedSessions</h3>
+<p>Returns the map of all sessions which are currently managed by this service. A managed session is a session which is added to the service listener. It will be used to process the idle sessions, and other session aspects, depending on the kind of listeners a user adds to a service.</p>
+<h3 id="getmanagedsessioncount">getManagedSessionCount</h3>
+<p>Returns the number of all sessions which are currently managed by this service.</p>
+<h3 id="getsessionconfig">getSessionConfig</h3>
+<p>Returns the session configuration.</p>
+<h3 id="getfilterchainbuilder">getFilterChainBuilder</h3>
+<p>Returns the <em>Filter</em> chain builder. This is useful if one wants to add some new filter that will be injected when the sessions will be created.</p>
+<h3 id="setfilterchainbuilder">setFilterChainBuilder</h3>
+<p>Defines the <em>Filter</em> chain builder to use with the service.</p>
+<h3 id="getfilterchain">getFilterChain</h3>
+<p>Returns the current default <em>Filter</em> chain for the service.</p>
+<h3 id="isactive">isActive</h3>
+<p>Tells if the service is active or not.</p>
+<h3 id="getactivationtime">getActivationTime</h3>
+<p>Returns the time when this service was activated. It returns the last time when this service was activated if the service is not anymore active.</p>
+<h3 id="broadcast">broadcast</h3>
+<p>Writes the given message to all the managed sessions.</p>
+<h3 id="setsessiondatastructurefactory">setSessionDataStructureFactory</h3>
+<p>Sets the <em>IoSessionDataStructureFactory</em> that provides related data structures for a new session created by this service.</p>
+<h3 id="getscheduledwritebytes">getScheduledWriteBytes</h3>
+<p>Returns the number of bytes scheduled to be written (ie, the bytes stored in memory waiting for the socket to be ready for write).</p>
+<h3 id="getscheduledwritemessages">getScheduledWriteMessages</h3>
+<p>Returns the number of messages scheduled to be written (ie, the messages stored in memory waiting for the socket to be ready for write).</p>
+<h3 id="getstatistics">getStatistics</h3>
+<p>Returns the <em>IoServiceStatistics</em> object for this service.</p>
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+			&nbsp;
+        
+        </div>
+        <div class="nav_up">
+        
+            <a href="ch3-service.html">Chapter 3 - Service</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="io-service-details.html">IoService Details</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+                </div><!-- rightColumn -->
+                <div id="endContent"></div>
+            </div><!-- content -->
+            <div id="footer">&copy; 2003-2012, <a href="http://www.apache.org">The Apache Software Foundation</a> - <a href="./../../../privacy-policy.html">Privacy Policy</a><br />
+                Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
+                Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
+            </div>
+        </div><!-- container -->
+    </body>
+</html>
+

Added: websites/staging/mina/trunk/content/mina-project/userguide/ch4-session/ch4-session.html
==============================================================================
--- websites/staging/mina/trunk/content/mina-project/userguide/ch4-session/ch4-session.html (added)
+++ websites/staging/mina/trunk/content/mina-project/userguide/ch4-session/ch4-session.html Thu Nov 15 13:10:37 2012
@@ -0,0 +1,255 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+	<title>Chapter 4 - Session &mdash; Apache MINA</title>
+	
+		<link href="./../../../css/common.css" rel="stylesheet" type="text/css">
+		<link href="./../../../css/mina.css" rel="stylesheet" type="text/css">
+	
+</head>
+  <body>
+    <div id="container">
+      <div id="header">
+        <div id="subProjectsNavBar">
+          <a href="./../../../">
+            
+              <strong>Apache MINA Project</strong>
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../mina/index.html">
+            
+              MINA
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../asyncweb/index.html">
+            
+              AsyncWeb
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../ftpserver/index.html">
+            
+              FtpServer
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../sshd/index.html">
+            
+              SSHD
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../vysper/index.html">
+            
+              Vysper
+            
+          </a>
+        </div><!-- subProjectsNavBar -->
+      </div><!-- header -->
+      <div id="content">
+        <div id="leftColumn">
+                              
+          
+          
+          
+          
+          
+            <div id="navigation">
+
+    <h5>Latest Downloads</h5>
+    <ul>
+        <li><a href="./../../../downloads-mina.html">Mina 2.0.7</a></li>
+        <li><a href="./../../../downloads-ftpserver.html">FtpServer 1.0.6</a></li>
+        <li><a href="./../../../downloads-sshd.html">SSHD 0.8.0</a></li>
+        <li><a href="./../../../downloads-vysper.html">Vysper 0.7</a></li>
+    </ul>
+    <h5>Projects</h5>
+    <ul>
+        <li><a href="./../../../mina/index.html">MINA</a></li>
+        <li><a href="./../../../asyncweb/index.html">AsyncWeb</a></li>
+        <li><a href="./../../../ftpserver/index.html">FtpServer</a></li>
+        <li><a href="./../../../sshd/index.html">SSHD</a></li>
+        <li><a href="./../../../vysper/index.html">Vysper</a></li>
+    </ul>
+
+    <h5>Community</h5>
+    <ul>
+      <li><a href="./../../../contributors.html" class="external-link" rel="nofollow">Team</a></li>
+      <li><a href="http://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a></li>
+      <li><a href="http://www.apache.org/foundation/contributing.html" class="external-link" rel="nofollow">Contributing</a></li>
+      <li><a href="http://www.apache.org/" title="Apache Software Foundation" class="external-link" rel="nofollow">ASF main site</a></li>
+      <li><a href="http://www.apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a></li>
+      <li><a href="http://www.apache.org/foundation/sponsorship.html" title="The ASF sponsorship program" class="external-link" rel="nofollow">Sponsorship program</a></li>
+      <li><a href="http://www.apache.org/security/" class="external-link" rel="nofollow">Security</a></li>
+    </ul>
+
+    <h3><a name="Navigation-Upcoming"></a>Upcoming</h3>
+
+</div>
+
+<!-- navigation -->
+          
+        </div><!-- leftColumn -->
+      <div id="rightColumn">
+
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="../ch3-service/ch3-service.html">Chapter 3 - Service</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="../user-guide-toc.html">User Guide</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="../ch5-filters/ch5-filters.html">Chapter 5 - Filters</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+<h1 id="chapter-4-session">Chapter 4 - Session</h1>
+<p>The Session is at the heart of MINA : every time a client connects to the server, a new session is created, and will be kept in memory until the client is disconnected.</p>
+<p>A session is used to store persistent informations about the connection, plus any kind of information the server might need to use during the request processing, and eventually during the whole session life.</p>
+<h2 id="session-state">Session state</h2>
+<p>A session has a state, which will evolve during time.</p>
+<ul>
+<li>Connected : the session has been created and is available</li>
+<li>Idle : the session hasn't processed any request for at least a period of time (this period is configurable)<ul>
+<li>Idle for read : no read has actually been made for a period of time</li>
+<li>Idle for write : no write has actually been made for a period of time</li>
+<li>Idle for both : no read nor write for a period of time</li>
+</ul>
+</li>
+<li>Closing : the session is being closed (the remaining messages are being flushed, cleaning up is not terminated)</li>
+<li>Closed : The session is now closed, nothing else can be done to revive it.</li>
+</ul>
+<p>The following state diagram exposes all the possible states and transitions :</p>
+<p><img alt="" src="../../../staticresources/images/mina/session-state.png" /></p>
+<h2 id="configuration">Configuration</h2>
+<p>Many different parameters can be set for a specific session :</p>
+<ul>
+<li>receive buffer size</li>
+<li>sending buffer size</li>
+<li>Idle time</li>
+<li>Write timeOut</li>
+</ul>
+<p>plus other configuration, depending on the transport type used (see Chapter 6 - Transports)</p>
+<h2 id="managing-user-defined-attributes">Managing user-defined attributes</h2>
+<p>It might be necessary to store some data which may be used later. This is done using the dedicated data structure associated which each session. This is a key-value association, which can store any type of data the developer might want to keep remanent.</p>
+<p>For instance, if you want to track the number of request a user has sent since the session has been created, it's easy to store it into this map: just create a key that will be associated with this value.</p>
+<div class="codehilite"><pre><span class="o">...</span>
+<span class="kt">int</span> <span class="n">counterValue</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="na">getAttribute</span><span class="o">(</span> <span class="s">&quot;counter&quot;</span> <span class="o">);</span>
+<span class="n">session</span><span class="o">.</span><span class="na">setAttribute</span><span class="o">(</span> <span class="s">&quot;counter&quot;</span><span class="o">,</span> <span class="n">counterValue</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">);</span>
+<span class="o">...</span>
+</pre></div>
+
+
+<p>We have a way to handle stored Attributes into the session : an Attribute is a key/value pair, which can be added, removed and read from the session's container.</p>
+<p>This container is created automatically when the session is created, and will be disposed when the session is terminated.</p>
+<h2 id="defining-the-container">Defining the container</h2>
+<p>As we said, this container is a key/value container, which default to a Map, but it's also possible to define another data structure if one want to handle long lived data, or to avoid storing all those data in memory if they are large : we can implement an interface and a factory that will be used to create this container when the session is created.</p>
+<p>This snippet of code shows how the container is created during the session initialization :</p>
+<div class="codehilite"><pre><span class="kd">protected</span> <span class="kd">final</span> <span class="kt">void</span> <span class="nf">initSession</span><span class="o">(</span><span class="n">IoSession</span> <span class="n">session</span><span class="o">,</span>
+        <span class="n">IoFuture</span> <span class="n">future</span><span class="o">,</span> <span class="n">IoSessionInitializer</span> <span class="n">sessionInitializer</span><span class="o">)</span> <span class="o">{</span>
+    <span class="o">...</span>
+    <span class="k">try</span> <span class="o">{</span>
+        <span class="o">((</span><span class="n">AbstractIoSession</span><span class="o">)</span> <span class="n">session</span><span class="o">).</span><span class="na">setAttributeMap</span><span class="o">(</span><span class="n">session</span><span class="o">.</span><span class="na">getService</span><span class="o">()</span>
+                <span class="o">.</span><span class="na">getSessionDataStructureFactory</span><span class="o">().</span><span class="na">getAttributeMap</span><span class="o">(</span><span class="n">session</span><span class="o">));</span>
+    <span class="o">}</span> <span class="k">catch</span> <span class="o">(</span><span class="n">IoSessionInitializationException</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+        <span class="k">throw</span> <span class="n">e</span><span class="o">;</span>
+    <span class="o">}</span> <span class="k">catch</span> <span class="o">(</span><span class="n">Exception</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+        <span class="k">throw</span> <span class="k">new</span> <span class="nf">IoSessionInitializationException</span><span class="o">(</span>
+                <span class="s">&quot;Failed to initialize an attributeMap.&quot;</span><span class="o">,</span> <span class="n">e</span><span class="o">);</span>
+    <span class="o">}</span>
+    <span class="o">...</span>
+</pre></div>
+
+
+<p>and here is the factory interface we can implement if we want to define another kind of container :</p>
+<div class="codehilite"><pre>public interface IoSessionDataStructureFactory {
+    /**
+     * Returns an {@link IoSessionAttributeMap} which is going to be associated
+     * with the specified <span class="nt">&lt;tt&gt;</span>session<span class="nt">&lt;/tt&gt;</span>.  Please note that the returned
+     * implementation must be thread-safe.
+     */
+     IoSessionAttributeMap getAttributeMap(IoSession session) throws Exception;
+ }
+</pre></div>
+
+
+<h2 id="filter-chain">Filter chain</h2>
+<p>Each session is associated with a chain of filters, which will be processed when an incoming request or an outgoing message is received or emitted. Those filters are specific for each session individually, even if most of the cases, we will use the very same chain of filters for all the existing sessions.</p>
+<p>However, it's possible to dynamically modify the chain for a single session, for instance by adding a Logger Filter in the chain for a specific session.</p>
+<h2 id="statistics">Statistics</h2>
+<p>Each session also keep a track of records about what has been done for the session :</p>
+<ul>
+<li>number of bytes received/sent</li>
+<li>number of messages received/sent</li>
+<li>Idle status</li>
+<li>throughput</li>
+</ul>
+<p>and many other useful informations.</p>
+<h2 id="handler">Handler</h2>
+<p>Last, not least, a session is attached to a Handler, in charge of dispatching the messages to your application. This handler will also send pack response by using the session, simply by calling the write() method :</p>
+<div class="codehilite"><pre><span class="o">...</span>
+<span class="n">session</span><span class="o">.</span><span class="na">write</span><span class="o">(</span> <span class="o">&lt;</span><span class="n">your</span> <span class="n">message</span><span class="o">&gt;</span> <span class="o">);</span>
+<span class="o">...</span>
+</pre></div>
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="../ch3-service/ch3-service.html">Chapter 3 - Service</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="../user-guide-toc.html">User Guide</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="../ch5-filters/ch5-filters.html">Chapter 5 - Filters</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+                </div><!-- rightColumn -->
+                <div id="endContent"></div>
+            </div><!-- content -->
+            <div id="footer">&copy; 2003-2012, <a href="http://www.apache.org">The Apache Software Foundation</a> - <a href="./../../../privacy-policy.html">Privacy Policy</a><br />
+                Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
+                Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
+            </div>
+        </div><!-- container -->
+    </body>
+</html>
+

Added: websites/staging/mina/trunk/content/mina-project/userguide/ch5-filters/ch5-filters.html
==============================================================================
--- websites/staging/mina/trunk/content/mina-project/userguide/ch5-filters/ch5-filters.html (added)
+++ websites/staging/mina/trunk/content/mina-project/userguide/ch5-filters/ch5-filters.html Thu Nov 15 13:10:37 2012
@@ -0,0 +1,408 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+	<title>Chapter 5 - Filters &mdash; Apache MINA</title>
+	
+		<link href="./../../../css/common.css" rel="stylesheet" type="text/css">
+		<link href="./../../../css/mina.css" rel="stylesheet" type="text/css">
+	
+</head>
+  <body>
+    <div id="container">
+      <div id="header">
+        <div id="subProjectsNavBar">
+          <a href="./../../../">
+            
+              <strong>Apache MINA Project</strong>
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../mina/index.html">
+            
+              MINA
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../asyncweb/index.html">
+            
+              AsyncWeb
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../ftpserver/index.html">
+            
+              FtpServer
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../sshd/index.html">
+            
+              SSHD
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../vysper/index.html">
+            
+              Vysper
+            
+          </a>
+        </div><!-- subProjectsNavBar -->
+      </div><!-- header -->
+      <div id="content">
+        <div id="leftColumn">
+                              
+          
+          
+          
+          
+          
+            <div id="navigation">
+
+    <h5>Latest Downloads</h5>
+    <ul>
+        <li><a href="./../../../downloads-mina.html">Mina 2.0.7</a></li>
+        <li><a href="./../../../downloads-ftpserver.html">FtpServer 1.0.6</a></li>
+        <li><a href="./../../../downloads-sshd.html">SSHD 0.8.0</a></li>
+        <li><a href="./../../../downloads-vysper.html">Vysper 0.7</a></li>
+    </ul>
+    <h5>Projects</h5>
+    <ul>
+        <li><a href="./../../../mina/index.html">MINA</a></li>
+        <li><a href="./../../../asyncweb/index.html">AsyncWeb</a></li>
+        <li><a href="./../../../ftpserver/index.html">FtpServer</a></li>
+        <li><a href="./../../../sshd/index.html">SSHD</a></li>
+        <li><a href="./../../../vysper/index.html">Vysper</a></li>
+    </ul>
+
+    <h5>Community</h5>
+    <ul>
+      <li><a href="./../../../contributors.html" class="external-link" rel="nofollow">Team</a></li>
+      <li><a href="http://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a></li>
+      <li><a href="http://www.apache.org/foundation/contributing.html" class="external-link" rel="nofollow">Contributing</a></li>
+      <li><a href="http://www.apache.org/" title="Apache Software Foundation" class="external-link" rel="nofollow">ASF main site</a></li>
+      <li><a href="http://www.apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a></li>
+      <li><a href="http://www.apache.org/foundation/sponsorship.html" title="The ASF sponsorship program" class="external-link" rel="nofollow">Sponsorship program</a></li>
+      <li><a href="http://www.apache.org/security/" class="external-link" rel="nofollow">Security</a></li>
+    </ul>
+
+    <h3><a name="Navigation-Upcoming"></a>Upcoming</h3>
+
+</div>
+
+<!-- navigation -->
+          
+        </div><!-- leftColumn -->
+      <div id="rightColumn">
+
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="../ch4-session/ch4-session.html">Chapter 4 - Session</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="../user-guide-toc.html">User Guide</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="../ch6-transports/ch6-transports.html">Chapter 6 - Transports</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+<h1 id="chapter-5-filters">Chapter 5 - Filters</h1>
+<p>IoFilter is one of the MINA core constructs that serves a very important role. It filters all I/O events and requests between IoService and IoHandler. If you have an experience with web application programming, you can safely think that it's a cousin of Servlet filter. Many out-of-the-box filters are provided to accelerate network application development pace by simplifying typical cross-cutting concerns using the out-of-the-box filters such as:</p>
+<ul>
+<li>LoggingFilter logs all events and requests.</li>
+<li>ProtocolCodecFilter converts an incoming ByteBuffer into message POJO and vice versa.</li>
+<li>CompressionFilter compresses all data.</li>
+<li>SSLFilter adds SSL - TLS - StartTLS support.</li>
+<li>and many more!</li>
+</ul>
+<p>In this tutorial, we will walk through how to implement an IoFilter for a real world use case. It's easy to implement an IoFilter in general, but you might also need to know specifics of MINA internals. Any related internal properties will be explained here.</p>
+<div class="toc">
+<ul>
+<li><a href="#chapter-5-filters">Chapter 5 - Filters</a><ul>
+<li><a href="#filters-already-present">Filters already present</a></li>
+<li><a href="#overriding-events-selectively">Overriding Events Selectively</a></li>
+<li><a href="#transforming-a-write-request">Transforming a Write Request</a></li>
+<li><a href="#be-careful-when-filtering-sessioncreated-event">Be Careful When Filtering sessionCreated Event</a></li>
+<li><a href="#watch-out-the-empty-buffers">Watch out the Empty Buffers!</a></li>
+</ul>
+</li>
+</ul>
+</div>
+<h2 id="filters-already-present">Filters already present</h2>
+<p>We have many filters already written. The following table list all the existing filters, with a short description of their usage.</p>
+<table>
+<thead>
+<tr>
+<th>Filter</th>
+<th>class</th>
+<th>Description</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>Blacklist</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/firewall/BlacklistFilter.html">BlacklistFilter</a></td>
+<td>Blocks connections from blacklisted remote addresses<BR class="atl-forced-newline"></td>
+</tr>
+<tr>
+<td>Buffered Write</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/buffer/BufferedWriteFilter.html">BufferedWriteFilter</a></td>
+<td>Buffers outgoing requests like the BufferedOutputStream does</td>
+</tr>
+<tr>
+<td>Compression</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/compression/CompressionFilter.html">CompressionFilter</a></td>
+<td>&nbsp;</td>
+</tr>
+<tr>
+<td>ConnectionThrottle</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/firewall/ConnectionThrottleFilter.html">ConnectionThrottleFilter</a></td>
+<td>&nbsp;</td>
+</tr>
+<tr>
+<td>ErrorGenerating</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/errorgenerating/ErrorGeneratingFilter.html">ErrorGeneratingFilter</a></td>
+<td>&nbsp;</td>
+</tr>
+<tr>
+<td>Executor</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/executor/ExecutorFilter.html">ExecutorFilter</a></td>
+<td>&nbsp;</td>
+</tr>
+<tr>
+<td>FileRegionWrite</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/stream/FileRegionWriteFilter.html">FileRegionWriteFilter</a></td>
+<td>&nbsp;</td>
+</tr>
+<tr>
+<td>KeepAlive</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/keepalive/KeepAliveFilter.html">KeepAliveFilter</a></td>
+<td>&nbsp;</td>
+</tr>
+<tr>
+<td>Logging</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/logging/LoggingFilter.html">LoggingFilter</a></td>
+<td>Logs event messages, like MessageReceived, MessageSent, SessionOpened, ...</td>
+</tr>
+<tr>
+<td>MDC Injection</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/logging/MdcInjectionFilter.html">MdcInjectionFilter</a></td>
+<td>Inject key IoSession properties into the MDC</td>
+</tr>
+<tr>
+<td>Noop</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/util/NoopFilter.html">NoopFilter</a></td>
+<td>A filter that does nothing. Useful for tests.</td>
+</tr>
+<tr>
+<td>Profiler</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/statistic/ProfilerTimerFilter.html">ProfilerTimerFilter</a></td>
+<td>Profile event messages, like MessageReceived, MessageSent, SessionOpened, ...</td>
+</tr>
+<tr>
+<td>ProtocolCodec</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/codec/ProtocolCodecFilter.html">ProtocolCodecFilter</a></td>
+<td>A filter in charge of encoding and decoding messages</td>
+</tr>
+<tr>
+<td>Proxy</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/proxy/filter/ProxyFilter.html">ProxyFilter</a></td>
+<td>&nbsp;</td>
+</tr>
+<tr>
+<td>Reference counting</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/util/ReferenceCountingFilter.html">ReferenceCountingFilter</a></td>
+<td>Keeps track of the number of usages of this filter</td>
+</tr>
+<tr>
+<td>RequestResponse</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/reqres/RequestResponseFilter.html">RequestResponseFilter</a></td>
+<td>&nbsp;</td>
+</tr>
+<tr>
+<td>SessionAttributeInitializing</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/util/SessionAttributeInitializingFilter.html">SessionAttributeInitializingFilter</a></td>
+<td>&nbsp;</td>
+</tr>
+<tr>
+<td>StreamWrite</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/stream/StreamWriteFilter.html">StreamWriteFilter</a></td>
+<td>&nbsp;</td>
+</tr>
+<tr>
+<td>SslFilter</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/ssl/SslFilter.html">SslFilter</a></td>
+<td>&nbsp;</td>
+</tr>
+<tr>
+<td>WriteRequest</td>
+<td><a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/util/WriteRequestFilter.html">WriteRequestFilter</a></td>
+<td>&nbsp;</td>
+</tr>
+</tbody>
+</table>
+<h2 id="overriding-events-selectively">Overriding Events Selectively</h2>
+<p>You can extend IoAdapter instead of implementing IoFilter directly. Unless overriden, any received events will be forward to the next filter immediately:</p>
+<div class="codehilite"><pre><span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyFilter</span> <span class="kd">extends</span> <span class="n">IoFilterAdapter</span> <span class="o">{</span>
+    <span class="nd">@Override</span>
+    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">sessionOpened</span><span class="o">(</span><span class="n">NextFilter</span> <span class="n">nextFilter</span><span class="o">,</span> <span class="n">IoSession</span> <span class="n">session</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
+        <span class="c1">// Some logic here...</span>
+        <span class="n">nextFilter</span><span class="o">.</span><span class="na">sessionOpened</span><span class="o">(</span><span class="n">session</span><span class="o">);</span>
+        <span class="c1">// Some other logic here...</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<h2 id="transforming-a-write-request">Transforming a Write Request</h2>
+<p>If you are going to transform an incoming write request via IoSession.write(), things can get pretty tricky. For example, let's assume your filter transforms HighLevelMessage to LowLevelMessage when IoSession.write() is invoked with a HighLevelMessage object. You could insert appropriate transformation code to your filter's filterWrite() method and think that's all. However, you have to note that you also need to take care of messageSent event because an IoHandler or any filters next to yours will expect messageSent() method is called with HighLevelMessage as a parameter, because it's irrational for the caller to get notified that LowLevelMessage is sent when the caller actually wrote HighLevelMessage. Consequently, you have to implement both filterWrite() and messageSent() if your filter performs transformation.</p>
+<p>Please also note that you still need to implement similar mechanism even if the types of the input object and the output object are identical (e.g. CompressionFilter) because the caller of IoSession.write() will expect exactly what he wrote in his or her messageSent() handler method.</p>
+<p>Let's assume that you are implementing a filter that transforms a String into a char[]. Your filter's filterWrite() will look like the following:</p>
+<div class="codehilite"><pre><span class="kd">public</span> <span class="kt">void</span> <span class="nf">filterWrite</span><span class="o">(</span><span class="n">NextFilter</span> <span class="n">nextFilter</span><span class="o">,</span> <span class="n">IoSession</span> <span class="n">session</span><span class="o">,</span> <span class="n">WriteRequest</span> <span class="n">request</span><span class="o">)</span> <span class="o">{</span>
+    <span class="n">nextFilter</span><span class="o">.</span><span class="na">filterWrite</span><span class="o">(</span>
+        <span class="n">session</span><span class="o">,</span> <span class="k">new</span> <span class="n">DefaultWriteRequest</span><span class="o">(</span>
+                <span class="o">((</span><span class="n">String</span><span class="o">)</span> <span class="n">request</span><span class="o">.</span><span class="na">getMessage</span><span class="o">()).</span><span class="na">toCharArray</span><span class="o">(),</span> <span class="n">request</span><span class="o">.</span><span class="na">getFuture</span><span class="o">(),</span> <span class="n">request</span><span class="o">.</span><span class="na">getDestination</span><span class="o">()));</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>Now, we need to do the reverse in messageSent():</p>
+<div class="codehilite"><pre><span class="kd">public</span> <span class="kt">void</span> <span class="nf">messageSent</span><span class="o">(</span><span class="n">NextFilter</span> <span class="n">nextFilter</span><span class="o">,</span> <span class="n">IoSession</span> <span class="n">session</span><span class="o">,</span> <span class="n">Object</span> <span class="n">message</span><span class="o">)</span> <span class="o">{</span>
+    <span class="n">nextFilter</span><span class="o">.</span><span class="na">messageSent</span><span class="o">(</span><span class="n">session</span><span class="o">,</span> <span class="k">new</span> <span class="n">String</span><span class="o">((</span><span class="kt">char</span><span class="o">[])</span> <span class="n">message</span><span class="o">));</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>What about String-to-ByteBuffer transformation? We can be a little bit more efficient because we don't need to reconstruct the original message (String). However, it's somewhat more complex than the previous example:</p>
+<div class="codehilite"><pre><span class="kd">public</span> <span class="kt">void</span> <span class="nf">filterWrite</span><span class="o">(</span><span class="n">NextFilter</span> <span class="n">nextFilter</span><span class="o">,</span> <span class="n">IoSession</span> <span class="n">session</span><span class="o">,</span> <span class="n">WriteRequest</span> <span class="n">request</span><span class="o">)</span> <span class="o">{</span>
+    <span class="n">String</span> <span class="n">m</span> <span class="o">=</span> <span class="o">(</span><span class="n">String</span><span class="o">)</span> <span class="n">request</span><span class="o">.</span><span class="na">getMessage</span><span class="o">();</span>
+    <span class="n">ByteBuffer</span> <span class="n">newBuffer</span> <span class="o">=</span> <span class="k">new</span> <span class="n">MyByteBuffer</span><span class="o">(</span><span class="n">m</span><span class="o">,</span> <span class="n">ByteBuffer</span><span class="o">.</span><span class="na">wrap</span><span class="o">(</span><span class="n">m</span><span class="o">.</span><span class="na">getBytes</span><span class="o">());</span>
+
+    <span class="n">nextFilter</span><span class="o">.</span><span class="na">filterWrite</span><span class="o">(</span>
+            <span class="n">session</span><span class="o">,</span> <span class="k">new</span> <span class="n">WriteRequest</span><span class="o">(</span><span class="n">newBuffer</span><span class="o">,</span> <span class="n">request</span><span class="o">.</span><span class="na">getFuture</span><span class="o">(),</span> <span class="n">request</span><span class="o">.</span><span class="na">getDestination</span><span class="o">()));</span>
+<span class="o">}</span>
+
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">messageSent</span><span class="o">(</span><span class="n">NextFilter</span> <span class="n">nextFilter</span><span class="o">,</span> <span class="n">IoSession</span> <span class="n">session</span><span class="o">,</span> <span class="n">Object</span> <span class="n">message</span><span class="o">)</span> <span class="o">{</span>
+    <span class="k">if</span> <span class="o">(</span><span class="n">message</span> <span class="k">instanceof</span> <span class="n">MyByteBuffer</span><span class="o">)</span> <span class="o">{</span>
+        <span class="n">nextFilter</span><span class="o">.</span><span class="na">messageSent</span><span class="o">(</span><span class="n">session</span><span class="o">,</span> <span class="o">((</span><span class="n">MyByteBuffer</span><span class="o">)</span> <span class="n">message</span><span class="o">).</span><span class="na">originalValue</span><span class="o">);</span>
+    <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
+        <span class="n">nextFilter</span><span class="o">.</span><span class="na">messageSent</span><span class="o">(</span><span class="n">session</span><span class="o">,</span> <span class="n">message</span><span class="o">);</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+
+<span class="kd">private</span> <span class="kd">static</span> <span class="kd">class</span> <span class="nc">MyByteBuffer</span> <span class="kd">extends</span> <span class="n">ByteBufferProxy</span> <span class="o">{</span>
+    <span class="kd">private</span> <span class="kd">final</span> <span class="n">Object</span> <span class="n">originalValue</span><span class="o">;</span>
+    <span class="kd">private</span> <span class="nf">MyByteBuffer</span><span class="o">(</span><span class="n">Object</span> <span class="n">originalValue</span><span class="o">,</span> <span class="n">ByteBuffer</span> <span class="n">encodedValue</span><span class="o">)</span> <span class="o">{</span>
+        <span class="kd">super</span><span class="o">(</span><span class="n">encodedValue</span><span class="o">);</span>
+        <span class="k">this</span><span class="o">.</span><span class="na">originalValue</span> <span class="o">=</span> <span class="n">originalValue</span><span class="o">;</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>If you are using MINA 2.0, it will be somewhat different from 1.0 and 1.1. Please refer to <a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/compression/CompressionFilter.html">CompressionFilter</a> and <a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/reqres/RequestResponseFilter.html">RequestResponseFilter</a> meanwhile.</p>
+<h2 id="be-careful-when-filtering-sessioncreated-event">Be Careful When Filtering sessionCreated Event</h2>
+<p>sessionCreated is a special event that must be executed in the I/O processor thread (see Configuring Thread Model). Never forward sessionCreated event to the other thread.</p>
+<div class="codehilite"><pre><span class="kd">public</span> <span class="kt">void</span> <span class="nf">sessionCreated</span><span class="o">(</span><span class="n">NextFilter</span> <span class="n">nextFilter</span><span class="o">,</span> <span class="n">IoSession</span> <span class="n">session</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
+    <span class="c1">// ...</span>
+    <span class="n">nextFilter</span><span class="o">.</span><span class="na">sessionCreated</span><span class="o">(</span><span class="n">session</span><span class="o">);</span>
+<span class="o">}</span>
+
+<span class="c1">// DON&#39;T DO THIS!</span>
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">sessionCreated</span><span class="o">(</span><span class="kd">final</span> <span class="n">NextFilter</span> <span class="n">nextFilter</span><span class="o">,</span> <span class="kd">final</span> <span class="n">IoSession</span> <span class="n">session</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
+    <span class="n">Executor</span> <span class="n">executor</span> <span class="o">=</span> <span class="o">...;</span>
+    <span class="n">executor</span><span class="o">.</span><span class="na">execute</span><span class="o">(</span><span class="k">new</span> <span class="n">Runnable</span><span class="o">()</span> <span class="o">{</span>
+        <span class="n">nextFilter</span><span class="o">.</span><span class="na">sessionCreated</span><span class="o">(</span><span class="n">session</span><span class="o">);</span>
+        <span class="o">});</span>
+    <span class="o">}</span>
+</pre></div>
+
+
+<h2 id="watch-out-the-empty-buffers">Watch out the Empty Buffers!</h2>
+<p>MINA uses an empty buffer as an internal signal at a couple of cases. Empty buffers sometimes become a problem because it's a cause of various exceptions such as IndexOutOfBoundsException. This section explains how to avoid such a unexpected situation.</p>
+<p>ProtocolCodecFilter uses an empty buffer (i.e. buf.hasRemaining() = 0) to mark the end of the message. If your filter is placed before the ProtocolCodecFilter, please make sure your filter forward the empty buffer to the next filter if your filter implementation can throw a unexpected exception if the buffer is empty:</p>
+<div class="codehilite"><pre><span class="kd">public</span> <span class="kt">void</span> <span class="nf">messageSent</span><span class="o">(</span><span class="n">NextFilter</span> <span class="n">nextFilter</span><span class="o">,</span> <span class="n">IoSession</span> <span class="n">session</span><span class="o">,</span> <span class="n">Object</span> <span class="n">message</span><span class="o">)</span> <span class="o">{</span>
+    <span class="k">if</span> <span class="o">(</span><span class="n">message</span> <span class="k">instanceof</span> <span class="n">ByteBuffer</span> <span class="o">&amp;&amp;</span> <span class="o">!((</span><span class="n">ByteBuffer</span><span class="o">)</span> <span class="n">message</span><span class="o">).</span><span class="na">hasRemaining</span><span class="o">())</span> <span class="o">{</span>
+        <span class="n">nextFilter</span><span class="o">.</span><span class="na">messageSent</span><span class="o">(</span><span class="n">nextFilter</span><span class="o">,</span> <span class="n">session</span><span class="o">,</span> <span class="n">message</span><span class="o">);</span>
+        <span class="k">return</span><span class="o">;</span>
+    <span class="o">}</span>
+    <span class="o">...</span>
+<span class="o">}</span>
+
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">filterWrite</span><span class="o">(</span><span class="n">NextFilter</span> <span class="n">nextFilter</span><span class="o">,</span> <span class="n">IoSession</span> <span class="n">session</span><span class="o">,</span> <span class="n">WriteRequest</span> <span class="n">request</span><span class="o">)</span> <span class="o">{</span>
+    <span class="n">Object</span> <span class="n">message</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="na">getMessage</span><span class="o">();</span>
+    <span class="k">if</span> <span class="o">(</span><span class="n">message</span> <span class="k">instanceof</span> <span class="n">ByteBuffer</span> <span class="o">&amp;&amp;</span> <span class="o">!((</span><span class="n">ByteBuffer</span><span class="o">)</span> <span class="n">message</span><span class="o">).</span><span class="na">hasRemaining</span><span class="o">())</span> <span class="o">{</span>
+        <span class="n">nextFilter</span><span class="o">.</span><span class="na">filterWrite</span><span class="o">(</span><span class="n">nextFilter</span><span class="o">,</span> <span class="n">session</span><span class="o">,</span> <span class="n">request</span><span class="o">);</span>
+        <span class="k">return</span><span class="o">;</span>
+    <span class="o">}</span>
+    <span class="o">...</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>Do we always have to insert the if block for every filters? Fortunately, you don't have to. Here's the golden rule of handling empty buffers:</p>
+<ul>
+<li>If your filter works without any problem even if the buffer is empty, you don't need to add the if blocks at all.</li>
+<li>If your filter is placed after ProtocolCodecFilter, you don't need to add the if blocks at all.</li>
+<li>Otherwise, you need the if blocks.</li>
+</ul>
+<p>If you need the if blocks, please remember you don't always need to follow the example above. You can check if the buffer is empty wherever you want as long as your filter doesn't throw a unexpected exception.</p>
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="../ch4-session/ch4-session.html">Chapter 4 - Session</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="../user-guide-toc.html">User Guide</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="../ch6-transports/ch6-transports.html">Chapter 6 - Transports</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+                </div><!-- rightColumn -->
+                <div id="endContent"></div>
+            </div><!-- content -->
+            <div id="footer">&copy; 2003-2012, <a href="http://www.apache.org">The Apache Software Foundation</a> - <a href="./../../../privacy-policy.html">Privacy Policy</a><br />
+                Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
+                Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
+            </div>
+        </div><!-- container -->
+    </body>
+</html>
+

Added: websites/staging/mina/trunk/content/mina-project/userguide/ch6-transports/apr-transport.html
==============================================================================
--- websites/staging/mina/trunk/content/mina-project/userguide/ch6-transports/apr-transport.html (added)
+++ websites/staging/mina/trunk/content/mina-project/userguide/ch6-transports/apr-transport.html Thu Nov 15 13:10:37 2012
@@ -0,0 +1,211 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+	<title>APR Transport &mdash; Apache MINA</title>
+	
+		<link href="./../../../css/common.css" rel="stylesheet" type="text/css">
+		<link href="./../../../css/mina.css" rel="stylesheet" type="text/css">
+	
+</head>
+  <body>
+    <div id="container">
+      <div id="header">
+        <div id="subProjectsNavBar">
+          <a href="./../../../">
+            
+              <strong>Apache MINA Project</strong>
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../mina/index.html">
+            
+              MINA
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../asyncweb/index.html">
+            
+              AsyncWeb
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../ftpserver/index.html">
+            
+              FtpServer
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../sshd/index.html">
+            
+              SSHD
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../vysper/index.html">
+            
+              Vysper
+            
+          </a>
+        </div><!-- subProjectsNavBar -->
+      </div><!-- header -->
+      <div id="content">
+        <div id="leftColumn">
+                              
+          
+          
+          
+          
+          
+            <div id="navigation">
+
+    <h5>Latest Downloads</h5>
+    <ul>
+        <li><a href="./../../../downloads-mina.html">Mina 2.0.7</a></li>
+        <li><a href="./../../../downloads-ftpserver.html">FtpServer 1.0.6</a></li>
+        <li><a href="./../../../downloads-sshd.html">SSHD 0.8.0</a></li>
+        <li><a href="./../../../downloads-vysper.html">Vysper 0.7</a></li>
+    </ul>
+    <h5>Projects</h5>
+    <ul>
+        <li><a href="./../../../mina/index.html">MINA</a></li>
+        <li><a href="./../../../asyncweb/index.html">AsyncWeb</a></li>
+        <li><a href="./../../../ftpserver/index.html">FtpServer</a></li>
+        <li><a href="./../../../sshd/index.html">SSHD</a></li>
+        <li><a href="./../../../vysper/index.html">Vysper</a></li>
+    </ul>
+
+    <h5>Community</h5>
+    <ul>
+      <li><a href="./../../../contributors.html" class="external-link" rel="nofollow">Team</a></li>
+      <li><a href="http://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a></li>
+      <li><a href="http://www.apache.org/foundation/contributing.html" class="external-link" rel="nofollow">Contributing</a></li>
+      <li><a href="http://www.apache.org/" title="Apache Software Foundation" class="external-link" rel="nofollow">ASF main site</a></li>
+      <li><a href="http://www.apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a></li>
+      <li><a href="http://www.apache.org/foundation/sponsorship.html" title="The ASF sponsorship program" class="external-link" rel="nofollow">Sponsorship program</a></li>
+      <li><a href="http://www.apache.org/security/" class="external-link" rel="nofollow">Security</a></li>
+    </ul>
+
+    <h3><a name="Navigation-Upcoming"></a>Upcoming</h3>
+
+</div>
+
+<!-- navigation -->
+          
+        </div><!-- leftColumn -->
+      <div id="rightColumn">
+
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+			&nbsp;
+        
+        </div>
+        <div class="nav_up">
+        
+            <a href="ch6-transports.html">Chapter 6 - Transports</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="serial-transport.html">Serial Transport</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+<h1 id="apr-transport">APR Transport</h1>
+<h2 id="introduction">Introduction</h2>
+<p><a href="http://apr.apache.org/">APR (Apache Portable Runtime)</a> provide superior scalability, performance, and better integration with native server technologies. APR transport is supported by MINA. In this section, we shall touch base upon how to use APR transport with MINA. We shall the Time Server example for this.</p>
+<h2 id="pre-requisite">Pre-requisite</h2>
+<p><DIV class="info" markdown="1">
+    APR transport depends following components<BR>
+    APR library - Download/install appropriate library for the platform from <A href="http://www.apache.org/dist/tomcat/tomcat-connectors/native/" class="external-link" rel="nofollow">http://www.apache.org/dist/tomcat/tomcat-connectors/native/</A><BR>
+    JNI wrapper (tomcat-apr-5.5.23.jar) The jar is shipped with release
+    <P>Put the native library in PATH</P>
+</DIV></p>
+<h2 id="using-apr-transport">Using APR Transport</h2>
+<p>Refer <a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/example/gettingstarted/timeserver/">Time Server</a> example for complete source</p>
+<p>Lets see how NIO based Time server implementation looks like</p>
+<div class="codehilite"><pre><span class="n">IoAcceptor</span> <span class="n">acceptor</span> <span class="o">=</span> <span class="k">new</span> <span class="n">NioSocketAcceptor</span><span class="o">();</span>
+
+<span class="n">acceptor</span><span class="o">.</span><span class="na">getFilterChain</span><span class="o">().</span><span class="na">addLast</span><span class="o">(</span> <span class="s">&quot;logger&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">LoggingFilter</span><span class="o">()</span> <span class="o">);</span>
+<span class="n">acceptor</span><span class="o">.</span><span class="na">getFilterChain</span><span class="o">().</span><span class="na">addLast</span><span class="o">(</span> <span class="s">&quot;codec&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">ProtocolCodecFilter</span><span class="o">(</span> <span class="k">new</span> <span class="n">TextLineCodecFactory</span><span class="o">(</span> <span class="n">Charset</span><span class="o">.</span><span class="na">forName</span><span class="o">(</span> <span class="s">&quot;UTF-8&quot;</span> <span class="o">))));</span>
+
+<span class="n">acceptor</span><span class="o">.</span><span class="na">setHandler</span><span class="o">(</span>  <span class="k">new</span> <span class="n">TimeServerHandler</span><span class="o">()</span> <span class="o">);</span>
+
+<span class="n">acceptor</span><span class="o">.</span><span class="na">getSessionConfig</span><span class="o">().</span><span class="na">setReadBufferSize</span><span class="o">(</span> <span class="mi">2048</span> <span class="o">);</span>
+<span class="n">acceptor</span><span class="o">.</span><span class="na">getSessionConfig</span><span class="o">().</span><span class="na">setIdleTime</span><span class="o">(</span> <span class="n">IdleStatus</span><span class="o">.</span><span class="na">BOTH_IDLE</span><span class="o">,</span> <span class="mi">10</span> <span class="o">);</span>
+
+<span class="n">acceptor</span><span class="o">.</span><span class="na">bind</span><span class="o">(</span> <span class="k">new</span> <span class="n">InetSocketAddress</span><span class="o">(</span><span class="n">PORT</span><span class="o">)</span> <span class="o">);</span>
+</pre></div>
+
+
+<p>Lets see how to use APR Transport</p>
+<div class="codehilite"><pre><span class="n">IoAcceptor</span> <span class="n">acceptor</span> <span class="o">=</span> <span class="k">new</span> <span class="n">AprSocketAcceptor</span><span class="o">();</span>
+
+<span class="n">acceptor</span><span class="o">.</span><span class="na">getFilterChain</span><span class="o">().</span><span class="na">addLast</span><span class="o">(</span> <span class="s">&quot;logger&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">LoggingFilter</span><span class="o">()</span> <span class="o">);</span>
+<span class="n">acceptor</span><span class="o">.</span><span class="na">getFilterChain</span><span class="o">().</span><span class="na">addLast</span><span class="o">(</span> <span class="s">&quot;codec&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">ProtocolCodecFilter</span><span class="o">(</span> <span class="k">new</span> <span class="n">TextLineCodecFactory</span><span class="o">(</span> <span class="n">Charset</span><span class="o">.</span><span class="na">forName</span><span class="o">(</span> <span class="s">&quot;UTF-8&quot;</span> <span class="o">))));</span>
+
+<span class="n">acceptor</span><span class="o">.</span><span class="na">setHandler</span><span class="o">(</span>  <span class="k">new</span> <span class="n">TimeServerHandler</span><span class="o">()</span> <span class="o">);</span>
+
+<span class="n">acceptor</span><span class="o">.</span><span class="na">getSessionConfig</span><span class="o">().</span><span class="na">setReadBufferSize</span><span class="o">(</span> <span class="mi">2048</span> <span class="o">);</span>
+<span class="n">acceptor</span><span class="o">.</span><span class="na">getSessionConfig</span><span class="o">().</span><span class="na">setIdleTime</span><span class="o">(</span> <span class="n">IdleStatus</span><span class="o">.</span><span class="na">BOTH_IDLE</span><span class="o">,</span> <span class="mi">10</span> <span class="o">);</span>
+
+<span class="n">acceptor</span><span class="o">.</span><span class="na">bind</span><span class="o">(</span> <span class="k">new</span> <span class="n">InetSocketAddress</span><span class="o">(</span><span class="n">PORT</span><span class="o">)</span> <span class="o">);</span>
+</pre></div>
+
+
+<p>We just change the NioSocketAcceptor to AprSocketAcceptor. That's it, now our Time Server shall use APR transport.</p>
+<p>Rest complete process remains same.</p>
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+			&nbsp;
+        
+        </div>
+        <div class="nav_up">
+        
+            <a href="ch6-transports.html">Chapter 6 - Transports</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="serial-transport.html">Serial Transport</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+                </div><!-- rightColumn -->
+                <div id="endContent"></div>
+            </div><!-- content -->
+            <div id="footer">&copy; 2003-2012, <a href="http://www.apache.org">The Apache Software Foundation</a> - <a href="./../../../privacy-policy.html">Privacy Policy</a><br />
+                Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
+                Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
+            </div>
+        </div><!-- container -->
+    </body>
+</html>
+