Skip to content

Commit 71242d2

Browse files
committed
Return a ListenableFuture. That shouldn't break any compatibility
1 parent 7d7d9c0 commit 71242d2

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed

src/main/java/com/ning/http/client/AsyncHttpClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ private BoundRequestBuilder(Request prototype) {
223223
super(BoundRequestBuilder.class, prototype);
224224
}
225225

226-
public <T> Future<T> execute(AsyncHandler<T> handler) throws IOException {
226+
public <T> ListenableFuture<T> execute(AsyncHandler<T> handler) throws IOException {
227227
return AsyncHttpClient.this.executeRequest(build(), handler);
228228
}
229229

230-
public Future<Response> execute() throws IOException {
230+
public ListenableFuture<Response> execute() throws IOException {
231231
return AsyncHttpClient.this.executeRequest(build(), new AsyncCompletionHandlerBase());
232232
}
233233

@@ -468,7 +468,7 @@ public BoundRequestBuilder prepareRequest(Request request) {
468468
* @return a {@link Future} of type T
469469
* @throws IOException
470470
*/
471-
public <T> Future<T> executeRequest(Request request, AsyncHandler<T> handler) throws IOException {
471+
public <T> ListenableFuture<T> executeRequest(Request request, AsyncHandler<T> handler) throws IOException {
472472

473473
FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(handler).request(request).build();
474474
fc = preProcessRequest(fc);
@@ -482,7 +482,7 @@ public <T> Future<T> executeRequest(Request request, AsyncHandler<T> handler) th
482482
* @return a {@link Future} of type Response
483483
* @throws IOException
484484
*/
485-
public Future<Response> executeRequest(Request request) throws IOException {
485+
public ListenableFuture<Response> executeRequest(Request request) throws IOException {
486486
FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(new AsyncCompletionHandlerBase()).request(request).build();
487487
fc = preProcessRequest(fc);
488488
return httpProvider.execute(fc.getRequest(), fc.getAsyncHandler());

src/main/java/com/ning/http/client/AsyncHttpProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public interface AsyncHttpProvider<A> {
2929
* Execute the request and invoke the {@link AsyncHandler} when the response arrive.
3030
*
3131
* @param handler an instance of {@link AsyncHandler}
32-
* @return a {@link java.util.concurrent.Future} of Type T.
32+
* @return a {@link ListenableFuture} of Type T.
3333
* @throws IOException
3434
*/
35-
public <T> Future<T> execute(Request request, AsyncHandler<T> handler) throws IOException;
35+
public <T> ListenableFuture<T> execute(Request request, AsyncHandler<T> handler) throws IOException;
3636

3737
/**
3838
* Close the current underlying TCP/HTTP connection.

src/main/java/com/ning/http/client/providers/apache/ApacheAsyncHttpProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.ning.http.client.HttpResponseBodyPart;
2424
import com.ning.http.client.HttpResponseHeaders;
2525
import com.ning.http.client.HttpResponseStatus;
26+
import com.ning.http.client.ListenableFuture;
2627
import com.ning.http.client.MaxRedirectException;
2728
import com.ning.http.client.Part;
2829
import com.ning.http.client.PerRequestConfig;
@@ -160,7 +161,7 @@ public ApacheAsyncHttpProvider(AsyncHttpClientConfig config) {
160161
private void configure(ApacheAsyncHttpProviderConfig config) {
161162
}
162163

163-
public <T> Future<T> execute(Request request, AsyncHandler<T> handler) throws IOException {
164+
public <T> ListenableFuture<T> execute(Request request, AsyncHandler<T> handler) throws IOException {
164165
if (isClose.get()) {
165166
throw new IOException("Closed");
166167
}

src/main/java/com/ning/http/client/providers/jdk/JDKAsyncHttpProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ private void configure(JDKAsyncHttpProviderConfig config) {
112112
System.setProperty(e.getKey(), e.getValue());
113113
}
114114
}
115-
public <T> Future<T> execute(Request request, AsyncHandler<T> handler) throws IOException {
115+
public <T> ListenableFuture<T> execute(Request request, AsyncHandler<T> handler) throws IOException {
116116
return execute(request, handler, null);
117117
}
118-
public <T> Future<T> execute(Request request, AsyncHandler<T> handler, ListenableFuture<?> future) throws IOException {
118+
public <T> ListenableFuture<T> execute(Request request, AsyncHandler<T> handler, ListenableFuture<?> future) throws IOException {
119119
if (isClose.get()) {
120120
throw new IOException("Closed");
121121
}

src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.ning.http.client.HttpResponseBodyPart;
2727
import com.ning.http.client.HttpResponseHeaders;
2828
import com.ning.http.client.HttpResponseStatus;
29+
import com.ning.http.client.ListenableFuture;
2930
import com.ning.http.client.MaxRedirectException;
3031
import com.ning.http.client.PerRequestConfig;
3132
import com.ning.http.client.ProgressAsyncHandler;
@@ -704,15 +705,15 @@ public Response prepareResponse(final HttpResponseStatus status,
704705

705706
/* @Override */
706707

707-
public <T> Future<T> execute(Request request, final AsyncHandler<T> asyncHandler) throws IOException {
708+
public <T> ListenableFuture<T> execute(Request request, final AsyncHandler<T> asyncHandler) throws IOException {
708709
return doConnect(request, asyncHandler, null, true);
709710
}
710711

711712
private <T> void execute(final Request request, final NettyResponseFuture<T> f, boolean useCache) throws IOException {
712713
doConnect(request, f.getAsyncHandler(), f, useCache);
713714
}
714715

715-
private <T> Future<T> doConnect(final Request request, final AsyncHandler<T> asyncHandler, NettyResponseFuture<T> f, boolean useCache) throws IOException {
716+
private <T> ListenableFuture<T> doConnect(final Request request, final AsyncHandler<T> asyncHandler, NettyResponseFuture<T> f, boolean useCache) throws IOException {
716717

717718
if (isClose.get()) {
718719
throw new IOException("Closed");

src/test/java/com/ning/http/client/async/ListenableFutureTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public void testListenableFuture() throws Throwable {
3333
final AtomicInteger statusCode = new AtomicInteger(500);
3434
AsyncHttpClient ahc = getAsyncHttpClient(null);
3535
final CountDownLatch latch = new CountDownLatch(1);
36-
final Future<Response> future = ahc.prepareGet(getTargetUrl()).execute();
37-
((ListenableFuture)future).addListener(new Runnable(){
36+
final ListenableFuture<Response> future = ahc.prepareGet(getTargetUrl()).execute();
37+
future.addListener(new Runnable(){
3838

3939
public void run() {
4040
try {

0 commit comments

Comments
 (0)