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