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.channel.ChannelFlushPromiseNotifier.FlushCheckpoint;
19 import io.netty.util.concurrent.DefaultPromise;
20 import io.netty.util.concurrent.EventExecutor;
21 import io.netty.util.concurrent.Future;
22 import io.netty.util.concurrent.GenericFutureListener;
23
24 import static io.netty.util.internal.ObjectUtil.checkNotNull;
25
26
27
28
29
30 public class DefaultChannelPromise extends DefaultPromise<Void> implements ChannelPromise, FlushCheckpoint {
31
32 private final Channel channel;
33 private long checkpoint;
34
35
36
37
38
39
40
41 public DefaultChannelPromise(Channel channel) {
42 this.channel = checkNotNull(channel, "channel");
43 }
44
45
46
47
48
49
50
51 public DefaultChannelPromise(Channel channel, EventExecutor executor) {
52 super(executor);
53 this.channel = checkNotNull(channel, "channel");
54 }
55
56 @Override
57 protected EventExecutor executor() {
58 EventExecutor e = super.executor();
59 if (e == null) {
60 return channel().eventLoop();
61 } else {
62 return e;
63 }
64 }
65
66 @Override
67 public Channel channel() {
68 return channel;
69 }
70
71 @Override
72 public ChannelPromise setSuccess() {
73 return setSuccess(null);
74 }
75
76 @Override
77 public ChannelPromise setSuccess(Void result) {
78 super.setSuccess(result);
79 return this;
80 }
81
82 @Override
83 public boolean trySuccess() {
84 return trySuccess(null);
85 }
86
87 @Override
88 public ChannelPromise setFailure(Throwable cause) {
89 super.setFailure(cause);
90 return this;
91 }
92
93 @Override
94 public ChannelPromise addListener(GenericFutureListener<? extends Future<? super Void>> listener) {
95 super.addListener(listener);
96 return this;
97 }
98
99 @Override
100 public ChannelPromise addListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
101 super.addListeners(listeners);
102 return this;
103 }
104
105 @Override
106 public ChannelPromise removeListener(GenericFutureListener<? extends Future<? super Void>> listener) {
107 super.removeListener(listener);
108 return this;
109 }
110
111 @Override
112 public ChannelPromise removeListeners(GenericFutureListener<? extends Future<? super Void>>... listeners) {
113 super.removeListeners(listeners);
114 return this;
115 }
116
117 @Override
118 public ChannelPromise sync() throws InterruptedException {
119 super.sync();
120 return this;
121 }
122
123 @Override
124 public ChannelPromise syncUninterruptibly() {
125 super.syncUninterruptibly();
126 return this;
127 }
128
129 @Override
130 public ChannelPromise await() throws InterruptedException {
131 super.await();
132 return this;
133 }
134
135 @Override
136 public ChannelPromise awaitUninterruptibly() {
137 super.awaitUninterruptibly();
138 return this;
139 }
140
141 @Override
142 public long flushCheckpoint() {
143 return checkpoint;
144 }
145
146 @Override
147 public void flushCheckpoint(long checkpoint) {
148 this.checkpoint = checkpoint;
149 }
150
151 @Override
152 public ChannelPromise promise() {
153 return this;
154 }
155
156 @Override
157 protected void checkDeadLock() {
158 if (channel().isRegistered()) {
159 super.checkDeadLock();
160 }
161 }
162 }