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 org.apache.mina.core.RuntimeIoException;
23 import org.apache.mina.core.session.IoSession;
24
25
26
27
28
29
30 public class DefaultConnectFuture extends DefaultIoFuture implements ConnectFuture {
31
32 private static final Object CANCELED = new Object();
33
34
35
36
37 public DefaultConnectFuture() {
38 super(null);
39 }
40
41
42
43
44
45
46
47 public static ConnectFuture newFailedFuture(Throwable exception) {
48 DefaultConnectFutureure.html#DefaultConnectFuture">DefaultConnectFuture failedFuture = new DefaultConnectFuture();
49 failedFuture.setException(exception);
50
51 return failedFuture;
52 }
53
54
55
56
57 @Override
58 public IoSession getSession() {
59 Object v = getValue();
60
61 if (v instanceof IoSession) {
62 return (IoSession) v;
63 } else if (v instanceof RuntimeException) {
64 throw (RuntimeException) v;
65 } else if (v instanceof Error) {
66 throw (Error) v;
67 } else if (v instanceof Throwable) {
68 throw (RuntimeIoExceptionoException.html#RuntimeIoException">RuntimeIoException) new RuntimeIoException("Failed to get the session.").initCause((Throwable) v);
69 } else {
70 return null;
71 }
72 }
73
74
75
76
77 @Override
78 public Throwable getException() {
79 Object v = getValue();
80
81 if (v instanceof Throwable) {
82 return (Throwable) v;
83 } else {
84 return null;
85 }
86 }
87
88
89
90
91 @Override
92 public boolean isConnected() {
93 return getValue() instanceof IoSession;
94 }
95
96
97
98
99 @Override
100 public boolean isCanceled() {
101 return getValue() == CANCELED;
102 }
103
104
105
106
107 @Override
108 public void setSession(IoSession session) {
109 if (session == null) {
110 throw new IllegalArgumentException("session");
111 }
112
113 setValue(session);
114 }
115
116
117
118
119 @Override
120 public void setException(Throwable exception) {
121 if (exception == null) {
122 throw new IllegalArgumentException("exception");
123 }
124
125 setValue(exception);
126 }
127
128
129
130
131 @Override
132 public boolean cancel() {
133 return setValue(CANCELED);
134 }
135
136
137
138
139 @Override
140 public ConnectFuture await() throws InterruptedException {
141 return (ConnectFuture) super.await();
142 }
143
144
145
146
147 @Override
148 public ConnectFuture awaitUninterruptibly() {
149 return (ConnectFuture) super.awaitUninterruptibly();
150 }
151
152
153
154
155 @Override
156 public ConnectFuture addListener(IoFutureListener<?> listener) {
157 return (ConnectFuture) super.addListener(listener);
158 }
159
160
161
162
163 @Override
164 public ConnectFuture removeListener(IoFutureListener<?> listener) {
165 return (ConnectFuture) super.removeListener(listener);
166 }
167 }