1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.core.future;
21
22 import java.io.IOException;
23
24 import org.apache.mina.core.RuntimeIoException;
25 import org.apache.mina.core.session.IoSession;
26
27
28
29
30
31
32 public class DefaultReadFuture extends DefaultIoFuture implements ReadFuture {
33
34 private static final Object CLOSED = new Object();
35
36
37
38
39
40
41 public DefaultReadFuture(IoSession session) {
42 super(session);
43 }
44
45
46
47
48 @Override
49 public Object getMessage() {
50 if (isDone()) {
51 Object v = getValue();
52
53 if (v == CLOSED) {
54 return null;
55 }
56
57 if (v instanceof RuntimeException) {
58 throw (RuntimeException) v;
59 }
60
61 if (v instanceof Error) {
62 throw (Error) v;
63 }
64
65 if (v instanceof IOException || v instanceof Exception) {
66 throw new RuntimeIoException((Exception) v);
67 }
68
69 return v;
70 }
71
72 return null;
73 }
74
75
76
77
78 @Override
79 public boolean isRead() {
80 if (isDone()) {
81 Object v = getValue();
82
83 return v != CLOSED && !(v instanceof Throwable);
84 }
85
86 return false;
87 }
88
89
90
91
92 @Override
93 public boolean isClosed() {
94 if (isDone()) {
95 return getValue() == CLOSED;
96 }
97
98 return false;
99 }
100
101
102
103
104 @Override
105 public Throwable getException() {
106 if (isDone()) {
107 Object v = getValue();
108
109 if (v instanceof Throwable) {
110 return (Throwable)v;
111 }
112 }
113
114 return null;
115 }
116
117
118
119
120 @Override
121 public void setClosed() {
122 setValue(CLOSED);
123 }
124
125
126
127
128 @Override
129 public void setRead(Object message) {
130 if (message == null) {
131 throw new IllegalArgumentException("message");
132 }
133
134 setValue(message);
135 }
136
137
138
139
140 @Override
141 public void setException(Throwable exception) {
142 if (exception == null) {
143 throw new IllegalArgumentException("exception");
144 }
145
146 setValue(exception);
147 }
148
149
150
151
152 @Override
153 public ReadFuture await() throws InterruptedException {
154 return (ReadFuture) super.await();
155 }
156
157
158
159
160 @Override
161 public ReadFuture awaitUninterruptibly() {
162 return (ReadFuture) super.awaitUninterruptibly();
163 }
164
165
166
167
168 @Override
169 public ReadFuture addListener(IoFutureListener<?> listener) {
170 return (ReadFuture) super.addListener(listener);
171 }
172
173
174
175
176 @Override
177 public ReadFuture removeListener(IoFutureListener<?> listener) {
178 return (ReadFuture) super.removeListener(listener);
179 }
180 }