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.List;
24 import java.util.Set;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 public class DummySession extends AbstractIoSession {
40
41 private static final TransportMetadata TRANSPORT_METADATA =
42 new DefaultTransportMetadata(
43 "mina", "dummy", false, false,
44 SocketAddress.class, IoSessionConfig.class, Object.class);
45
46 private static final SocketAddress ANONYMOUS_ADDRESS = new SocketAddress() {
47 private static final long serialVersionUID = -496112902353454179L;
48
49 @Override
50 public String toString() {
51 return "?";
52 }
53 };
54
55 private volatile IoService service;
56
57 private volatile IoSessionConfig config = new AbstractIoSessionConfig() {
58 @Override
59 protected void doSetAll(IoSessionConfig config) {
60 }
61 };
62
63 private final IoFilterChain filterChain = new DefaultIoFilterChain(this);
64 private final IoProcessor<IoSession> processor;
65
66 private volatile IoHandler handler = new IoHandlerAdapter();
67 private volatile SocketAddress localAddress = ANONYMOUS_ADDRESS;
68 private volatile SocketAddress remoteAddress = ANONYMOUS_ADDRESS;
69 private volatile TransportMetadata transportMetadata = TRANSPORT_METADATA;
70
71
72
73
74 public DummySession() {
75
76 IoAcceptor acceptor = new AbstractIoAcceptor(
77 new AbstractIoSessionConfig() {
78 @Override
79 protected void doSetAll(IoSessionConfig config) {}
80 }) {
81
82 @Override
83 protected Set<SocketAddress> bind0(List<? extends SocketAddress> localAddresses) throws Exception {
84 throw new UnsupportedOperationException();
85 }
86
87 @Override
88 protected void unbind0(List<? extends SocketAddress> localAddresses) throws Exception {
89 throw new UnsupportedOperationException();
90 }
91
92 public IoSession newSession(SocketAddress remoteAddress, SocketAddress localAddress) {
93 throw new UnsupportedOperationException();
94 }
95
96 public TransportMetadata getTransportMetadata() {
97 return TRANSPORT_METADATA;
98 }
99
100 @Override
101 protected IoFuture dispose0() throws Exception {
102 return null;
103 }
104 };
105
106
107 acceptor.setHandler(new IoHandlerAdapter());
108
109 this.service = acceptor;
110
111 this.processor = new IoProcessor<IoSession>() {
112 public void add(IoSession session) {
113 }
114
115 public void flush(IoSession session) {
116 getFilterChain().fireMessageSent(
117 ((DummySession) session).getWriteRequestQueue().poll(session));
118 }
119
120 public void remove(IoSession session) {
121 }
122
123 public void updateTrafficMask(IoSession session) {
124 }
125
126 public void dispose() {
127 }
128
129 public boolean isDisposed() {
130 return false;
131 }
132
133 public boolean isDisposing() {
134 return false;
135 }
136 };
137
138 try {
139 IoSessionDataStructureFactory factory = new DefaultIoSessionDataStructureFactory();
140 setAttributeMap(factory.getAttributeMap(this));
141 setWriteRequestQueue(factory.getWriteRequestQueue(this));
142 } catch (Exception e) {
143 throw new InternalError();
144 }
145 }
146
147 public IoSessionConfig getConfig() {
148 return config;
149 }
150
151
152
153
154 public void setConfig(IoSessionConfig config) {
155 if (config == null) {
156 throw new NullPointerException("config");
157 }
158
159 this.config = config;
160 }
161
162 public IoFilterChain getFilterChain() {
163 return filterChain;
164 }
165
166 public IoHandler getHandler() {
167 return handler;
168 }
169
170
171
172
173 public void setHandler(IoHandler handler) {
174 if (handler == null) {
175 throw new NullPointerException("handler");
176 }
177
178 this.handler = handler;
179 }
180
181 public SocketAddress getLocalAddress() {
182 return localAddress;
183 }
184
185 public SocketAddress getRemoteAddress() {
186 return remoteAddress;
187 }
188
189
190
191
192
193 public void setLocalAddress(SocketAddress localAddress) {
194 if (localAddress == null) {
195 throw new NullPointerException("localAddress");
196 }
197
198 this.localAddress = localAddress;
199 }
200
201
202
203
204 public void setRemoteAddress(SocketAddress remoteAddress) {
205 if (remoteAddress == null) {
206 throw new NullPointerException("remoteAddress");
207 }
208
209 this.remoteAddress = remoteAddress;
210 }
211
212 public IoService getService() {
213 return service;
214 }
215
216
217
218
219 public void setService(IoService service) {
220 if (service == null) {
221 throw new NullPointerException("service");
222 }
223
224 this.service = service;
225 }
226
227 @Override
228 protected final IoProcessor<IoSession> getProcessor() {
229 return processor;
230 }
231
232 public TransportMetadata getTransportMetadata() {
233 return transportMetadata;
234 }
235
236
237
238
239 public void setTransportMetadata(TransportMetadata transportMetadata) {
240 if (transportMetadata == null) {
241 throw new NullPointerException("transportMetadata");
242 }
243
244 this.transportMetadata = transportMetadata;
245 }
246
247 @Override
248 public void setScheduledWriteBytes(long byteCount){
249 super.setScheduledWriteBytes(byteCount);
250 }
251
252 @Override
253 public void setScheduledWriteMessages(int messages) {
254 super.setScheduledWriteMessages(messages);
255 }
256
257
258
259
260
261
262
263
264
265 public void updateThroughput(boolean force) {
266 super.updateThroughput(System.currentTimeMillis(), force);
267 }
268 }