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.concurrent.EventExecutorGroup;
19 import io.netty.util.concurrent.RejectedExecutionHandler;
20 import io.netty.util.concurrent.RejectedExecutionHandlers;
21 import io.netty.util.concurrent.SingleThreadEventExecutor;
22 import io.netty.util.internal.SystemPropertyUtil;
23
24 import java.util.concurrent.ThreadFactory;
25
26
27
28
29
30 public abstract class SingleThreadEventLoop extends SingleThreadEventExecutor implements EventLoop {
31
32 protected static final int DEFAULT_MAX_PENDING_TASKS = Math.max(16,
33 SystemPropertyUtil.getInt("io.netty.eventLoop.maxPendingTasks", Integer.MAX_VALUE));
34
35
36
37
38 protected SingleThreadEventLoop(EventLoopGroup parent, ThreadFactory threadFactory, boolean addTaskWakesUp) {
39 this(parent, threadFactory, addTaskWakesUp, DEFAULT_MAX_PENDING_TASKS, RejectedExecutionHandlers.reject());
40 }
41
42 protected SingleThreadEventLoop(EventLoopGroup parent, ThreadFactory threadFactory,
43 boolean addTaskWakesUp, int maxPendingTasks,
44 RejectedExecutionHandler rejectedExecutionHandler) {
45 super(parent, threadFactory, addTaskWakesUp, maxPendingTasks, rejectedExecutionHandler);
46 }
47
48 @Override
49 public EventLoopGroup parent() {
50 return (EventLoopGroup) super.parent();
51 }
52
53 @Override
54 public EventLoop next() {
55 return (EventLoop) super.next();
56 }
57
58 @Override
59 public ChannelFuture register(Channel channel) {
60 return register(channel, new DefaultChannelPromise(channel, this));
61 }
62
63 @Override
64 public ChannelFuture register(final Channel channel, final ChannelPromise promise) {
65 if (channel == null) {
66 throw new NullPointerException("channel");
67 }
68 if (promise == null) {
69 throw new NullPointerException("promise");
70 }
71
72 channel.unsafe().register(this, promise);
73 return promise;
74 }
75
76 @Override
77 protected boolean wakesUpForTask(Runnable task) {
78 return !(task instanceof NonWakeupRunnable);
79 }
80
81
82
83
84 interface NonWakeupRunnable extends Runnable { }
85 }