1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel;
17
18
19
20
21
22
23
24 @Deprecated
25 public class ThreadPerChannelEventLoop extends SingleThreadEventLoop {
26
27 private final ThreadPerChannelEventLoopGroup parent;
28 private Channel ch;
29
30 public ThreadPerChannelEventLoop(ThreadPerChannelEventLoopGroup parent) {
31 super(parent, parent.executor, true);
32 this.parent = parent;
33 }
34
35 @Override
36 public ChannelFuture register(ChannelPromise promise) {
37 return super.register(promise).addListener(new ChannelFutureListener() {
38 @Override
39 public void operationComplete(ChannelFuture future) throws Exception {
40 if (future.isSuccess()) {
41 ch = future.channel();
42 } else {
43 deregister();
44 }
45 }
46 });
47 }
48
49 @Deprecated
50 @Override
51 public ChannelFuture register(Channel channel, ChannelPromise promise) {
52 return super.register(channel, promise).addListener(new ChannelFutureListener() {
53 @Override
54 public void operationComplete(ChannelFuture future) throws Exception {
55 if (future.isSuccess()) {
56 ch = future.channel();
57 } else {
58 deregister();
59 }
60 }
61 });
62 }
63
64 @Override
65 protected void run() {
66 for (;;) {
67 Runnable task = takeTask();
68 if (task != null) {
69 task.run();
70 updateLastExecutionTime();
71 }
72
73 Channel ch = this.ch;
74 if (isShuttingDown()) {
75 if (ch != null) {
76 ch.unsafe().close(ch.unsafe().voidPromise());
77 }
78 if (confirmShutdown()) {
79 break;
80 }
81 } else {
82 if (ch != null) {
83
84 if (!ch.isRegistered()) {
85 runAllTasks();
86 deregister();
87 }
88 }
89 }
90 }
91 }
92
93 protected void deregister() {
94 ch = null;
95 parent.activeChildren.remove(this);
96 parent.idleChildren.add(this);
97 }
98
99 @Override
100 public int registeredChannels() {
101 return 1;
102 }
103 }