A {@link DatagramChannelFactory} that creates a NIO-based connectionless{@link DatagramChannel}. It utilizes the non-blocking I/O mode which was introduced with NIO to serve many number of concurrent connections efficiently.
How threads work
There is only one thread type in a {@link NioDatagramChannelFactory}; worker threads.
Worker threads
One {@link NioDatagramChannelFactory} can have one or more workerthreads. A worker thread performs non-blocking read and write for one or more {@link DatagramChannel}s in a non-blocking mode.
Life cycle of threads and graceful shutdown
All worker threads are acquired from the {@link Executor} which was specifiedwhen a {@link NioDatagramChannelFactory} was created. Therefore, you shouldmake sure the specified {@link Executor} is able to lend the sufficientnumber of threads. It is the best bet to specify {@linkplain Executors#newCachedThreadPool() a cached thread pool}.
All worker threads are acquired lazily, and then released when there's nothing left to process. All the related resources such as {@link Selector}are also released when the worker threads are released. Therefore, to shut down a service gracefully, you should do the following:
- close all channels created by the factory usually using {@link ChannelGroup#close()}, and
- call {@link #releaseExternalResources()}.
Please make sure not to shut down the executor until all channels are closed. Otherwise, you will end up with a {@link RejectedExecutionException}and the related resources might not be released properly.
Limitation
Multicast is not supported. Please use {@link OioDatagramChannelFactory}instead.
@author The Netty Project (netty-dev@lists.jboss.org)
@author Trustin Lee (tlee@redhat.com)
@author Daniel Bevenius (dbevenius@jboss.com)
@version $Rev: 1580 $, $Date: 2009-07-17 21:49:32 +0900 (Fri, 17 Jul 2009) $
@apiviz.landmark