/
StreamingHttpClient.java
89 lines (79 loc) · 3.87 KB
/
StreamingHttpClient.java
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright © 2018 Apple Inc. and the ServiceTalk project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.servicetalk.http.api;
import io.servicetalk.concurrent.GracefulAutoCloseable;
import io.servicetalk.concurrent.api.Single;
import static io.servicetalk.concurrent.internal.FutureUtils.awaitTermination;
/**
* The equivalent of {@link HttpClient} but that accepts {@link StreamingHttpRequest} and returns
* {@link StreamingHttpResponse}.
*/
public interface StreamingHttpClient extends FilterableStreamingHttpClient, GracefulAutoCloseable {
/**
* Send a {@code request}.
*
* @param request the request to send.
* @return The response.
*/
@Override // FIXME: 0.42 - remove, this method is defined in StreamingHttpRequester
Single<StreamingHttpResponse> request(StreamingHttpRequest request);
/**
* Reserve a {@link StreamingHttpConnection} based on provided {@link HttpRequestMetaData}.
*
* @param metaData Allows the underlying layers to know what {@link StreamingHttpConnection}s are valid to
* reserve for future {@link StreamingHttpRequest requests} with the same {@link HttpRequestMetaData}.
* For example this may provide some insight into shard or other info.
* @return a {@link Single} that provides the {@link ReservedStreamingHttpConnection} upon completion.
*/
@Override // FIXME: 0.42 - remove, this method is defined in FilterableStreamingHttpClient
Single<ReservedStreamingHttpConnection> reserveConnection(HttpRequestMetaData metaData);
@Deprecated
@Override
Single<ReservedStreamingHttpConnection> reserveConnection(HttpExecutionStrategy strategy,
HttpRequestMetaData metaData);
/**
* Convert this {@link StreamingHttpClient} to the {@link HttpClient} API.
* <p>
* This API is provided for convenience. It is recommended that
* filters are implemented using the {@link StreamingHttpClient} asynchronous API for maximum portability.
* @return a {@link HttpClient} representation of this {@link StreamingHttpRequester}.
*/
HttpClient asClient();
/**
* Convert this {@link StreamingHttpClient} to the {@link BlockingStreamingHttpClient} API.
* <p>
* This API is provided for convenience for a more familiar sequential programming model. It is recommended that
* filters are implemented using the {@link StreamingHttpClient} asynchronous API for maximum portability.
* @return a {@link BlockingStreamingHttpClient} representation of this {@link StreamingHttpClient}.
*/
BlockingStreamingHttpClient asBlockingStreamingClient();
/**
* Convert this {@link StreamingHttpClient} to the {@link BlockingHttpClient} API.
* <p>
* This API is provided for convenience for a more familiar sequential programming model. It is recommended that
* filters are implemented using the {@link StreamingHttpClient} asynchronous API for maximum portability.
* @return a {@link BlockingHttpClient} representation of this {@link StreamingHttpClient}.
*/
BlockingHttpClient asBlockingClient();
@Override
default void close() throws Exception {
awaitTermination(closeAsync().toFuture());
}
@Override
default void closeGracefully() throws Exception {
awaitTermination(closeAsyncGracefully().toFuture());
}
}