XNIO Concepts: Difference between revisions
(22 intermediate revisions by the same user not shown) | |||
Line 10: | Line 10: | ||
=NIO Concepts= | =NIO Concepts= | ||
* [[ | * [[Java_Non-Blocking_I/O_Concepts#ByteBuffer|NIO ByteBuffer]] | ||
* [[Java_Non-Blocking_I/O_Concepts#Channel|NIO Channel]] | |||
=XNIO Worker= | =XNIO Worker= | ||
Line 20: | Line 21: | ||
==I/O Thread== | ==I/O Thread== | ||
The I/O threads run non-blocking handlers. They run in a loop, which does three things: | |||
# runs any tasks that have been scheduled for execution by the I/O thread | |||
# runs any scheduled tasks that have hit their timeout | |||
# call <tt>Selector.start()</tt> and then invoke any callbacks for the selected keys. | |||
The I/O must never perform blocking operations because they are responsible for multiple connections, so while the operation is blocking, the other connections will essentially hang. | |||
The I/O threads come in two types: | The I/O threads come in two types: | ||
* '''Read threads''' that can handle callbacks for read events. | * '''Read threads''' that can handle callbacks for read events. | ||
* '''Write threads''' that can handle callback for write events. | * '''Write threads''' that can handle callback for write events. | ||
For details on how to configure I/O Threads see [[XNIO Configuration#WORKER_IO_THREADS|XNIO Configuration]]. | |||
==Worker Thread== | ==Worker Thread== | ||
Worker threads are used for | Worker threads are used for blocking tasks (such as servlet invocations). The worker threads are managed by a standard Executor-based thread pool. | ||
For details on how to configure worker threads see [[XNIO Configuration#WORKER_TASK_CORE_THREADS|XNIO Configuration]]. | |||
=Channel= | =Channel= | ||
Line 33: | Line 45: | ||
XNIO provides a channel abstraction that hides the underlying transport. Channels are notified of events using the <tt>ChannelListener</tt> API. Upon creation, channels are assigned an [[#I.2FO_Thread|I/O Thread]], which will be used to execute all <tt>ChannelListener</tt> invocations for the channel. | XNIO provides a channel abstraction that hides the underlying transport. Channels are notified of events using the <tt>ChannelListener</tt> API. Upon creation, channels are assigned an [[#I.2FO_Thread|I/O Thread]], which will be used to execute all <tt>ChannelListener</tt> invocations for the channel. | ||
= | Also see [[NIO Concepts#Channel|NIO Channel]]. | ||
=ChannelListener= | |||
A <tt>ChannelListener</tt> is a listener for [[#Channel|Channel]] events, such as: channel readable, channel writable, channel opened, channel closed, channel bound, channel unbound. |
Latest revision as of 22:51, 25 July 2018
Internal
Overview
XNIO is a simplified low-level I/O layer, built in top of Java NIO. It has an API for combining blocking and non-blocking operations, even on the same channel.
NIO Concepts
XNIO Worker
- https://docs.jboss.org/author/display/XNIO/Workers
- http://docs.jboss.org/xnio/3.1/api/index.html?org/xnio/XnioWorker.html
An XNIO worker is the central point of coordination for a network application. It manages several kind of threads, and the threads created by the worker are tagged with the worker name. A worker has two different types of thread pools:
I/O Thread
The I/O threads run non-blocking handlers. They run in a loop, which does three things:
- runs any tasks that have been scheduled for execution by the I/O thread
- runs any scheduled tasks that have hit their timeout
- call Selector.start() and then invoke any callbacks for the selected keys.
The I/O must never perform blocking operations because they are responsible for multiple connections, so while the operation is blocking, the other connections will essentially hang.
The I/O threads come in two types:
- Read threads that can handle callbacks for read events.
- Write threads that can handle callback for write events.
For details on how to configure I/O Threads see XNIO Configuration.
Worker Thread
Worker threads are used for blocking tasks (such as servlet invocations). The worker threads are managed by a standard Executor-based thread pool.
For details on how to configure worker threads see XNIO Configuration.
Channel
XNIO provides a channel abstraction that hides the underlying transport. Channels are notified of events using the ChannelListener API. Upon creation, channels are assigned an I/O Thread, which will be used to execute all ChannelListener invocations for the channel.
Also see NIO Channel.
ChannelListener
A ChannelListener is a listener for Channel events, such as: channel readable, channel writable, channel opened, channel closed, channel bound, channel unbound.