Netty is a NIO client-server framework, which enables quick and easy development of
network applications, such as protocol servers and clients. Netty offers you a new way to
develop your network applications, which makes it easy and scalable. It achieves this by
abstracting away the complexity involved and by providing an easy-to-use API that
decouples business-logic from the network-handling code. Because it’s built for NIO, the
entire Netty API is asynchronous.
Development Area Netty Features
Design
• Unified API for various transport types—blocking and non-blocking socket
• Flexible to use
• Simple but powerful thread-model
• True connectionless datagram socket support
• Chaining of logics to make reuse easy
Ease of Use
• Well-documented Javadoc and plenty of examples provided
• No additional dependencies except JDK 1.6 (or above). Some features are
supported only in Java 1.7 and above. Other features may have other
dependencies, but these are optional
Performance
• Better throughput; lower latency than core Java APIs
• Less resource consumption because of pooling and reuse
• Minimized unnecessary memory copy Robustness
• No more Out Of Memory Error due to fast, slow, or overloaded connection.
• No more unfair read/write ratio often found in a NIO application in high-speed
networks
Security
• Complete SSL/TLS and StartTLS support
• Runs in a restricted environment such as Applet or OSGI
Community
• Release early, release often
• Active
Non-blocking IO basics
BYTEBUFFER
A ByteBuffer is fundamental to both NIO APIs and, indeed, to Netty. A ByteBuffer can
either be allocated on the heap or directly, which means it’s stored outside of the Heap-
Space.
• Writing data to the ByteBuffer
• Calling ByteBuffer.flip() to adjust the position and limit
• Reading data out of the ByteBuffer
• Calling either ByteBuffer.clear() or ByteBuffer.compact()
A selector is a NIO component that determines if one or more channels are ready for
reading and/or writing, thus a single select selector can be used to handle multiple
connections, alleviating the need for the thread-per-connection model you saw in the
blocking IO EchoServer example.
To use selectors, you typically complete the following steps.
1. Create one or more selectors to which opened channels (sockets) can be registered.
2. When a channel is registered, you specify which events you’re interested in listening
in.
The four available events (or Ops/operations) are:
• OP_ACCEPT—Operation-set bit for socket-accept operations
• OP_CONNECT—Operation-set bit for socket-connect operations
• OP_READ—Operation-set bit for read operations
• OP_WRITE—Operation-set bit for write operations
3. When channels are registered, you call the Selector.select() method to block
until one of these events occurs.
4. When the method unblocks, you can obtain all of the SelectionKey instances (which
hold the reference to the registered channel and to selected Ops) and do something.
What exactly you do depends on which operation is ready. A SelectedKey can
include more than one operation at any given time.
Cross-platform and compatibility issues
NIO is low level and depends on how the operating system (OS) handles IO. So fulfilling the
requirement of having a unified API exposed in Java, which works and behaves the same on all OSs, isn’t trivial.
reference site : http://netty.io/wiki/user-guide-for-4.x.html
from netty in action
댓글 없음:
댓글 쓰기