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 public Object getMessage() {
49 if (isDone()) {
50 Object v = getValue();
51
52 if (v == CLOSED) {
53 return null;
54 }
55
56 if (v instanceof RuntimeException) {
57 throw (RuntimeException) v;
58 }
59
60 if (v instanceof Error) {
61 throw (Error) v;
62 }
63
64 if (v instanceof IOException || v instanceof Exception) {
65 throw new RuntimeIoException((Exception) v);
66 }
67
68 return v;
69 }
70
71 return null;
72 }
73
74
75
76
77 public boolean isRead() {
78 if (isDone()) {
79 Object v = getValue();
80
81 return (v != CLOSED && !(v instanceof Throwable));
82 }
83
84 return false;
85 }
86
87
88
89
90 public boolean isClosed() {
91 if (isDone()) {
92 return getValue() == CLOSED;
93 }
94
95 return false;
96 }
97
98
99
100
101 public Throwable getException() {
102 if (isDone()) {
103 Object v = getValue();
104
105 if (v instanceof Throwable) {
106 return (Throwable)v;
107 }
108 }
109
110 return null;
111 }
112
113
114
115
116 public void setClosed() {
117 setValue(CLOSED);
118 }
119
120
121
122
123 public void setRead(Object message) {
124 if (message == null) {
125 throw new IllegalArgumentException("message");
126 }
127
128 setValue(message);
129 }
130
131
132
133
134 public void setException(Throwable exception) {
135 if (exception == null) {
136 throw new IllegalArgumentException("exception");
137 }
138
139 setValue(exception);
140 }
141
142
143
144
145 @Override
146 public ReadFuture await() throws InterruptedException {
147 return (ReadFuture) super.await();
148 }
149
150
151
152
153 @Override
154 public ReadFuture awaitUninterruptibly() {
155 return (ReadFuture) super.awaitUninterruptibly();
156 }
157
158
159
160
161 @Override
162 public ReadFuture addListener(IoFutureListener<?> listener) {
163 return (ReadFuture) super.addListener(listener);
164 }
165
166
167
168
169 @Override
170 public ReadFuture removeListener(IoFutureListener<?> listener) {
171 return (ReadFuture) super.removeListener(listener);
172 }
173 }