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.hc.core5.reactor;
29  
30  import org.apache.hc.core5.io.GracefullyCloseable;
31  import org.apache.hc.core5.util.TimeValue;
32  
33  /**
34   * HttpCore NIO is based on the Reactor pattern as described by Doug Lea.
35   * The purpose of I/O reactors is to react to I/O events and to dispatch event
36   * notifications to individual I/O sessions. The main idea of I/O reactor
37   * pattern is to break away from the one thread per connection model imposed
38   * by the classic blocking I/O model.
39   * <p>
40   * The IOReactor interface represents an abstract object implementing
41   * the Reactor pattern.
42   * <p>
43   * I/O reactors usually employ a small number of dispatch threads (often as
44   * few as one) to dispatch I/O event notifications to a much greater number
45   * (often as many as several thousands) of I/O sessions or connections. It is
46   * generally recommended to have one dispatch thread per CPU core.
47   *
48   * @since 4.0
49   */
50  public interface IOReactor extends GracefullyCloseable {
51  
52      /**
53       * Returns the current status of the reactor.
54       *
55       * @return reactor status.
56       */
57      IOReactorStatus getStatus();
58  
59      /**
60       * Initiates shutdown of the reactor without blocking. The reactor is expected
61       * to terminate all active connections, to shut down itself and to release
62       * system resources it currently holds
63       *
64       * @since 5.0
65       */
66      void initiateShutdown();
67  
68      /**
69       * Blocks for the given period of time in milliseconds awaiting
70       * the completion of the reactor shutdown.
71       *
72       * @param waitTime wait time.
73       *
74       * @since 5.0
75       */
76      void awaitShutdown(TimeValue waitTime) throws InterruptedException;
77  
78  }