Skip to content

Commit dfbcb62

Browse files
committed
Introduce HttpClient.Metrics and HttpClient.Builder.State
1 parent 2c8f1cb commit dfbcb62

File tree

3 files changed

+104
-62
lines changed

3 files changed

+104
-62
lines changed

client/src/main/java/io/avaje/http/client/DHttpClientContextBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import static java.util.Objects.requireNonNull;
2121

22-
final class DHttpClientContextBuilder implements HttpClientContext.Builder.State {
22+
final class DHttpClientContextBuilder implements HttpClientContext.Builder, HttpClientContext.Builder.State {
2323

2424
private HttpClient client;
2525
private String baseUrl;
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package io.avaje.http.client;
2+
3+
import java.time.Duration;
4+
5+
/**
6+
* The HTTP client context that we use to build and process requests.
7+
*
8+
* <pre>{@code
9+
*
10+
* HttpClient client = HttpClient.builder()
11+
* .baseUrl("http://localhost:8080")
12+
* .bodyAdapter(new JacksonBodyAdapter())
13+
* .build();
14+
*
15+
* HelloDto dto = client.request()
16+
* .path("hello")
17+
* .queryParam("name", "Rob")
18+
* .queryParam("say", "Whats up")
19+
* .GET()
20+
* .bean(HelloDto.class);
21+
*
22+
* }</pre>
23+
*/
24+
public interface HttpClient {
25+
26+
interface Builder {
27+
28+
/**
29+
* The state of the builder with methods to read the set state.
30+
*/
31+
interface State {
32+
33+
/**
34+
* Return the base URL.
35+
*/
36+
String baseUrl();
37+
38+
/**
39+
* Return the body adapter.
40+
*/
41+
BodyAdapter bodyAdapter();
42+
43+
/**
44+
* Return the HttpClient.
45+
*/
46+
java.net.http.HttpClient client();
47+
48+
/**
49+
* Return true if requestLogging is on.
50+
*/
51+
boolean requestLogging();
52+
53+
/**
54+
* Return the request timeout.
55+
*/
56+
Duration requestTimeout();
57+
58+
/**
59+
* Return the retry handler.
60+
*/
61+
RetryHandler retryHandler();
62+
}
63+
}
64+
65+
/**
66+
* Statistic metrics collected to provide an overview of activity of this client.
67+
*/
68+
interface Metrics {
69+
70+
/**
71+
* Return the total number of responses.
72+
*/
73+
long totalCount();
74+
75+
/**
76+
* Return the total number of error responses (status code >= 300).
77+
*/
78+
long errorCount();
79+
80+
/**
81+
* Return the total response bytes (excludes streaming responses).
82+
*/
83+
long responseBytes();
84+
85+
/**
86+
* Return the total response time in microseconds.
87+
*/
88+
long totalMicros();
89+
90+
/**
91+
* Return the max response time in microseconds (since the last reset).
92+
*/
93+
long maxMicros();
94+
95+
/**
96+
* Return the average response time in microseconds.
97+
*/
98+
long avgMicros();
99+
}
100+
}

client/src/main/java/io/avaje/http/client/HttpClientContext.java

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -346,73 +346,15 @@ interface Builder {
346346
/**
347347
* The state of the builder with methods to read the set state.
348348
*/
349-
interface State extends Builder {
350-
351-
/**
352-
* Return the base URL.
353-
*/
354-
String baseUrl();
355-
356-
/**
357-
* Return the body adapter.
358-
*/
359-
BodyAdapter bodyAdapter();
360-
361-
/**
362-
* Return the HttpClient.
363-
*/
364-
HttpClient client();
365-
366-
/**
367-
* Return true if requestLogging is on.
368-
*/
369-
boolean requestLogging();
370-
371-
/**
372-
* Return the request timeout.
373-
*/
374-
Duration requestTimeout();
375-
376-
/**
377-
* Return the retry handler.
378-
*/
379-
RetryHandler retryHandler();
349+
interface State extends io.avaje.http.client.HttpClient.Builder.State {
350+
380351
}
381352
}
382353

383354
/**
384355
* Statistic metrics collected to provide an overview of activity of this client.
385356
*/
386-
interface Metrics {
387-
388-
/**
389-
* Return the total number of responses.
390-
*/
391-
long totalCount();
392-
393-
/**
394-
* Return the total number of error responses (status code >= 300).
395-
*/
396-
long errorCount();
397-
398-
/**
399-
* Return the total response bytes (excludes streaming responses).
400-
*/
401-
long responseBytes();
357+
interface Metrics extends io.avaje.http.client.HttpClient.Metrics {
402358

403-
/**
404-
* Return the total response time in microseconds.
405-
*/
406-
long totalMicros();
407-
408-
/**
409-
* Return the max response time in microseconds (since the last reset).
410-
*/
411-
long maxMicros();
412-
413-
/**
414-
* Return the average response time in microseconds.
415-
*/
416-
long avgMicros();
417359
}
418360
}

0 commit comments

Comments
 (0)