/** * Creates a new instance. * * @param workerPool * the {@link WorkerPool} which will be used to obtain the {@link Worker} that execute * the I/O worker threads * @param family * the {@link InternetProtocolFamily} to use. This should be used for UDP multicast. * <strong>Be aware that this option is only considered when running on java7+</strong> */ public NioDatagramChannelFactory(WorkerPool<NioDatagramWorker> workerPool, InternetProtocolFamily family) { this.workerPool = workerPool; this.family = family; sink = new NioDatagramPipelineSink(workerPool); }
public DatagramChannel newChannel(final ChannelPipeline pipeline) { return new NioDatagramChannel(this, pipeline, sink, sink.nextWorker(), family); }
/** * Will bind the DatagramSocket to the passed-in address. * Every call bind will spawn a new thread using the that basically in turn */ private static void bind(final NioDatagramChannel channel, final ChannelFuture future, final InetSocketAddress address) { boolean bound = false; boolean started = false; try { // First bind the DatagramSocket the specified port. channel.getDatagramChannel().socket().bind(address); bound = true; future.setSuccess(); fireChannelBound(channel, address); channel.worker.register(channel, null); started = true; } catch (final Throwable t) { future.setFailure(t); fireExceptionCaught(channel, t); } finally { if (!started && bound) { close(channel, future); } } }
/** * Will bind the DatagramSocket to the passed-in address. * Every call bind will spawn a new thread using the that basically in turn */ private static void bind(final NioDatagramChannel channel, final ChannelFuture future, final InetSocketAddress address) { boolean bound = false; boolean started = false; try { // First bind the DatagramSocket the specified port. channel.getDatagramChannel().socket().bind(address); bound = true; future.setSuccess(); fireChannelBound(channel, address); channel.worker.register(channel, null); started = true; } catch (final Throwable t) { future.setFailure(t); fireExceptionCaught(channel, t); } finally { if (!started && bound) { close(channel, future); } } }
/** * Create a new {@link NioDatagramChannelFactory} with a {@link Executors#newCachedThreadPool()}. * * See {@link #NioDatagramChannelFactory(Executor)} */ public NioDatagramChannelFactory(InternetProtocolFamily family) { workerPool = new NioDatagramWorkerPool(Executors.newCachedThreadPool(), SelectorUtil.DEFAULT_IO_THREADS); this.family = family; sink = new NioDatagramPipelineSink(workerPool); releasePool = true; }
public NioClientDatagramChannelFactory(WorkerPool<NioWorker> workerPool) { this.workerPool = workerPool; this.family = null; sink = new NioDatagramPipelineSink(); releasePool = true; }
public NioServerDatagramChannelFactory(Executor bossExecutor, int bossCount, WorkerPool<NioWorker> workerPool) { bossPool = new NioDatagramBossPool(bossExecutor, bossCount, null); this.workerPool = workerPool; this.family = null; sink = new NioDatagramPipelineSink(); childSink = new NioChildDatagramPipelineSink(); releasePool = true; }