1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.netty.util.concurrent;
18
19 import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
20
21 public class DefaultProgressivePromise<V> extends DefaultPromise<V> implements ProgressivePromise<V> {
22
23
24
25
26
27
28
29
30
31 public DefaultProgressivePromise(EventExecutor executor) {
32 super(executor);
33 }
34
35 protected DefaultProgressivePromise() { }
36
37 @Override
38 public ProgressivePromise<V> setProgress(long progress, long total) {
39 if (total < 0) {
40
41 total = -1;
42 checkPositiveOrZero(progress, "progress");
43 } else if (progress < 0 || progress > total) {
44 throw new IllegalArgumentException(
45 "progress: " + progress + " (expected: 0 <= progress <= total (" + total + "))");
46 }
47
48 if (isDone()) {
49 throw new IllegalStateException("complete already");
50 }
51
52 notifyProgressiveListeners(progress, total);
53 return this;
54 }
55
56 @Override
57 public boolean tryProgress(long progress, long total) {
58 if (total < 0) {
59 total = -1;
60 if (progress < 0 || isDone()) {
61 return false;
62 }
63 } else if (progress < 0 || progress > total || isDone()) {
64 return false;
65 }
66
67 notifyProgressiveListeners(progress, total);
68 return true;
69 }
70
71 @Override
72 public ProgressivePromise<V> addListener(GenericFutureListener<? extends Future<? super V>> listener) {
73 super.addListener(listener);
74 return this;
75 }
76
77 @Override
78 public ProgressivePromise<V> addListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
79 super.addListeners(listeners);
80 return this;
81 }
82
83 @Override
84 public ProgressivePromise<V> removeListener(GenericFutureListener<? extends Future<? super V>> listener) {
85 super.removeListener(listener);
86 return this;
87 }
88
89 @Override
90 public ProgressivePromise<V> removeListeners(GenericFutureListener<? extends Future<? super V>>... listeners) {
91 super.removeListeners(listeners);
92 return this;
93 }
94
95 @Override
96 public ProgressivePromise<V> sync() throws InterruptedException {
97 super.sync();
98 return this;
99 }
100
101 @Override
102 public ProgressivePromise<V> syncUninterruptibly() {
103 super.syncUninterruptibly();
104 return this;
105 }
106
107 @Override
108 public ProgressivePromise<V> await() throws InterruptedException {
109 super.await();
110 return this;
111 }
112
113 @Override
114 public ProgressivePromise<V> awaitUninterruptibly() {
115 super.awaitUninterruptibly();
116 return this;
117 }
118
119 @Override
120 public ProgressivePromise<V> setSuccess(V result) {
121 super.setSuccess(result);
122 return this;
123 }
124
125 @Override
126 public ProgressivePromise<V> setFailure(Throwable cause) {
127 super.setFailure(cause);
128 return this;
129 }
130 }