1 20 package org.apache.mina.common; 21 22 import java.net.SocketAddress ; 23 24 import org.apache.mina.filter.ReferenceCountingIoFilter; 25 26 78 public interface IoFilter { 79 85 void init() throws Exception ; 86 87 93 void destroy() throws Exception ; 94 95 106 void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) 107 throws Exception ; 108 109 120 void onPostAdd(IoFilterChain parent, String name, NextFilter nextFilter) 121 throws Exception ; 122 123 134 void onPreRemove(IoFilterChain parent, String name, NextFilter nextFilter) 135 throws Exception ; 136 137 148 void onPostRemove(IoFilterChain parent, String name, NextFilter nextFilter) 149 throws Exception ; 150 151 154 void sessionCreated(NextFilter nextFilter, IoSession session) 155 throws Exception ; 156 157 160 void sessionOpened(NextFilter nextFilter, IoSession session) 161 throws Exception ; 162 163 166 void sessionClosed(NextFilter nextFilter, IoSession session) 167 throws Exception ; 168 169 173 void sessionIdle(NextFilter nextFilter, IoSession session, IdleStatus status) 174 throws Exception ; 175 176 180 void exceptionCaught(NextFilter nextFilter, IoSession session, 181 Throwable cause) throws Exception ; 182 183 187 void messageReceived(NextFilter nextFilter, IoSession session, 188 Object message) throws Exception ; 189 190 194 void messageSent(NextFilter nextFilter, IoSession session, Object message) 195 throws Exception ; 196 197 200 void filterClose(NextFilter nextFilter, IoSession session) throws Exception ; 201 202 205 void filterWrite(NextFilter nextFilter, IoSession session, 206 WriteRequest writeRequest) throws Exception ; 207 208 211 public interface NextFilter { 212 215 void sessionCreated(IoSession session); 216 217 220 void sessionOpened(IoSession session); 221 222 225 void sessionClosed(IoSession session); 226 227 230 void sessionIdle(IoSession session, IdleStatus status); 231 232 235 void exceptionCaught(IoSession session, Throwable cause); 236 237 240 void messageReceived(IoSession session, Object message); 241 242 245 void messageSent(IoSession session, Object message); 246 247 250 void filterWrite(IoSession session, WriteRequest writeRequest); 251 252 255 void filterClose(IoSession session); 256 } 257 258 261 public static class WriteRequest { 262 private static final WriteFuture UNUSED_FUTURE = new WriteFuture() { 263 public boolean isWritten() { 264 return false; 265 } 266 267 public void setWritten(boolean written) { 268 } 269 270 public IoSession getSession() { 271 return null; 272 } 273 274 public void join() { 275 } 276 277 public boolean join(long timeoutInMillis) { 278 return true; 279 } 280 281 public boolean isReady() { 282 return true; 283 } 284 285 public void addListener(IoFutureListener listener) { 286 throw new IllegalStateException ( 287 "You can't add a listener to a dummy future."); 288 } 289 290 public void removeListener(IoFutureListener listener) { 291 throw new IllegalStateException ( 292 "You can't add a listener to a dummy future."); 293 } 294 }; 295 296 private final Object message; 297 298 private final WriteFuture future; 299 300 private final SocketAddress destination; 301 302 307 public WriteRequest(Object message) { 308 this(message, null, null); 309 } 310 311 314 public WriteRequest(Object message, WriteFuture future) { 315 this(message, future, null); 316 } 317 318 326 public WriteRequest(Object message, WriteFuture future, 327 SocketAddress destination) { 328 if (message == null) { 329 throw new NullPointerException ("message"); 330 } 331 332 if (future == null) { 333 future = UNUSED_FUTURE; 334 } 335 336 this.message = message; 337 this.future = future; 338 this.destination = destination; 339 } 340 341 344 public WriteFuture getFuture() { 345 return future; 346 } 347 348 351 public Object getMessage() { 352 return message; 353 } 354 355 360 public SocketAddress getDestination() { 361 return destination; 362 } 363 364 public String toString() { 365 return message.toString(); 366 } 367 } 368 } 369 | Popular Tags |