1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.common;
21
22
23
24
25
26
27
28
29 public class DefaultConnectFuture extends DefaultIoFuture implements
30 ConnectFuture {
31
32 private static final Object CANCELED = new Object();
33
34
35
36
37 public static ConnectFuture newFailedFuture(Throwable exception) {
38 DefaultConnectFuture failedFuture = new DefaultConnectFuture();
39 failedFuture.setException(exception);
40 return failedFuture;
41 }
42
43
44
45
46 public DefaultConnectFuture() {
47 super(null);
48 }
49
50 @Override
51 public IoSession getSession() {
52 Object v = getValue();
53 if (v instanceof RuntimeException) {
54 throw (RuntimeException) v;
55 } else if (v instanceof Error) {
56 throw (Error) v;
57 } else if (v instanceof Throwable) {
58 throw (RuntimeIoException) new RuntimeIoException(
59 "Failed to get the session.").initCause((Throwable) v);
60 } else if (v instanceof IoSession) {
61 return (IoSession) v;
62 } else {
63 return null;
64 }
65 }
66
67 public Throwable getException() {
68 Object v = getValue();
69 if (v instanceof Throwable) {
70 return (Throwable) v;
71 } else {
72 return null;
73 }
74 }
75
76 public boolean isConnected() {
77 return getValue() instanceof IoSession;
78 }
79
80 public boolean isCanceled() {
81 return getValue() == CANCELED;
82 }
83
84 public void setSession(IoSession session) {
85 if (session == null) {
86 throw new NullPointerException("session");
87 }
88 setValue(session);
89 }
90
91 public void setException(Throwable exception) {
92 if (exception == null) {
93 throw new NullPointerException("exception");
94 }
95 setValue(exception);
96 }
97
98 public void cancel() {
99 setValue(CANCELED);
100 }
101
102 @Override
103 public ConnectFuture await() throws InterruptedException {
104 return (ConnectFuture) super.await();
105 }
106
107 @Override
108 public ConnectFuture awaitUninterruptibly() {
109 return (ConnectFuture) super.awaitUninterruptibly();
110 }
111
112 @Override
113 public ConnectFuture addListener(IoFutureListener<?> listener) {
114 return (ConnectFuture) super.addListener(listener);
115 }
116
117 @Override
118 public ConnectFuture removeListener(IoFutureListener<?> listener) {
119 return (ConnectFuture) super.removeListener(listener);
120 }
121 }