1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel;
17
18 import io.netty.util.NettyRuntime;
19 import io.netty.util.concurrent.DefaultThreadFactory;
20 import io.netty.util.concurrent.EventExecutorChooserFactory;
21 import io.netty.util.concurrent.MultithreadEventExecutorGroup;
22 import io.netty.util.internal.SystemPropertyUtil;
23 import io.netty.util.internal.logging.InternalLogger;
24 import io.netty.util.internal.logging.InternalLoggerFactory;
25
26 import java.util.concurrent.Executor;
27 import java.util.concurrent.ThreadFactory;
28
29
30
31
32
33 public abstract class MultithreadEventLoopGroup extends MultithreadEventExecutorGroup implements EventLoopGroup {
34
35 private static final InternalLogger logger = InternalLoggerFactory.getInstance(MultithreadEventLoopGroup.class);
36
37 private static final int DEFAULT_EVENT_LOOP_THREADS;
38
39 static {
40 DEFAULT_EVENT_LOOP_THREADS = Math.max(1, SystemPropertyUtil.getInt(
41 "io.netty.eventLoopThreads", NettyRuntime.availableProcessors() * 2));
42
43 if (logger.isDebugEnabled()) {
44 logger.debug("-Dio.netty.eventLoopThreads: {}", DEFAULT_EVENT_LOOP_THREADS);
45 }
46 }
47
48
49
50
51 protected MultithreadEventLoopGroup(int nThreads, Executor executor, Object... args) {
52 super(nThreads == 0 ? DEFAULT_EVENT_LOOP_THREADS : nThreads, executor, args);
53 }
54
55
56
57
58 protected MultithreadEventLoopGroup(int nThreads, ThreadFactory threadFactory, Object... args) {
59 super(nThreads == 0 ? DEFAULT_EVENT_LOOP_THREADS : nThreads, threadFactory, args);
60 }
61
62
63
64
65
66 protected MultithreadEventLoopGroup(int nThreads, Executor executor, EventExecutorChooserFactory chooserFactory,
67 Object... args) {
68 super(nThreads == 0 ? DEFAULT_EVENT_LOOP_THREADS : nThreads, executor, chooserFactory, args);
69 }
70
71 @Override
72 protected ThreadFactory newDefaultThreadFactory() {
73 return new DefaultThreadFactory(getClass(), Thread.MAX_PRIORITY);
74 }
75
76 @Override
77 public EventLoop next() {
78 return (EventLoop) super.next();
79 }
80
81 @Override
82 protected abstract EventLoop newChild(Executor executor, Object... args) throws Exception;
83
84 @Override
85 public ChannelFuture register(Channel channel) {
86 return next().register(channel);
87 }
88
89 @Override
90 public ChannelFuture register(ChannelPromise promise) {
91 return next().register(promise);
92 }
93
94 @Deprecated
95 @Override
96 public ChannelFuture register(Channel channel, ChannelPromise promise) {
97 return next().register(channel, promise);
98 }
99
100 }