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 <a href="http://mina.apache.org">Apache MINA Project</a>
31   * 
32   * @param <T> the type of the {@link IoSession} this processor can handle
33   */
34  public interface IoProcessor<T extends IoSession> {
35  
36      /**
37       * Returns <tt>true</tt> if and if only {@link #dispose()} method has
38       * been called.  Please note that this method will return <tt>true</tt>
39       * even after all the related resources are released.
40       */
41      boolean isDisposing();
42      
43      /**
44       * Returns <tt>true</tt> if and if only all resources of this processor
45       * have been disposed.
46       */
47      boolean isDisposed();
48      
49      /**
50       * Releases any resources allocated by this processor.  Please note that 
51       * the resources might not be released as long as there are any sessions
52       * managed by this processor.  Most implementations will close all sessions
53       * immediately and release the related resources.
54       */
55      void dispose();
56      
57      /**
58       * Adds the specified {@code session} to the I/O processor so that
59       * the I/O processor starts to perform any I/O operations related
60       * with the {@code session}.
61       */
62      void add(T session);
63  
64      /**
65       * Flushes the internal write request queue of the specified
66       * {@code session}.
67       */
68      void flush(T session);
69  
70      /**
71       * Controls the traffic of the specified {@code session} depending of the
72       * {@link IoSession#isReadSuspended()} and {@link IoSession#isWriteSuspended()}
73       * flags
74       */
75      void updateTrafficControl(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  }