Your SlideShare is downloading. ×
0
Apache MINA2  Author: Quốc Minh Đức  Since: 2008 July
Outline Introduction Architecture Core components Synopsis Demo2
Introduction – what is Apache MINA? A Java open-source network application framework. Abstract API                      ...
Introduction – MINA2 pros Reusable and Maintainable    • Networking engine – MINA I/O service    • Protocol codec – MINA ...
Outline Introduction Architecture Core components Synopsis Demo5
Architecture – what does it look like? Perform actual I/O -------- Filter events & requests - A connection ------------...
Architecture – basic components         IoAcceptor, IoConnector    Base of Chain of IoFilters: LoggingFilter, SslFilter,...
Outline Introduction Architecture Core components Synopsis Demo8
Core components – IoSession Abstract a underlying transports connection away    (Socket, Channel, ... ) Provides asynchr...
Core components – IoService IoAcceptor (extends IoService) is for the server side MINA classes implement IoAcceptor (act...
Core components – IoService (cont.) IoConnector (extends IoService) is for the client side MINA classes implement IoConn...
Core components – IoBuffer Replacement for NIO ByteBuffer              Provides all methods in ByteBuffer (get, put, fli...
Core components – IoHandler IoHandler implementations is for the logic processing You can also extend IoHandlerAdapter (...
Core components – IoFilter Concerns seperated to cross-cutting ones to handle              Logging              Thread-...
Core components – IoFilterChain Filter all events (read/write/idle... ) , per connection Fire qualified events to next F...
Core components – ProtocolCodecFilter Why Protocol ?              Packets order/assembly control              Message p...
Core components – ProtocolCodecFilter What does ProtocolCodecFilter looks like ?17
Core components – ProtocolCodecFilter Rewrite EchoHandler code using ProtocolCodecFilter     + TextLineCodecFactory (byte...
Core components – ExecutorFilter ThreadModel – for thread pooling in MINA 1.x - has been     removed in MINA 2.x . Replac...
Outline Introduction Architecture Core components Synopsis Demo20
Synopsis – Apache MINA2 A network (client/server) application framework based on NIO MINA is designed for network applic...
Synopsis – recommended application pattern    basic IoService with IoAcceptor (server) or IoConnector (client)    Add Ex...
Outline Introduction Architecture Core components Synopsis Demo23
Demo TCP (PalindromeServer) UDP (NetworkTimeServer) ProtocolCodecFilter extension( minimum libraries: mina-core-2.xxx.j...
Q&A     Thank you :-)25
Bonus Apache Directory ( http://directory.apache.org ) SubEtha SMTP ( http://subethasmtp.tigris.org ) Apache Qpid - AMQ...
Bonus      Define ImageCodecFilter protocol:       ►Request Message:              4 byte               4 byte            ...
Bonus      Define ImageCodecFilter protocol:       ►Response Message:           4 byte         n byte         4 byte     ...
Upcoming SlideShare
Loading in...5
×

Mina2

1,571

Published on

Apache MINA framework version 2.x

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

No Downloads
Views
Total Views
1,571
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
26
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Transcript of "Mina2"

  1. 1. Apache MINA2 Author: Quốc Minh Đức Since: 2008 July
  2. 2. Outline Introduction Architecture Core components Synopsis Demo2
  3. 3. Introduction – what is Apache MINA? A Java open-source network application framework. Abstract API Multi-purpose  Event-driven , built on Java New I/O  Asynchronous , non-blocking Infrastructure for Unit-testable Network  Implementations Applications  Socket (TCP) & Datagram (UDP)  In-VM pipes* , Apache Protable Runtime (APR)*  Serial Port (RS232)* - RxTx.org  User-defined protocol3 * : new features since 2.0
  4. 4. Introduction – MINA2 pros Reusable and Maintainable • Networking engine – MINA I/O service • Protocol codec – MINA codec framework • Your business logic Extensible http://mina.apache.org/ • Runtime modification of application behaviour using filter Manageable • Introspection of connections and services via JMX API Unit-testable • Abstract API , mock objects4
  5. 5. Outline Introduction Architecture Core components Synopsis Demo5
  6. 6. Architecture – what does it look like? Perform actual I/O -------- Filter events & requests - A connection --------------- <Your protocol logic> ----6
  7. 7. Architecture – basic components IoAcceptor, IoConnector Base of Chain of IoFilters: LoggingFilter, SslFilter, ProtocolCodecFilter, ExecutorFilter, ... Connection instance: IoSession Logic processing: IoHandler, IoBuffer, ByteBuffer, ...7
  8. 8. Outline Introduction Architecture Core components Synopsis Demo8
  9. 9. Core components – IoSession Abstract a underlying transports connection away (Socket, Channel, ... ) Provides asynchronous operation to I/O service  Write, close ...  Asynchronous , non-blocking  Returns IoFuture (WriteFuture, CloseFuture... )  (you can add more IoFutureListener for notification ) Provides I/O statistics  Read bytes, written bytes, last I/O time...9
  10. 10. Core components – IoService IoAcceptor (extends IoService) is for the server side MINA classes implement IoAcceptor (act as server) :  NioSocketAcceptor , NioDatagramAcceptor  VmPipeAcceptor10  AprAcceptor* , SerialAcceptor*
  11. 11. Core components – IoService (cont.) IoConnector (extends IoService) is for the client side MINA classes implement IoConnector (act as client) :  NioSocketConnector , NioDatagramConnector  VmPipeConnector11  AprConnector* , SerialConnector*
  12. 12. Core components – IoBuffer Replacement for NIO ByteBuffer  Provides all methods in ByteBuffer (get, put, flip, remaining... )  Provides easy wrap/unwrap methods  More extensible Rich (low-level) manipulation methods on text & binary  Unsigned value, enum, String, Java Object... More control over allocation mechanism On-demand automatic expansion and shrinkage12
  13. 13. Core components – IoHandler IoHandler implementations is for the logic processing You can also extend IoHandlerAdapter (base class)13
  14. 14. Core components – IoFilter Concerns seperated to cross-cutting ones to handle  Logging  Thread-safe/Overload prevention  Remote Peer blacklisting (firewall)  Encoder/Decoder for transport protocol  Statistics/Management  Compression  SSL/TLS  More to come – whatever you want to intercept ! Reuseable, extensible, hot-deployable14
  15. 15. Core components – IoFilterChain Filter all events (read/write/idle... ) , per connection Fire qualified events to next Filter / Handler15
  16. 16. Core components – ProtocolCodecFilter Why Protocol ?  Packets order/assembly control  Message position control Why ProtocolCodecFilter ?  Bad idea to implement a protocol with only ByteBuffer (Packet fragmentation and assembly, complex logic)  Codecs are often reusable MINA ProtocolCodecFilter provides :  Text line codec  Object stream codec16  Reusable components to build a custom-codec
  17. 17. Core components – ProtocolCodecFilter What does ProtocolCodecFilter looks like ?17
  18. 18. Core components – ProtocolCodecFilter Rewrite EchoHandler code using ProtocolCodecFilter + TextLineCodecFactory (bytes to Java Strings)18
  19. 19. Core components – ExecutorFilter ThreadModel – for thread pooling in MINA 1.x - has been removed in MINA 2.x . Replacement: explicit ExecutorFilter19
  20. 20. Outline Introduction Architecture Core components Synopsis Demo20
  21. 21. Synopsis – Apache MINA2 A network (client/server) application framework based on NIO MINA is designed for network applications:  Stable  Scalable  Extensible  Manageable, unit-testable  Ease-of-use, elegant MINA supports various network protocols (simple, complex), data (text, binary) , and evolving standards.21
  22. 22. Synopsis – recommended application pattern basic IoService with IoAcceptor (server) or IoConnector (client) Add ExecutorFilter explicitly to chain for multi-threading  Unless you need really low latency Use ProtocolCodecFilter  Convert the transport protocol into a Java representation Put application logic into an IoHandler Store state in the IoSession Combine all using minimum Java (5 or above)22
  23. 23. Outline Introduction Architecture Core components Synopsis Demo23
  24. 24. Demo TCP (PalindromeServer) UDP (NetworkTimeServer) ProtocolCodecFilter extension( minimum libraries: mina-core-2.xxx.jar, slf4j-api-1.yyy.jar, slf4j-simple-1.yyy.jar )24
  25. 25. Q&A Thank you :-)25
  26. 26. Bonus Apache Directory ( http://directory.apache.org ) SubEtha SMTP ( http://subethasmtp.tigris.org ) Apache Qpid - AMQP ( http://cwiki.apache.org/qpid ) OpenFire - XMPP ( http://jivesoftware.com/products ) Red5 - RTMP ( http://osflash.org/red5 ) And more... (may be you, next time ! )26
  27. 27. Bonus  Define ImageCodecFilter protocol: ►Request Message: 4 byte 4 byte 4 byte width height numchar • width: the width of the requested image • height: the height of the requested image • numchar: the number of chars to generate27
  28. 28. Bonus  Define ImageCodecFilter protocol: ►Response Message: 4 byte n byte 4 byte m byte Length1 (n) image1 Length2 (m) image2 • length1: the number of bytes used by image1 • image1: an image in PNG format • length2: the number of bytes used by image2 • image2: an image in PNG format28
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×