View Javadoc

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  
24  /**
25   * An internal interface to represent an 'I/O processor' that performs
26   * actual I/O operations for {@link IoSession}s.  It abstracts existing
27   * reactor frameworks such as Java NIO once again to simplify transport
28   * implementations.
29   *
30   * @author The Apache MINA Project (dev@mina.apache.org)
31   * @version $Rev: 671827 $, $Date: 2008-06-26 10:49:48 +0200 (jeu, 26 jun 2008) $
32   * 
33   * @param <T> the type of the {@link IoSession} this processor can handle
34   */
35  public interface IoProcessor<T extends IoSession> {
36  
37      /**
38       * Returns <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       * Returns <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      void add(T session);
64  
65      /**
66       * Flushes the internal write request queue of the specified
67       * {@code session}.
68       */
69      void flush(T session);
70  
71      /**
72       * Controls the traffic of the specified {@code session} as specified
73       * in {@link IoSession#getTrafficMask()}.
74       */
75      void updateTrafficMask(T session);
76  
77      /**
78       * Removes and closes the specified {@code session} from the I/O
79       * processor so that the I/O processor closes the connection
80       * associated with the {@code session} and releases any other related
81       * resources.
82       */
83      void remove(T session);
84  }