If you can't read please download the document
Apachecon Eu 2008 Mina
Embed Size (px)
Citation preview
2. Niklas Gustavsson [email_address] http://protocol7.com 3.
4.
5.
-
- Java API for network applications
6.
7.
8.
-
- Pluggable implementations
9.
10.
11.
12.
13. IoService IoConnector IoAcceptor 14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
-
- Fine, so what's best for me?
24.
25.
26.
27.
-
- and default to heap allocation
28.
29.
30.
-
- So, which version shouldI use?
31.
32.
33.
34.
35.
36.
-
- Update class and package names
37.
38.
39.
-
- public final static Chat INSTANCE = new Chat();
-
- private List users = new ArrayList();
-
- public void addUser(User user) {
-
- public void removeUser(User user) {
-
- public void talkToAll(Message 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);
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.
-
- public void messageReceived(IoSession session,Object o) throws
Exception {
-
- Message msg = (Message) o;
-
- if(msg.getText().equalsIgnoreCase("QUIT")) {
-
- 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/