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 package org.apache.http.nio.client; 28 29 import java.util.concurrent.Future; 30 31 import org.apache.http.HttpHost; 32 import org.apache.http.HttpRequest; 33 import org.apache.http.HttpResponse; 34 import org.apache.http.client.methods.HttpUriRequest; 35 import org.apache.http.concurrent.FutureCallback; 36 import org.apache.http.nio.protocol.HttpAsyncRequestProducer; 37 import org.apache.http.nio.protocol.HttpAsyncResponseConsumer; 38 import org.apache.http.protocol.HttpContext; 39 40 /** 41 * This interface represents only the most basic contract for HTTP request 42 * execution. It imposes no restrictions or particular details on the request 43 * execution process and leaves the specifics of state management, 44 * authentication and redirect handling up to individual implementations. 45 * 46 * @since 4.0 47 */ 48 public interface HttpAsyncClient { 49 50 /** 51 * Initiates asynchronous HTTP request execution using the given context. 52 * <p> 53 * The request producer passed to this method will be used to generate 54 * a request message and stream out its content without buffering it 55 * in memory. The response consumer passed to this method will be used 56 * to process a response message without buffering its content in memory. 57 * <p> 58 * Please note it may be unsafe to interact with the context instance 59 * while the request is still being executed. 60 * 61 * @param <T> the result type of request execution. 62 * @param requestProducer request producer callback. 63 * @param responseConsumer response consumer callaback. 64 * @param context HTTP context 65 * @param callback future callback. 66 * @return future representing pending completion of the operation. 67 */ 68 <T> Future<T> execute( 69 HttpAsyncRequestProducer requestProducer, 70 HttpAsyncResponseConsumer<T> responseConsumer, 71 HttpContext context, 72 FutureCallback<T> callback); 73 74 /** 75 * Initiates asynchronous HTTP request execution using the default 76 * context. 77 * <p> 78 * The request producer passed to this method will be used to generate 79 * a request message and stream out its content without buffering it 80 * in memory. The response consumer passed to this method will be used 81 * to process a response message without buffering its content in memory. 82 * 83 * @param <T> the result type of request execution. 84 * @param requestProducer request producer callback. 85 * @param responseConsumer response consumer callaback. 86 * @param callback future callback. 87 * @return future representing pending completion of the operation. 88 */ 89 <T> Future<T> execute( 90 HttpAsyncRequestProducer requestProducer, 91 HttpAsyncResponseConsumer<T> responseConsumer, 92 FutureCallback<T> callback); 93 94 /** 95 * Initiates asynchronous HTTP request execution against the given target 96 * using the given context. 97 * <p> 98 * Please note it may be unsafe to interact with the context instance 99 * while the request is still being executed. 100 * 101 * @param target the target host for the request. 102 * Implementations may accept {@code null} 103 * if they can still determine a route, for example 104 * to a default target or by inspecting the request. 105 * @param request the request to execute 106 * @param context the context to use for the execution, or 107 * {@code null} to use the default context 108 * @param callback future callback. 109 * @return future representing pending completion of the operation. 110 */ 111 Future<HttpResponse> execute( 112 HttpHost target, HttpRequest request, HttpContext context, 113 FutureCallback<HttpResponse> callback); 114 115 /** 116 * Initiates asynchronous HTTP request execution against the given target. 117 * 118 * @param target the target host for the request. 119 * Implementations may accept {@code null} 120 * if they can still determine a route, for example 121 * to a default target or by inspecting the request. 122 * @param request the request to execute 123 * @param callback future callback. 124 * @return future representing pending completion of the operation. 125 */ 126 Future<HttpResponse> execute( 127 HttpHost target, HttpRequest request, 128 FutureCallback<HttpResponse> callback); 129 130 /** 131 * Initiates asynchronous HTTP request execution using the given 132 * context. 133 * <p> 134 * Please note it may be unsafe to interact with the context instance 135 * while the request is still being executed. 136 * 137 * @param request the request to execute 138 * @param context HTTP context 139 * @param callback future callback. 140 * @return future representing pending completion of the operation. 141 */ 142 Future<HttpResponse> execute( 143 HttpUriRequest request, HttpContext context, 144 FutureCallback<HttpResponse> callback); 145 146 /** 147 * Initiates asynchronous HTTP request execution. 148 * 149 * @param request the request to execute 150 * @param callback future callback. 151 * @return future representing pending completion of the operation. 152 */ 153 Future<HttpResponse> execute( 154 HttpUriRequest request, 155 FutureCallback<HttpResponse> callback); 156 157 }