1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.nio;
17
18 import io.netty.channel.Channel;
19 import io.netty.channel.DefaultSelectStrategyFactory;
20 import io.netty.channel.MultithreadEventLoopGroup;
21 import io.netty.channel.SelectStrategyFactory;
22 import io.netty.util.concurrent.EventExecutor;
23 import io.netty.util.concurrent.RejectedExecutionHandler;
24 import io.netty.util.concurrent.RejectedExecutionHandlers;
25
26 import java.nio.channels.Selector;
27 import java.nio.channels.spi.SelectorProvider;
28 import java.util.concurrent.ThreadFactory;
29
30
31
32
33 public class NioEventLoopGroup extends MultithreadEventLoopGroup {
34
35
36
37
38
39 public NioEventLoopGroup() {
40 this(0);
41 }
42
43
44
45
46
47 public NioEventLoopGroup(int nThreads) {
48 this(nThreads, null);
49 }
50
51
52
53
54
55 public NioEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
56 this(nThreads, threadFactory, SelectorProvider.provider());
57 }
58
59
60
61
62
63 public NioEventLoopGroup(
64 int nThreads, ThreadFactory threadFactory, final SelectorProvider selectorProvider) {
65 this(nThreads, threadFactory, selectorProvider, DefaultSelectStrategyFactory.INSTANCE);
66 }
67
68 public NioEventLoopGroup(int nThreads, ThreadFactory threadFactory,
69 final SelectorProvider selectorProvider, final SelectStrategyFactory selectStrategyFactory) {
70 super(nThreads, threadFactory, selectorProvider, selectStrategyFactory, RejectedExecutionHandlers.reject());
71 }
72
73 public NioEventLoopGroup(int nThreads, ThreadFactory threadFactory,
74 final SelectorProvider selectorProvider,
75 final SelectStrategyFactory selectStrategyFactory,
76 final RejectedExecutionHandler rejectedExecutionHandler) {
77 super(nThreads, threadFactory, selectorProvider, selectStrategyFactory, rejectedExecutionHandler);
78 }
79
80
81
82
83
84 public void setIoRatio(int ioRatio) {
85 for (EventExecutor e: children()) {
86 ((NioEventLoop) e).setIoRatio(ioRatio);
87 }
88 }
89
90
91
92
93
94 public void rebuildSelectors() {
95 for (EventExecutor e: children()) {
96 ((NioEventLoop) e).rebuildSelector();
97 }
98 }
99
100 @Override
101 protected EventExecutor newChild(ThreadFactory threadFactory, Object... args) throws Exception {
102 return new NioEventLoop(this, threadFactory, (SelectorProvider) args[0],
103 ((SelectStrategyFactory) args[1]).newSelectStrategy(), (RejectedExecutionHandler) args[2]);
104 }
105 }