ApacheCon EU  2008
Niklas Gustavsson [email_address] http://protocol7.com
<ul><ul><li>MINA commiter since 2007 </li></ul></ul><ul><ul><li>On FtpServer since 2005 </li></ul></ul>
<ul><ul><li>So, what's  MINA ? </li></ul></ul>
<ul><ul><li>Java API for network applications </li></ul></ul>
<ul><ul><li>Event driven </li></ul></ul><ul><ul><li>Asynchronous </li></ul></ul>
<ul><ul><li>Server side </li></ul></ul><ul><ul><li>Client side </li></ul></ul>
<ul><ul><li>Pluggable implementations </li></ul></ul>
<ul><ul><li>You will probably use  </li></ul></ul><ul><ul><li>the NIO implementation </li></ul></ul>
<ul><ul><li>...and the VmPipe </li></ul></ul>
<ul><ul><li>Separation of concerns </li></ul></ul><ul><ul><li>Wire  ↔   Business logic </li></ul></ul>
<ul><ul><li>MINA  architecture </li></ul></ul>
IoService IoConnector IoAcceptor
<ul><ul><li>IoFilter </li></ul></ul>
<ul><ul><li>Protocol codec </li></ul></ul>
<ul><ul><li>Lots of  free  stuff! </li></ul></ul>
<ul><ul><li>Traffic shapers </li></ul></ul><ul><ul><li>SSL </li></ul></ul><ul><ul><li>Compression </li></ul></ul><ul><ul><...
<ul><ul><li>IoHandler </li></ul></ul>
<ul><ul><li>Concurrency... yeay! </li></ul></ul>
<ul><ul><li>Acceptor thread </li></ul></ul><ul><ul><li>Connector thread </li></ul></ul>
<ul><ul><li>I/O processor thread </li></ul></ul><ul><ul><li>Cores + 1 </li></ul></ul>
<ul><ul><li>ExecutorFilter </li></ul></ul>
<ul><ul><li>Fine, so what's best for me? </li></ul></ul>
<ul><ul><li>What's new in MINA  2.0 </li></ul></ul>
<ul><ul><li>Thread model redesigned </li></ul></ul>
<ul><ul><li>Simplified configuration </li></ul></ul>
<ul><ul><li>ByteBuffer now IoBuffer </li></ul></ul><ul><ul><li>and default to heap allocation </li></ul></ul>
<ul><ul><li>IoSessionLogger  removed </li></ul></ul>
<ul><ul><li>And  lots  and lots of  </li></ul></ul><ul><ul><li>Cleanup and improvements </li></ul></ul>
<ul><ul><li>So, which version should  I use? </li></ul></ul>
<ul><ul><li>MINA  1.0 </li></ul></ul><ul><ul><li>MINA  1.1 </li></ul></ul><ul><ul><li>MINA  2.0 </li></ul></ul>
<ul><ul><li>Migrating from  1.x </li></ul></ul>
<ul><ul><li>Review thread model </li></ul></ul>
<ul><ul><li>Update configuration </li></ul></ul>
<ul><ul><li>Remove IoSessionLogger </li></ul></ul>
<ul><ul><li>Update class and package names </li></ul></ul>
<ul><ul><li>DEMO! </li></ul></ul>
<ul><ul><li>Simple  chat  server in MINA </li></ul></ul>
<ul><ul><li>public final static Chat INSTANCE = new Chat(); </li></ul></ul><ul><ul><li>private List<User> users = new Arra...
<ul><ul><li>public class ChatDecoder extends CumulativeProtocolDecoder { </li></ul></ul><ul><ul><li>protected boolean doDe...
<ul><ul><li>public class ChatHandler extends IoHandlerAdapter { </li></ul></ul><ul><ul><li>public void sessionCreated(IoSe...
<ul><ul><li>ChatHandler continued... </li></ul></ul><ul><ul><li>public void messageReceived(IoSession session,  Object o) ...
<ul><ul><li>SocketAcceptor acceptor = new NioSocketAcceptor(); </li></ul></ul><ul><ul><li>acceptor.getFilterChain().addLas...
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/
Upcoming SlideShare
Loading in …5
×

Apachecon Eu 2008 Mina

990 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
990
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
37
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Apachecon Eu 2008 Mina

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

    ×