2424import com .google .maps .internal .HttpHeaders ;
2525import com .google .maps .internal .StringJoin ;
2626import com .google .maps .internal .UrlSigner ;
27+ import com .google .maps .metrics .NoOpRequestMetricsReporter ;
28+ import com .google .maps .metrics .RequestMetrics ;
29+ import com .google .maps .metrics .RequestMetricsReporter ;
2730import java .io .UnsupportedEncodingException ;
2831import java .net .Proxy ;
2932import java .net .URLEncoder ;
@@ -64,6 +67,7 @@ public class GeoApiContext {
6467 private final Integer maxRetries ;
6568 private final UrlSigner urlSigner ;
6669 private String experienceIdHeaderValue ;
70+ private final RequestMetricsReporter requestMetricsReporter ;
6771
6872 /* package */
6973 GeoApiContext (
@@ -76,6 +80,7 @@ public class GeoApiContext {
7680 ExceptionsAllowedToRetry exceptionsAllowedToRetry ,
7781 Integer maxRetries ,
7882 UrlSigner urlSigner ,
83+ RequestMetricsReporter requestMetricsReporter ,
7984 String ... experienceIdHeaderValue ) {
8085 this .requestHandler = requestHandler ;
8186 this .apiKey = apiKey ;
@@ -86,6 +91,7 @@ public class GeoApiContext {
8691 this .exceptionsAllowedToRetry = exceptionsAllowedToRetry ;
8792 this .maxRetries = maxRetries ;
8893 this .urlSigner = urlSigner ;
94+ this .requestMetricsReporter = requestMetricsReporter ;
8995 setExperienceId (experienceIdHeaderValue );
9096 }
9197
@@ -108,7 +114,8 @@ <T, R extends ApiResponse<T>> PendingResult<T> handle(
108114 FieldNamingPolicy fieldNamingPolicy ,
109115 long errorTimeout ,
110116 Integer maxRetries ,
111- ExceptionsAllowedToRetry exceptionsAllowedToRetry );
117+ ExceptionsAllowedToRetry exceptionsAllowedToRetry ,
118+ RequestMetrics metrics );
112119
113120 <T , R extends ApiResponse <T >> PendingResult <T > handlePost (
114121 String hostName ,
@@ -120,7 +127,8 @@ <T, R extends ApiResponse<T>> PendingResult<T> handlePost(
120127 FieldNamingPolicy fieldNamingPolicy ,
121128 long errorTimeout ,
122129 Integer maxRetries ,
123- ExceptionsAllowedToRetry exceptionsAllowedToRetry );
130+ ExceptionsAllowedToRetry exceptionsAllowedToRetry ,
131+ RequestMetrics metrics );
124132
125133 void shutdown ();
126134
@@ -206,7 +214,8 @@ <T, R extends ApiResponse<T>> PendingResult<T> get(
206214 config .hostName ,
207215 config .path ,
208216 config .supportsClientId ,
209- query .toString ());
217+ query .toString (),
218+ requestMetricsReporter .newRequest (config .path ));
210219 }
211220
212221 <T , R extends ApiResponse <T >> PendingResult <T > get (
@@ -245,7 +254,8 @@ <T, R extends ApiResponse<T>> PendingResult<T> get(
245254 config .hostName ,
246255 config .path ,
247256 config .supportsClientId ,
248- query .toString ());
257+ query .toString (),
258+ requestMetricsReporter .newRequest (config .path ));
249259 }
250260
251261 <T , R extends ApiResponse <T >> PendingResult <T > post (
@@ -280,7 +290,8 @@ <T, R extends ApiResponse<T>> PendingResult<T> post(
280290 config .fieldNamingPolicy ,
281291 errorTimeout ,
282292 maxRetries ,
283- exceptionsAllowedToRetry );
293+ exceptionsAllowedToRetry ,
294+ requestMetricsReporter .newRequest (config .path ));
284295 }
285296
286297 private <T , R extends ApiResponse <T >> PendingResult <T > getWithPath (
@@ -289,7 +300,8 @@ private <T, R extends ApiResponse<T>> PendingResult<T> getWithPath(
289300 String hostName ,
290301 String path ,
291302 boolean canUseClientId ,
292- String encodedPath ) {
303+ String encodedPath ,
304+ RequestMetrics metrics ) {
293305 checkContext (canUseClientId );
294306 if (!encodedPath .startsWith ("&" )) {
295307 throw new IllegalArgumentException ("encodedPath must start with &" );
@@ -321,7 +333,8 @@ private <T, R extends ApiResponse<T>> PendingResult<T> getWithPath(
321333 fieldNamingPolicy ,
322334 errorTimeout ,
323335 maxRetries ,
324- exceptionsAllowedToRetry );
336+ exceptionsAllowedToRetry ,
337+ metrics );
325338 }
326339
327340 private void checkContext (boolean canUseClientId ) {
@@ -349,6 +362,7 @@ public static class Builder {
349362 private ExceptionsAllowedToRetry exceptionsAllowedToRetry = new ExceptionsAllowedToRetry ();
350363 private Integer maxRetries ;
351364 private UrlSigner urlSigner ;
365+ private RequestMetricsReporter requestMetricsReporter = new NoOpRequestMetricsReporter ();
352366 private String [] experienceIdHeaderValue ;
353367
354368 /** Builder pattern for the enclosing {@code GeoApiContext}. */
@@ -584,6 +598,11 @@ public Builder experienceId(String... experienceId) {
584598 return this ;
585599 }
586600
601+ public Builder requestMetricsReporter (RequestMetricsReporter requestMetricsReporter ) {
602+ this .requestMetricsReporter = requestMetricsReporter ;
603+ return this ;
604+ }
605+
587606 /**
588607 * Converts this builder into a {@code GeoApiContext}.
589608 *
@@ -600,6 +619,7 @@ public GeoApiContext build() {
600619 exceptionsAllowedToRetry ,
601620 maxRetries ,
602621 urlSigner ,
622+ requestMetricsReporter ,
603623 experienceIdHeaderValue );
604624 }
605625 }
0 commit comments