| <!DOCTYPE html>
|
|
|
| <html lang="en">
|
| <head>
|
| <title>3.1 - IO Service Introduction — Apache MINA</title>
|
|
|
| <link href="/assets/css/common.css" rel="stylesheet" type="text/css"/>
|
| <link href="/assets/css/mina.css" rel="stylesheet" type="text/css"/>
|
| </head>
|
| <body>
|
| <script src="https://www.apachecon.com/event-images/snippet.js"></script>
|
| <div id="container">
|
| <div id="header">
|
| <div id="subProjectsNavBar">
|
| <a href="/">
|
|
|
| Apache MINA Project
|
|
|
| </a>
|
| |
|
| <a href="/mina-project/">
|
|
|
| <strong>MINA</strong>
|
|
|
| </a>
|
| |
|
| <a href="/asyncweb-project/">
|
|
|
| AsyncWeb
|
|
|
| </a>
|
| |
|
| <a href="/ftpserver-project/">
|
|
|
| FtpServer
|
|
|
| </a>
|
| |
|
| <a href="/sshd-project/">
|
|
|
| SSHD
|
|
|
| </a>
|
| |
|
| <a href="/vysper-project/">
|
|
|
| Vysper
|
|
|
| </a>
|
| </div>
|
| </div>
|
|
|
|
|
| <div id="content">
|
| <div id="leftColumn">
|
| <div id="navigation">
|
| <a class="acevent" data-format="wide" data-width="170"></a>
|
| <h5>Social Networks</h5>
|
| <ul>
|
| <li><a href="https://fosstodon.org/@apachemina">Apache MINA Mastodon</a></li>
|
| </ul>
|
| <h5>Latest Downloads</h5>
|
| <ul>
|
| <li><a href="/mina-project/downloads_2_0.html">Mina 2.0.25</a></li>
|
| <li><a href="/mina-project/downloads_2_1.html">Mina 2.1.8</a></li>
|
| <li><a href="/mina-project/downloads_2_2.html">Mina 2.2.3</a></li>
|
| <li><a href="/mina-project/downloads_old.html">Mina old versions</a></li>
|
| </ul>
|
| <h5>Documentation</h5>
|
| <ul>
|
| <li><a href="/mina-project/documentation.html" class="external-link" rel="nofollow">Base documentation</a></li>
|
| <li><a href="/mina-project/userguide/user-guide-toc.html" class="external-link" rel="nofollow">User guide</a></li>
|
| <li><a href="/mina-project/2.2-vs-2.1.html" class="external-link" rel="nofollow">2.2 vs 2.1</a></li>
|
| <li><a href="/mina-project/2.1-vs-2.0.html" class="external-link" rel="nofollow">2.1 vs 2.0</a></li>
|
| <li><a href="/mina-project/features.html" class="external-link" rel="nofollow">Features</a></li>
|
| <li><a href="/mina-project/road-map.html" class="external-link" rel="nofollow">Road Map</a></li>
|
| <li><a href="/mina-project/quick-start-guide.html" class="external-link" rel="nofollow">Quick Start Guide</a></li>
|
| <li><a href="/mina-project/faq.html" class="external-link" rel="nofollow">FAQ</a></li>
|
| </ul>
|
| <h5>Resources</h5>
|
| <ul>
|
| <li><a href="/mina-project/mailing-lists.html" class="external-link" rel="nofollow">Mailing lists & IRC</a></li>
|
| <li><a href="/mina-project/issue-tracking.html" class="external-link" rel="nofollow">Issue tracking</a></li>
|
| <li><a href="/mina-project/sources.html" class="external-link" rel="nofollow">Sources</a></li>
|
| <li><a href="/mina-project/gen-docs/latest-2.0/apidocs/index.html" class="external-link" rel="nofollow">API Javadoc 2.0.25</a></li>
|
| <li><a href="/mina-project/gen-docs/latest-2.1/apidocs/index.html" class="external-link" rel="nofollow">API Javadoc 2.1.8</a></li>
|
| <li><a href="/mina-project/gen-docs/latest-2.2/apidocs/index.html" class="external-link" rel="nofollow">API Javadoc 2.2.3</a></li>
|
| <li><a href="/mina-project/gen-docs/latest-2.0/xref/index.html" class="external-link" rel="nofollow">API xref 2.0.25</a></li>
|
| <li><a href="/mina-project/gen-docs/latest-2.1/xref/index.html" class="external-link" rel="nofollow">API xref 2.1.8</a></li>
|
| <li><a href="/mina-project/gen-docs/latest-2.2/xref/index.html" class="external-link" rel="nofollow">API xref 2.2.3</a></li>
|
| <li><a href="/mina-project/performances.html" class="external-link" rel="nofollow">Performances</a></li>
|
| <li><a href="/mina-project/testimonials.html" class="external-link" rel="nofollow">Testimonials</a></li>
|
| <li><a href="/mina-project/conferences.html" class="external-link" rel="nofollow">Conferences</a></li>
|
| <li><a href="/mina-project/developer-guide.html" class="external-link" rel="nofollow">Developers Guide</a></li>
|
| <li><a href="/mina-project/related-projects.html" class="external-link" rel="nofollow">Related Projects</a></li>
|
| <li><a href="https://people.apache.org/~vgritsenko/stats/projects/mina.html" class="external-link" rel="nofollow">Statistics</a></li>
|
| </ul>
|
|
|
| <h5>Community</h5>
|
| <ul>
|
| <li><a href="https://www.apache.org/foundation/contributing.html" class="external-link" rel="nofollow">Contributing</a></li>
|
| <li><a href="/contributors.html" class="external-link" rel="nofollow">Team</a></li>
|
| <li><a href="/special-thanks.html" class="external-link" rel="nofollow">Special Thanks</a></li>
|
| <li><a href="https://www.apache.org/security/" class="external-link" rel="nofollow">Security</a></li>
|
| </ul>
|
|
|
| <h5>About Apache</h5>
|
| <ul>
|
| <li><a href="https://www.apache.org" class="external-link" rel="nofollow">Apache main site</a></li>
|
| <li><a href="https://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a></li>
|
| <li><a href="https://www.apache.org/foundation/sponsorship.html" title="The ASF sponsorship program" class="external-link" rel="nofollow">Sponsorship program</a></li>
|
| <li><a href="https://www.apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a></li>
|
| </ul>
|
|
|
| <h3><a name="Navigation-Upcoming"></a>Upcoming</h3>
|
| <ul>
|
| <li>No event</li>
|
| </ul>
|
| </div>
|
| </div>
|
| <div id="rightColumn">
|
|
|
| <div class="nav">
|
| <div class="nav_prev">
|
|
|
|
|
| <a href="ch3-service.html">Chapter 3 - Service</a>
|
|
|
| </div>
|
| <div class="nav_up">
|
|
|
|
|
| <a href="ch3-service.html">Chapter 3 - Service</a>
|
|
|
| </div>
|
| <div class="nav_next">
|
|
|
|
|
| <a href="ch3.2-io-service-details.html">3.2 - IoService Details</a>
|
|
|
| </div>
|
| <div class="clearfix"></div>
|
| </div>
|
|
|
|
|
| |
| <h1 id="31---ioservice-introduction">3.1 - IoService Introduction</h1> |
| <p><a href="https://nightlies.apache.org/mina/mina/2.0.22/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="https://nightlies.apache.org/mina/mina/2.0.22/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 src="/assets/img/mina/IoService_mindmap.png" alt=""></p> |
| <h2 id="responsibilities">Responsibilities</h2> |
| <p>As seen in the previous graphic, The <em>IoService</em> has many responsibilities :</p> |
| <ul> |
| <li>sessions management : Creates and deletes sessions, detect idleness.</li> |
| <li>filter chain management : Handles the filter 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">
|
|
|
|
|
| <a href="ch3-service.html">Chapter 3 - Service</a>
|
|
|
| </div>
|
| <div class="nav_up">
|
|
|
|
|
| <a href="ch3-service.html">Chapter 3 - Service</a>
|
|
|
| </div>
|
| <div class="nav_next">
|
|
|
|
|
| <a href="ch3.2-io-service-details.html">3.2 - IoService Details</a>
|
|
|
| </div>
|
| <div class="clearfix"></div>
|
| </div>
|
|
|
|
|
| </div>
|
| <div id="endContent"></div>
|
| </div>
|
|
|
| <div id="footer">
|
| © 2003-2024, <a href="https://www.apache.org">The Apache Software Foundation</a> - <a href="https://privacy.apache.org/policies/privacy-policy-public.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>
|
|
|
| </body>
|
|
|
| </html>
|