View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.nio.reactor;
29  
30  import java.io.IOException;
31  
32  /**
33   * HttpCore NIO is based on the Reactor pattern as described by Doug Lea.
34   * The purpose of I/O reactors is to react to I/O events and to dispatch event
35   * notifications to individual I/O sessions. The main idea of I/O reactor
36   * pattern is to break away from the one thread per connection model imposed
37   * by the classic blocking I/O model.
38   * <p>
39   * The IOReactor interface represents an abstract object implementing
40   * the Reactor pattern.
41   * <p>
42   * I/O reactors usually employ a small number of dispatch threads (often as
43   * few as one) to dispatch I/O event notifications to a much greater number
44   * (often as many as several thousands) of I/O sessions or connections. It is
45   * generally recommended to have one dispatch thread per CPU core.
46   *
47   * @since 4.0
48   */
49  public interface IOReactor {
50  
51      /**
52       * Returns the current status of the reactor.
53       *
54       * @return reactor status.
55       */
56      IOReactorStatus getStatus();
57  
58      /**
59       * Starts the reactor and initiates the dispatch of I/O event notifications
60       * to the given {@link IOEventDispatch}.
61       *
62       * @param eventDispatch the I/O event dispatch.
63       * @throws IOException in case of an I/O error.
64       */
65      void execute(IOEventDispatch eventDispatch)
66          throws IOException;
67  
68      /**
69       * Initiates shutdown of the reactor and blocks approximately for the given
70       * period of time in milliseconds waiting for the reactor to terminate all
71       * active connections, to shut down itself and to release system resources
72       * it currently holds.
73       *
74       * @param waitMs wait time in milliseconds.
75       * @throws IOException in case of an I/O error.
76       */
77      void shutdown(long waitMs)
78          throws IOException;
79  
80      /**
81       * Initiates shutdown of the reactor and blocks for a default period of
82       * time waiting for the reactor to terminate all active connections, to shut
83       * down itself and to release system resources it currently holds. It is
84       * up to individual implementations to decide for how long this method can
85       * remain blocked.
86       *
87       * @throws IOException in case of an I/O error.
88       */
89      void shutdown()
90          throws IOException;
91  
92  }