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