ApacheCon EU  2008
Niklas Gustavsson [email_address] http://protocol7.com
MINA commiter since 2007 On FtpServer since 2005
So, what's  MINA ?
Java API for network applications
Event driven Asynchronous
Server side Client side
Pluggable implementations
You will probably use  the NIO implementation
...and the VmPipe
Separation of concerns Wire  ↔   Business logic
MINA  architecture
IoService IoConnector IoAcceptor
IoFilter
Protocol codec
Lots of  free  stuff!
Traffic shapers SSL Compression Session based logging Firewall
IoHandler
Concurrency... yeay!
Acceptor thread Connector thread
I/O processor thread Cores + 1
ExecutorFilter
Fine, so what's best for me?
What's new in MINA  2.0
Thread model redesigned
Simplified configuration
ByteBuffer now IoBuffer and default to heap allocation
IoSessionLogger  removed
And  lots  and lots of  Cleanup and improvements
So, which version should  I use?
MINA  1.0 MINA  1.1 MINA  2.0
Migrating from  1.x
Review thread model
Update configuration
Remove IoSessionLogger
Update class and package names
DEMO!
Simple  chat  server in MINA
public final static Chat INSTANCE = new Chat(); private List<User> users = new ArrayList<User>(); public void addUser(User user) { users.add(user); } public void removeUser(User user) { users.remove(user); } public void talkToAll(Message msg) { for(User user : users) { user.talkTo(msg); } }
public class ChatDecoder extends CumulativeProtocolDecoder { protected boolean doDecode(IoSession session, IoBuffer buffer, ProtocolDecoderOutput out) throws Exception { if(do we have all the data we need?) { Message msg = new Message(user, text); out.write(msg); return true; } else { return false; } } }
public class ChatHandler extends IoHandlerAdapter { public void sessionCreated(IoSession session)  throws Exception { User user = new MinaUser(session); session.setAttribute(USER_ATTRIBUTE, user); Chat.INSTANCE.addUser(user); }
ChatHandler continued... public void messageReceived(IoSession session,  Object o) throws Exception { Message msg = (Message) o; if(msg.getText().equalsIgnoreCase(&quot;QUIT&quot;)) { session.closeOnFlush(); } else { Chat.INSTANCE.talkToAll(msg); } } ... }
SocketAcceptor acceptor = new NioSocketAcceptor(); acceptor.getFilterChain().addLast(&quot;codec&quot;, new ProtocolCodecFilter(new ChatCodecFactory()) ); acceptor.setIdleTime(IdleStatus.BOTH_IDLE, 60); acceptor.setHandler(new ChatHandler()); acceptor .bind(new InetSocketAddress(6789));
Fire up your  terminals telnet 62.12.11.90 6789
http://mina.apache.org
[email_address]
Questions ?
http://flickr.com/photos/samiksha/408007916/ http://flickr.com/photos/henrikmoltke/142750871/

Apachecon Eu 2008 Mina