1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.mina.core.service; 21 22 import org.apache.mina.core.session.IoSession; 23 import org.apache.mina.core.write.WriteRequest; 24 25 /** 26 * An internal interface to represent an 'I/O processor' that performs 27 * actual I/O operations for {@link IoSession}s. It abstracts existing 28 * reactor frameworks such as Java NIO once again to simplify transport 29 * implementations. 30 * 31 * @author <a href="http://mina.apache.org">Apache MINA Project</a> 32 * 33 * @param <S> the type of the {@link IoSession} this processor can handle 34 */ 35 public interface IoProcessor<S extends IoSession> { 36 37 /** 38 * @return <tt>true</tt> if and if only {@link #dispose()} method has 39 * been called. Please note that this method will return <tt>true</tt> 40 * even after all the related resources are released. 41 */ 42 boolean isDisposing(); 43 44 /** 45 * @return <tt>true</tt> if and if only all resources of this processor 46 * have been disposed. 47 */ 48 boolean isDisposed(); 49 50 /** 51 * Releases any resources allocated by this processor. Please note that 52 * the resources might not be released as long as there are any sessions 53 * managed by this processor. Most implementations will close all sessions 54 * immediately and release the related resources. 55 */ 56 void dispose(); 57 58 /** 59 * Adds the specified {@code session} to the I/O processor so that 60 * the I/O processor starts to perform any I/O operations related 61 * with the {@code session}. 62 * 63 * @param session The added session 64 */ 65 void add(S session); 66 67 /** 68 * Flushes the internal write request queue of the specified 69 * {@code session}. 70 * 71 * @param session The session we want the message to be written 72 */ 73 void flush(S session); 74 75 /** 76 * Writes the WriteRequest for the specified {@code session}. 77 * 78 * @param session The session we want the message to be written 79 * @param writeRequest the WriteRequest to write 80 */ 81 void write(S session, WriteRequest writeRequest); 82 83 /** 84 * Controls the traffic of the specified {@code session} depending of the 85 * {@link IoSession#isReadSuspended()} and {@link IoSession#isWriteSuspended()} 86 * flags 87 * 88 * @param session The session to be updated 89 */ 90 void updateTrafficControl(S session); 91 92 /** 93 * Removes and closes the specified {@code session} from the I/O 94 * processor so that the I/O processor closes the connection 95 * associated with the {@code session} and releases any other related 96 * resources. 97 * 98 * @param session The session to be removed 99 */ 100 void remove(S session); 101 }