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.write;
21
22 import java.net.SocketAddress;
23 import java.util.concurrent.TimeUnit;
24
25 import org.apache.mina.core.future.IoFutureListener;
26 import org.apache.mina.core.future.WriteFuture;
27 import org.apache.mina.core.session.IoSession;
28
29
30
31
32
33
34 public class DefaultWriteRequest implements WriteRequest {
35 private static final WriteFuture UNUSED_FUTURE = new WriteFuture() {
36 public boolean isWritten() {
37 return false;
38 }
39
40 public void setWritten() {
41
42 }
43
44 public IoSession getSession() {
45 return null;
46 }
47
48 public void join() {
49
50 }
51
52 public boolean join(long timeoutInMillis) {
53 return true;
54 }
55
56 public boolean isDone() {
57 return true;
58 }
59
60 public WriteFuture addListener(IoFutureListener<?> listener) {
61 throw new IllegalStateException(
62 "You can't add a listener to a dummy future.");
63 }
64
65 public WriteFuture removeListener(IoFutureListener<?> listener) {
66 throw new IllegalStateException(
67 "You can't add a listener to a dummy future.");
68 }
69
70 public WriteFuture await() throws InterruptedException {
71 return this;
72 }
73
74 public boolean await(long timeout, TimeUnit unit)
75 throws InterruptedException {
76 return true;
77 }
78
79 public boolean await(long timeoutMillis) throws InterruptedException {
80 return true;
81 }
82
83 public WriteFuture awaitUninterruptibly() {
84 return this;
85 }
86
87 public boolean awaitUninterruptibly(long timeout, TimeUnit unit) {
88 return true;
89 }
90
91 public boolean awaitUninterruptibly(long timeoutMillis) {
92 return true;
93 }
94
95 public Throwable getException() {
96 return null;
97 }
98
99 public void setException(Throwable cause) {
100
101 }
102 };
103
104 private final Object message;
105 private final WriteFuture future;
106 private final SocketAddress destination;
107
108
109
110
111
112
113 public DefaultWriteRequest(Object message) {
114 this(message, null, null);
115 }
116
117
118
119
120 public DefaultWriteRequest(Object message, WriteFuture future) {
121 this(message, future, null);
122 }
123
124
125
126
127
128
129
130
131
132 public DefaultWriteRequest(Object message, WriteFuture future,
133 SocketAddress destination) {
134 if (message == null) {
135 throw new NullPointerException("message");
136 }
137
138 if (future == null) {
139 future = UNUSED_FUTURE;
140 }
141
142 this.message = message;
143 this.future = future;
144 this.destination = destination;
145 }
146
147 public WriteFuture getFuture() {
148 return future;
149 }
150
151 public Object getMessage() {
152 return message;
153 }
154
155 public WriteRequest getOriginalRequest() {
156 return this;
157 }
158
159 public SocketAddress getDestination() {
160 return destination;
161 }
162
163 @Override
164 public String toString() {
165 if (getDestination() == null) {
166 return message.toString();
167 }
168
169 return message.toString() + " => " + getDestination();
170 }
171 }