General What does MINA mean?

MINA is:

  • an acronym for 'Multipurporse Infrastructure for Network Applications'
  • A girl's name
  • 'South' in Japanese
  • 'Mine' (as in mineshaft) in Spanish and Portuguese

Which version of MINA should I use?

MINA uses Linux-like version numbers. There are currently two streams in MINA; 0.7 and 0.9:

  • 0.7 is the first public release of MINA.
  • 0.8 is the official stable release of 0.7.
  • 0.9 has richer features and cleaner API than 0.8.
  • 1.0 is the official stable release of 0.9

Here are the general rules for choosing an appropriate release:

  • Prefer the latest release with even version numbers to with odd ones.
  • Try the latest release with odd version numbers if there are missing features in the stable release.

What is required to build/run MINA?

JDK 1.5 or above is required to build MINA. But MINA runs perfect with JDK 1.4 only if you don't use SSLFilter which uses Java 5 SSLEngine. This means JDK 1.5 or above is required for you to use SSL with MINA.

MINA depends on SLF4J (Simple Logging Facade for Java), a logging framework from the author of Log4J. SLF4J is very similar to Commons-Logging, but it doesn't cause any class loader issues at all. SLF4J provides bindings for Log4J, JDK 1.4 logging API, and NLog4J. Please put an appropriate SLF4J JAR file which corresponds to your favorite logging framework to the classpath as SLF4J documentation explains.

How can I get help?

The primary source to get help is the documentation. Please take a look at Getting Started section.

You can also contact us via the mailing list or the support forum to ask questions on MINA or to contribute to it. Please do not send messages to the authors directly.

If you've found some problem in MINA, please report the bug using our bug reporting system. A step-by-step instruction to reproduce the bug or JUnit test case code is appreciated.

How / What can I contribute?

You can contribute anything related with MINA; examples, useful codecs for existing protocols, tutorials, feature improvements, bug fixes, benchmarks, and whatever. Please contact us via the mailing list or the support forum.

Can MINA ...? Can I use MINA to create client applications?

Yes. You can create both client and server applications with MINA. Please take a look at IoConnector and ProtocolConnector.

Can MINA handle text protocols such as HTTP?

Yes. Please take a look at Reverser and HTTP server example.

Can MINA handle complex binary protocols such as LDAP?

Yes. Please take a look at SumUp example. There is also Apache ASN.1 project which provides ASN.1 codec for MINA.

Can I implement protocols that keeps connection alive with MINA?

Yes. MINA doesn't close any connections unless you called Session.close() or connection is closed by the remote peer.

Does MINA support TLS and SASL out-of-the-box?

Not yet. We're going to provide an easy way to implement TLS and SASL in version 0.9.

Do I need to make my IoHandler thread-safe?

It depends on your implementation. If you access the resource which is shared across multiple sessions, you have to make it thread-safe. If the resource is not shared at all and accessed by only one session (e.g. storing context information as a session attribute), then you don't need to make it thread-safe. It is because all events generated by MINA are transmitted to your handler in order, and the newer event is not processed if the event handler method for the older event for the same session didn't return yet because MINA uses leader-followers thread pool by default.

What transport types can MINA support except TCP/IP and UDP/IP?

Virtually all kind of transport types. MINA API is designed to be transport-independent. You can implement any transport type support only if you can conform to MINA API. Support for Pre-1.4 I/O (aka BIO), reliable multicast, Java Communications API, and file I/O is planned.

Does MINA support multicast?

Not yet. Java NIO doesn't support multicast yet. Multicast for NIO will be available in Java 6, Mustang. We are seriously considering to implement multicasts using pre-1.4 Java API.

How do I ...? How can I store session-specific information?

Sessions are capable of custom attributes that users can add or remove at any time. These custom attributes are not shared between sessions; it is designed to store session specific information.

How can I separate an event handler into multiple handlers when I implement complex business logic?

Please refer to DemuxingIoHandler (or DemuxingProtocolHandler). SumUp example demonstrates the usage.

How can I reconnect to server after my client session is closed.

Here is an example code: public void sessionClosed( ProtocolSession session ) throws Exception { // Wait for five seconds before reconnecting; you'll have to perform // reconnection in other thread if you're using MINA 0.7 or 0.8. // (You don't need to do if you're using MINA 0.9 or above.) Thread.sleep( 5000 ); // Reconnect. connector.connect( session.getRemoteAddress(), this ); }

Possibly it would be better to extract this code to a method like 'reconnect()' so that it can reusable in more than one place.

When should I implement my protocol handler using filters?

Filters (both IoFilter and ProtocolFilter) are usually considered reusable just like we think Servlet filters. Please implement commonly used business logic such as authorization and logging as a filter. In case you implement just complex multi-layer protocols like Kerberos, you could consider Apache Jakarta Commons Chain as an alternative.

How can I detect when the remote peer doesn't send a response message for my request message? You can't use sessionIdle event simply here. You'll have to use java.util.Timer and java.util.TimerTask (or OpenSymphony Quartz as an alternative). Schedule a timeout task to be executed on timeout situation for each request message, and cancel it when you receive the corresponding response message. How can I add filters to a specific session or port? There is IoSession.getFilterChain() and ProtocolSession.getFilterChain() that returns IoFilterChain and ProtocolFilterChain respectively. You can add any session-specific filters using the returned chain. But you cannot add port-specific filters right now. You'll have to create more than one IoAcceptor or ProtocolAcceptor because each acceptors have one filter chain you can adjust. How can I let MINA log messages using my favorite logging framework (i.e. Log4J)? MINA depends on SLF4J (Simple Logging Facade for Java), a logging framework from the author of Log4J. SLF4J is very similar to Commons-Logging, but it doesn't cause any class loader issues at all. SLF4J provides bindings for Log4J, JDK 1.4 logging API, and NLog4J. Please put an appropriate SLF4J JAR file which corresponds to your favorite logging framework to the classpath as SLF4J documentation explains.
Troubleshooting I get response timeout and connection reset under heavy load.

JVM might have ran out of direct memory. Please try increasing maximum direct memory size using -XX:MaxDirectMemorySize option (e.g. -XX:MaxDirectMemorySize=128M)

No data is writtin out to the session even if the buffer is not empty.

Please check if you called ByteBuffer.flip() to flip the buffer before writing the buffer out? It is a common mistake NIO beginners make.

I created an SSL client with MINA, but it doesn't initiate any handshake after the session is open. Please make sure you called SSLFilter.setUseClientMode(true) before you initiate a connection. Server developers will also have to disconnect users who doesn't initiate SSL handshake.