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.protocol; 29 30 import org.apache.http.HttpRequest; 31 import org.apache.http.HttpResponse; 32 import org.apache.http.concurrent.Cancellable; 33 34 /** 35 * {@code HttpAsyncExchange} represents a server-side HTTP message exchange 36 * where an HTTP response can be deferred without blocking the I/O event thread 37 * and triggered asynchronously at a later point of later time. 38 * 39 * @since 4.2 40 */ 41 public interface HttpAsyncExchange { 42 43 /** 44 * Returns the received HTTP request message. 45 * 46 * @return received HTTP request message. 47 */ 48 HttpRequest getRequest(); 49 50 /** 51 * Returns the default HTTP response message. Once ready the response 52 * message can submitted using {@link #submitResponse()} method. 53 * 54 * @return default HTTP response message. 55 */ 56 HttpResponse getResponse(); 57 58 /** 59 * Submits the default HTTP response and completed the message exchange. 60 * If the response encloses an {@link org.apache.http.HttpEntity} instance 61 * the entity is also expected to implement the 62 * {@link org.apache.http.nio.entity.HttpAsyncContentProducer } 63 * interface for efficient content streaming to a non-blocking HTTP 64 * connection. 65 * 66 * @throws IllegalStateException if a response has already been submitted. 67 */ 68 void submitResponse(); 69 70 /** 71 * Submits an HTTP response using a custom 72 * {@link HttpAsyncResponseProducer}. 73 * 74 * @throws IllegalStateException if a response has already been submitted. 75 */ 76 void submitResponse(HttpAsyncResponseProducer responseProducer); 77 78 /** 79 * Determines whether or not the message exchange has been completed. 80 * 81 * @return {@code true} if the message exchange has been completed, 82 * {@code false} otherwise. 83 */ 84 boolean isCompleted(); 85 86 /** 87 * Sets {@link Cancellable} callback to be invoked in case the underlying 88 * connection times out or gets terminated prematurely by the client. This 89 * callback can be used to cancel a long running response generating 90 * process if a response is no longer needed. 91 */ 92 void setCallback(Cancellable cancellable); 93 94 /** 95 * Sets timeout for this message exchange. 96 */ 97 void setTimeout(int timeout); 98 99 /** 100 * Returns timeout for this message exchange. 101 */ 102 int getTimeout(); 103 104 }