1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.apache.hc.client5.http.impl.async;
28
29 import java.util.concurrent.Future;
30
31 import org.apache.hc.client5.http.async.HttpAsyncClient;
32 import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
33 import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
34 import org.apache.hc.client5.http.async.methods.SimpleRequestProducer;
35 import org.apache.hc.client5.http.async.methods.SimpleResponseConsumer;
36 import org.apache.hc.core5.annotation.Contract;
37 import org.apache.hc.core5.annotation.ThreadingBehavior;
38 import org.apache.hc.core5.concurrent.FutureCallback;
39 import org.apache.hc.core5.function.Supplier;
40 import org.apache.hc.core5.http.HttpHost;
41 import org.apache.hc.core5.http.nio.AsyncPushConsumer;
42 import org.apache.hc.core5.http.nio.AsyncRequestProducer;
43 import org.apache.hc.core5.http.nio.AsyncResponseConsumer;
44 import org.apache.hc.core5.http.nio.HandlerFactory;
45 import org.apache.hc.core5.http.protocol.HttpContext;
46 import org.apache.hc.core5.io.ModalCloseable;
47 import org.apache.hc.core5.reactor.IOReactorStatus;
48 import org.apache.hc.core5.util.Args;
49 import org.apache.hc.core5.util.TimeValue;
50
51
52
53
54
55
56 @Contract(threading = ThreadingBehavior.STATELESS)
57 public abstract class CloseableHttpAsyncClient implements HttpAsyncClient, ModalCloseable {
58
59 public abstract void start();
60
61 public abstract IOReactorStatus getStatus();
62
63 public abstract void awaitShutdown(TimeValue waitTime) throws InterruptedException;
64
65 public abstract void initiateShutdown();
66
67 protected abstract <T> Future<T> doExecute(
68 final HttpHost target,
69 final AsyncRequestProducer requestProducer,
70 final AsyncResponseConsumer<T> responseConsumer,
71 final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
72 final HttpContext context,
73 final FutureCallback<T> callback);
74
75 public final <T> Future<T> execute(
76 final HttpHost target,
77 final AsyncRequestProducer requestProducer,
78 final AsyncResponseConsumer<T> responseConsumer,
79 final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
80 final HttpContext context,
81 final FutureCallback<T> callback) {
82 Args.notNull(requestProducer, "Request producer");
83 Args.notNull(responseConsumer, "Response consumer");
84 return doExecute(target, requestProducer, responseConsumer, pushHandlerFactory, context, callback);
85 }
86
87 @Override
88 public final <T> Future<T> execute(
89 final AsyncRequestProducer requestProducer,
90 final AsyncResponseConsumer<T> responseConsumer,
91 final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
92 final HttpContext context,
93 final FutureCallback<T> callback) {
94 Args.notNull(requestProducer, "Request producer");
95 Args.notNull(responseConsumer, "Response consumer");
96 return doExecute(null, requestProducer, responseConsumer, pushHandlerFactory, context, callback);
97 }
98
99 public final <T> Future<T> execute(
100 final AsyncRequestProducer requestProducer,
101 final AsyncResponseConsumer<T> responseConsumer,
102 final HttpContext context,
103 final FutureCallback<T> callback) {
104 Args.notNull(requestProducer, "Request producer");
105 Args.notNull(responseConsumer, "Response consumer");
106 return execute(requestProducer, responseConsumer, null, context, callback);
107 }
108
109 public final <T> Future<T> execute(
110 final AsyncRequestProducer requestProducer,
111 final AsyncResponseConsumer<T> responseConsumer,
112 final FutureCallback<T> callback) {
113 Args.notNull(requestProducer, "Request producer");
114 Args.notNull(responseConsumer, "Response consumer");
115 return execute(requestProducer, responseConsumer, null, callback);
116 }
117
118 public final Future<SimpleHttpResponse> execute(
119 final SimpleHttpRequest request,
120 final HttpContext context,
121 final FutureCallback<SimpleHttpResponse> callback) {
122 Args.notNull(request, "Request");
123 return execute(SimpleRequestProducer.create(request), SimpleResponseConsumer.create(), context, callback);
124 }
125
126 public final Future<SimpleHttpResponse> execute(
127 final SimpleHttpRequest request,
128 final FutureCallback<SimpleHttpResponse> callback) {
129 return execute(request, null, callback);
130 }
131
132 public abstract void register(String hostname, String uriPattern, Supplier<AsyncPushConsumer> supplier);
133
134 public final void register(final String uriPattern, final Supplier<AsyncPushConsumer> supplier) {
135 register(null, uriPattern, supplier);
136 }
137
138 }