|
16 | 16 |
|
17 | 17 | package com.google.cloud.logging;
|
18 | 18 |
|
| 19 | +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; |
| 20 | +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; |
| 21 | + |
19 | 22 | import com.google.api.core.ApiFunction;
|
| 23 | +import com.google.api.core.ObsoleteApi; |
20 | 24 | import com.google.cloud.StringEnumType;
|
21 | 25 | import com.google.cloud.StringEnumValue;
|
22 | 26 | import com.google.common.base.MoreObjects;
|
23 | 27 | import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
24 | 28 | import java.io.Serializable;
|
| 29 | +import java.time.Duration; |
25 | 30 | import java.util.Objects;
|
26 |
| -import org.threeten.bp.Duration; |
27 | 31 |
|
28 | 32 | /**
|
29 | 33 | * Objects of this class represent information about the (optional) HTTP request associated with a
|
@@ -51,7 +55,7 @@ public final class HttpRequest implements Serializable {
|
51 | 55 | private final boolean cacheHit;
|
52 | 56 | private final boolean cacheValidatedWithOriginServer;
|
53 | 57 | private final Long cacheFillBytes;
|
54 |
| - private final Duration latency; |
| 58 | + private final java.time.Duration latency; |
55 | 59 |
|
56 | 60 | /** The HTTP request method. */
|
57 | 61 | public static final class RequestMethod extends StringEnumValue {
|
@@ -112,7 +116,7 @@ public static final class Builder {
|
112 | 116 | private boolean cacheHit;
|
113 | 117 | private boolean cacheValidatedWithOriginServer;
|
114 | 118 | private Long cacheFillBytes;
|
115 |
| - private Duration latency; |
| 119 | + private java.time.Duration latency; |
116 | 120 |
|
117 | 121 | Builder() {}
|
118 | 122 |
|
@@ -258,12 +262,18 @@ public Builder setCacheFillBytes(long cacheFillBytes) {
|
258 | 262 | return this;
|
259 | 263 | }
|
260 | 264 |
|
| 265 | + /** This method is obsolete. Use {@link #setLatencyDuration(java.time.Duration)} instead. */ |
| 266 | + @ObsoleteApi("Use setLatencyDuration(java.time.Duration) instead") |
| 267 | + public Builder setLatency(org.threeten.bp.Duration latency) { |
| 268 | + return setLatencyDuration(toJavaTimeDuration(latency)); |
| 269 | + } |
| 270 | + |
261 | 271 | /**
|
262 | 272 | * Sets the latency on the server, from the time the request was received until the response was
|
263 | 273 | * sent.
|
264 | 274 | */
|
265 | 275 | @CanIgnoreReturnValue
|
266 |
| - public Builder setLatency(Duration latency) { |
| 276 | + public Builder setLatencyDuration(java.time.Duration latency) { |
267 | 277 | this.latency = latency;
|
268 | 278 | return this;
|
269 | 279 | }
|
@@ -393,13 +403,19 @@ public Long getCacheFillBytes() {
|
393 | 403 | return cacheFillBytes;
|
394 | 404 | }
|
395 | 405 |
|
| 406 | + /** This method is obsolete. Use {@link #getLatencyDuration()} instead. */ |
| 407 | + @ObsoleteApi("Use getLatencyDuration() instead") |
| 408 | + public org.threeten.bp.Duration getLatency() { |
| 409 | + return toThreetenDuration(getLatencyDuration()); |
| 410 | + } |
| 411 | + |
396 | 412 | /**
|
397 | 413 | * Returns the processing latency on the server, from the time the request was received until the
|
398 | 414 | * response was sent.
|
399 | 415 | *
|
400 | 416 | * @return the latency, for null if not populated.
|
401 | 417 | */
|
402 |
| - public Duration getLatency() { |
| 418 | + public Duration getLatencyDuration() { |
403 | 419 | return latency;
|
404 | 420 | }
|
405 | 421 |
|
@@ -561,7 +577,7 @@ static HttpRequest fromPb(com.google.logging.type.HttpRequest requestPb) {
|
561 | 577 | }
|
562 | 578 | if (requestPb.hasLatency()) {
|
563 | 579 | // NOTE(pongad): Don't convert to nano; large durations overflow longs!
|
564 |
| - builder.setLatency( |
| 580 | + builder.setLatencyDuration( |
565 | 581 | Duration.ofSeconds(
|
566 | 582 | requestPb.getLatency().getSeconds(), requestPb.getLatency().getNanos()));
|
567 | 583 | }
|
|
0 commit comments