apachecon eu 2008 mina
TRANSCRIPT
- 1. ApacheCon EU2008
2. Niklas Gustavsson [email_address] http://protocol7.com 3.
-
- MINA commiter since 2007
-
- On FtpServer since 2005
4.
-
- So, what'sMINA ?
5.
-
- Java API for network applications
6.
-
- Event driven
-
- Asynchronous
7.
-
- Server side
-
- Client side
8.
-
- Pluggable implementations
9.
-
- You will probably use
-
- the NIO implementation
10.
-
- ...and the VmPipe
11.
-
- Separation of concerns
-
- Wire Business logic
12.
-
- MINAarchitecture
13. IoService IoConnector IoAcceptor 14.
-
- IoFilter
15.
-
- Protocol codec
16.
-
- Lots offreestuff!
17.
-
- Traffic shapers
-
- SSL
-
- Compression
-
- Session based logging
-
- Firewall
18.
-
- IoHandler
19.
-
- Concurrency... yeay!
20.
-
- Acceptor thread
-
- Connector thread
21.
-
- I/O processor thread
-
- Cores + 1
22.
-
- ExecutorFilter
23.
-
- Fine, so what's best for me?
24.
-
- What's new in MINA2.0
25.
-
- Thread model redesigned
26.
-
- Simplified configuration
27.
-
- ByteBuffer now IoBuffer
-
- and default to heap allocation
28.
-
- IoSessionLoggerremoved
29.
-
- Andlotsand lots of
-
- Cleanup and improvements
30.
-
- So, which version shouldI use?
31.
-
- MINA1.0
-
- MINA1.1
-
- MINA2.0
32.
-
- Migrating from1.x
33.
-
- Review thread model
34.
-
- Update configuration
35.
-
- Remove IoSessionLogger
36.
-
- Update class and package names
37.
-
- DEMO!
38.
-
- Simplechatserver in MINA
39.
-
- public final static Chat INSTANCE = new Chat();
-
- private List users = new ArrayList();
-
- 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);
-
- }
-
- }
40.
-
- 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;
-
- }
-
- }
-
- }
41.
-
- 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);
-
- }
42.
-
- ChatHandler continued...
-
- public void messageReceived(IoSession session,Object o) throws Exception {
-
- Message msg = (Message) o;
-
- if(msg.getText().equalsIgnoreCase("QUIT")) {
-
- session.closeOnFlush();
-
- } else {
-
- Chat.INSTANCE.talkToAll(msg);
-
- }
-
- }
-
- ...
-
- }
43.
-
- SocketAcceptor acceptor = new NioSocketAcceptor();
-
- acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ChatCodecFactory()) );
-
- acceptor.setIdleTime(IdleStatus.BOTH_IDLE, 60);
-
- acceptor.setHandler(new ChatHandler());
-
- acceptor .bind(new InetSocketAddress(6789));
44. Fire up yourterminals telnet 62.12.11.90 6789 45. http://mina.apache.org 46. [email_address] 47. Questions ? 48. http://flickr.com/photos/samiksha/408007916/ http://flickr.com/photos/henrikmoltke/142750871/