Skip to content

Commit 308aeaf

Browse files
diegomarquezpblakeli0meltsufinlqiu96
authored
feat: Introduce java.time to Gax-Java (#1872)
This introduces the use of `java.time` in replacement of `org.threeten` backport classes. ### Message to library users (release note) We have made the following backwards-compatible changes in this library: * We have changed the method return type and argument type in __internal__ classes from `org.threeten.bp` to `java.time`. This has no effect in the API surface. * We have added `java.time` versions for each of the abstract methods involving `org.threeten.bp`. The affected classes are `BatchingSettings`, `RetrySettings`, `TimedAttemptSettings` and `ClientContext`, all of which are `AutoValue` classes, not meant to be extended by our users. * All getters and setters using `org.threeten.bp` will be marked final because we will force their behavior to be the same one as the `java.time` counterpart, which has the actual implementation. The affected classes are `BatchingSettings`, `RetrySettings`, `TimedAttemptSettings` and `ClientContext`, all of which are `AutoValue` classes, not meant to be extended by our users. * In three `interface`s, we have added `java.time` versions for each of the methods involving `org.threeten.bp`. The affected interfaces are `WatchdogProvider` (public interface), `ApiTracer` (internal) and `ApiCallContext` (internal). The new method in `WatchdogProvider` has a `default` behavior, which is to call the `threeten` counterpart, in order to make this a backwards-compatible change. ## Implementation It preserves method signatures using `threeten`. The cases are: ### `@AutoValue` clases and classes with public interface involving time objects Autovalues will have an internal `threeten` variable with a convenience `java.time` wrapper method. For example: https://github.com/googleapis/sdk-platform-java/blob/667f2da15d0800d87d0866e36627ac23955c0b01/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java#L78-L89 and https://github.com/googleapis/sdk-platform-java/blob/a99d3c1acd4b25a28bd571c8c6f7f7f5d74e1365/gax-java/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java#L243-L262 ### Internal variables `Duration` or `Instant` private variables are switched to `java.time`. In this case, the wrappers are of `threeten` clasess. For example https://github.com/googleapis/sdk-platform-java/blob/667f2da15d0800d87d0866e36627ac23955c0b01/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java#L237-L247 ## Deprecation warning `threeten` methods will now have an `@ObsoleteApi` annotation. For example: https://github.com/googleapis/sdk-platform-java/blob/667f2da15d0800d87d0866e36627ac23955c0b01/gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingSettings.java#L106 ## CLIRR checks ### `gax-java/gax` ``` [ERROR] 7013: com.google.api.gax.batching.BatchingSettings: Abstract method 'public java.time.Duration getDelayThresholdDuration()' has been added [ERROR] 7014: com.google.api.gax.batching.BatchingSettings$Builder: Method 'public com.google.api.gax.batching.BatchingSettings$Builder setDelayThreshold(org.threeten.bp.Duration)' is now final [ERROR] 7013: com.google.api.gax.batching.BatchingSettings$Builder: Abstract method 'public com.google.api.gax.batching.BatchingSettings$Builder setDelayThresholdDuration(java.time.Duration)' has been added [ERROR] 7005: com.google.api.gax.retrying.DirectRetryingExecutor: Parameter 1 of 'protected void sleep(org.threeten.bp.Duration)' has changed its type to java.time.Duration [ERROR] 7013: com.google.api.gax.retrying.RetrySettings: Abstract method 'public java.time.Duration getInitialRetryDelayDuration()' has been added [ERROR] 7014: com.google.api.gax.retrying.RetrySettings: Method 'public org.threeten.bp.Duration getInitialRpcTimeout()' is now final [ERROR] 7013: com.google.api.gax.retrying.RetrySettings: Abstract method 'public java.time.Duration getInitialRpcTimeoutDuration()' has been added [ERROR] 7013: com.google.api.gax.retrying.RetrySettings: Abstract method 'public java.time.Duration getMaxRetryDelayDuration()' has been added [ERROR] 7014: com.google.api.gax.retrying.RetrySettings: Method 'public org.threeten.bp.Duration getMaxRpcTimeout()' is now final [ERROR] 7013: com.google.api.gax.retrying.RetrySettings: Abstract method 'public java.time.Duration getMaxRpcTimeoutDuration()' has been added [ERROR] 7013: com.google.api.gax.retrying.RetrySettings: Abstract method 'public java.time.Duration getTotalTimeoutDuration()' has been added [ERROR] 7014: com.google.api.gax.retrying.RetrySettings$Builder: Method 'public org.threeten.bp.Duration getInitialRetryDelay()' is now final [ERROR] 7013: com.google.api.gax.retrying.RetrySettings$Builder: Abstract method 'public java.time.Duration getInitialRetryDelayDuration()' has been added [ERROR] 7014: com.google.api.gax.retrying.RetrySettings$Builder: Method 'public org.threeten.bp.Duration getInitialRpcTimeout()' is now final [ERROR] 7013: com.google.api.gax.retrying.RetrySettings$Builder: Abstract method 'public java.time.Duration getInitialRpcTimeoutDuration()' has been added [ERROR] 7014: com.google.api.gax.retrying.RetrySettings$Builder: Method 'public org.threeten.bp.Duration getMaxRetryDelay()' is now final [ERROR] 7013: com.google.api.gax.retrying.RetrySettings$Builder: Abstract method 'public java.time.Duration getMaxRetryDelayDuration()' has been added [ERROR] 7014: com.google.api.gax.retrying.RetrySettings$Builder: Method 'public org.threeten.bp.Duration getMaxRpcTimeout()' is now final [ERROR] 7013: com.google.api.gax.retrying.RetrySettings$Builder: Abstract method 'public java.time.Duration getMaxRpcTimeoutDuration()' has been added [ERROR] 7014: com.google.api.gax.retrying.RetrySettings$Builder: Method 'public org.threeten.bp.Duration getTotalTimeout()' is now final [ERROR] 7013: com.google.api.gax.retrying.RetrySettings$Builder: Abstract method 'public java.time.Duration getTotalTimeoutDuration()' has been added [ERROR] 7014: com.google.api.gax.retrying.RetrySettings$Builder: Method 'public com.google.api.gax.retrying.RetrySettings$Builder setInitialRetryDelay(org.threeten.bp.Duration)' is now final [ERROR] 7013: com.google.api.gax.retrying.RetrySettings$Builder: Abstract method 'public com.google.api.gax.retrying.RetrySettings$Builder setInitialRetryDelayDuration(java.time.Duration)' has been added [ERROR] 7014: com.google.api.gax.retrying.RetrySettings$Builder: Method 'public com.google.api.gax.retrying.RetrySettings$Builder setInitialRpcTimeout(org.threeten.bp.Duration)' is now final [ERROR] 7013: com.google.api.gax.retrying.RetrySettings$Builder: Abstract method 'public com.google.api.gax.retrying.RetrySettings$Builder setInitialRpcTimeoutDuration(java.time.Duration)' has been added [ERROR] 7014: com.google.api.gax.retrying.RetrySettings$Builder: Method 'public com.google.api.gax.retrying.RetrySettings$Builder setMaxRetryDelay(org.threeten.bp.Duration)' is now final [ERROR] 7013: com.google.api.gax.retrying.RetrySettings$Builder: Abstract method 'public com.google.api.gax.retrying.RetrySettings$Builder setMaxRetryDelayDuration(java.time.Duration)' has been added [ERROR] 7014: com.google.api.gax.retrying.RetrySettings$Builder: Method 'public com.google.api.gax.retrying.RetrySettings$Builder setMaxRpcTimeout(org.threeten.bp.Duration)' is now final [ERROR] 7013: com.google.api.gax.retrying.RetrySettings$Builder: Abstract method 'public com.google.api.gax.retrying.RetrySettings$Builder setMaxRpcTimeoutDuration(java.time.Duration)' has been added [ERROR] 7014: com.google.api.gax.retrying.RetrySettings$Builder: Method 'public com.google.api.gax.retrying.RetrySettings$Builder setTotalTimeout(org.threeten.bp.Duration)' is now final [ERROR] 7013: com.google.api.gax.retrying.RetrySettings$Builder: Abstract method 'public com.google.api.gax.retrying.RetrySettings$Builder setTotalTimeoutDuration(java.time.Duration)' has been added [ERROR] 7014: com.google.api.gax.retrying.TimedAttemptSettings: Method 'public org.threeten.bp.Duration getRandomizedRetryDelay()' is now final [ERROR] 7013: com.google.api.gax.retrying.TimedAttemptSettings: Abstract method 'public java.time.Duration getRandomizedRetryDelayDuration()' has been added [ERROR] 7014: com.google.api.gax.retrying.TimedAttemptSettings: Method 'public org.threeten.bp.Duration getRetryDelay()' is now final [ERROR] 7013: com.google.api.gax.retrying.TimedAttemptSettings: Abstract method 'public java.time.Duration getRetryDelayDuration()' has been added [ERROR] 7014: com.google.api.gax.retrying.TimedAttemptSettings: Method 'public org.threeten.bp.Duration getRpcTimeout()' is now final [ERROR] 7013: com.google.api.gax.retrying.TimedAttemptSettings: Abstract method 'public java.time.Duration getRpcTimeoutDuration()' has been added [ERROR] 7014: com.google.api.gax.retrying.TimedAttemptSettings$Builder: Method 'public com.google.api.gax.retrying.TimedAttemptSettings$Builder setRandomizedRetryDelay(org.threeten.bp.Duration)' is now final [ERROR] 7013: com.google.api.gax.retrying.TimedAttemptSettings$Builder: Abstract method 'public com.google.api.gax.retrying.TimedAttemptSettings$Builder setRandomizedRetryDelayDuration(java.time.Duration)' has been added [ERROR] 7014: com.google.api.gax.retrying.TimedAttemptSettings$Builder: Method 'public com.google.api.gax.retrying.TimedAttemptSettings$Builder setRetryDelay(org.threeten.bp.Duration)' is now final [ERROR] 7013: com.google.api.gax.retrying.TimedAttemptSettings$Builder: Abstract method 'public com.google.api.gax.retrying.TimedAttemptSettings$Builder setRetryDelayDuration(java.time.Duration)' has been added [ERROR] 7014: com.google.api.gax.retrying.TimedAttemptSettings$Builder: Method 'public com.google.api.gax.retrying.TimedAttemptSettings$Builder setRpcTimeout(org.threeten.bp.Duration)' is now final [ERROR] 7013: com.google.api.gax.retrying.TimedAttemptSettings$Builder: Abstract method 'public com.google.api.gax.retrying.TimedAttemptSettings$Builder setRpcTimeoutDuration(java.time.Duration)' has been added [ERROR] 7012: com.google.api.gax.rpc.ApiCallContext: Method 'public java.time.Duration getStreamIdleTimeoutDuration()' has been added to an interface [ERROR] 7012: com.google.api.gax.rpc.ApiCallContext: Method 'public java.time.Duration getStreamWaitTimeoutDuration()' has been added to an interface [ERROR] 7012: com.google.api.gax.rpc.ApiCallContext: Method 'public java.time.Duration getTimeoutDuration()' has been added to an interface [ERROR] 7012: com.google.api.gax.rpc.ApiCallContext: Method 'public com.google.api.gax.rpc.ApiCallContext withStreamIdleTimeoutDuration(java.time.Duration)' has been added to an interface [ERROR] 7012: com.google.api.gax.rpc.ApiCallContext: Method 'public com.google.api.gax.rpc.ApiCallContext withStreamWaitTimeoutDuration(java.time.Duration)' has been added to an interface [ERROR] 7012: com.google.api.gax.rpc.ApiCallContext: Method 'public com.google.api.gax.rpc.ApiCallContext withTimeoutDuration(java.time.Duration)' has been added to an interface [ERROR] 7014: com.google.api.gax.rpc.ClientContext: Method 'public org.threeten.bp.Duration getStreamWatchdogCheckInterval()' is now final [ERROR] 7013: com.google.api.gax.rpc.ClientContext: Abstract method 'public java.time.Duration getStreamWatchdogCheckIntervalDuration()' has been added [ERROR] 7014: com.google.api.gax.rpc.ClientContext$Builder: Method 'public com.google.api.gax.rpc.ClientContext$Builder setStreamWatchdogCheckInterval(org.threeten.bp.Duration)' is now final [ERROR] 7013: com.google.api.gax.rpc.ClientContext$Builder: Abstract method 'public com.google.api.gax.rpc.ClientContext$Builder setStreamWatchdogCheckIntervalDuration(java.time.Duration)' has been added [ERROR] 7012: com.google.api.gax.rpc.WatchdogProvider: Method 'public com.google.api.gax.rpc.WatchdogProvider withCheckIntervalDuration(java.time.Duration)' has been added to an interface [ERROR] 7012: com.google.api.gax.tracing.ApiTracer: Method 'public void attemptFailedDuration(java.lang.Throwable, java.time.Duration)' has been added to an interface ``` We have decided to ignore a these CLIRR messages due to the following reasons * `7005` (method type change): This has only been implemented in internal classes, not exposed to our customers * `7013` (new abstract method added): We have added several java.time versions for each of the methods involving org.threeten.bp. This affects `AutoValue` classes only. * `7014` (convert to final): All getters and setters using org.threeten.bp will be marked final because we will force their behavior to be the same one as the java.time counterpart, which has the actual implementation. This affects `AutoValue` classes only. * `7012` (new method in interface): We have added several java.time versions for each of the methods involving org.threeten.bp. For the only public interface `WatchdogProvider`, we added a `default` behavior. --------- Co-authored-by: Blake Li <[email protected]> Co-authored-by: Mike Eltsufin <[email protected]> Co-authored-by: Lawrence Qiu <[email protected]>
1 parent 36d12a6 commit 308aeaf

File tree

104 files changed

+2948
-929
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+2948
-929
lines changed

gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import java.util.logging.Level;
5656
import java.util.logging.Logger;
5757
import javax.annotation.Nullable;
58-
import org.threeten.bp.Duration;
5958

6059
/**
6160
* A {@link ManagedChannel} that will send requests round-robin via a set of channels.
@@ -69,7 +68,7 @@
6968
*/
7069
class ChannelPool extends ManagedChannel {
7170
@VisibleForTesting static final Logger LOG = Logger.getLogger(ChannelPool.class.getName());
72-
private static final Duration REFRESH_PERIOD = Duration.ofMinutes(50);
71+
private static final java.time.Duration REFRESH_PERIOD = java.time.Duration.ofMinutes(50);
7372

7473
private final ChannelPoolSettings settings;
7574
private final ChannelFactory channelFactory;

gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java

+77-20
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929
*/
3030
package com.google.api.gax.grpc;
3131

32+
import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration;
33+
import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration;
34+
3235
import com.google.api.core.BetaApi;
3336
import com.google.api.core.InternalApi;
37+
import com.google.api.core.ObsoleteApi;
3438
import com.google.api.gax.retrying.RetrySettings;
3539
import com.google.api.gax.rpc.ApiCallContext;
3640
import com.google.api.gax.rpc.ApiExceptionFactory;
@@ -62,7 +66,6 @@
6266
import java.util.Set;
6367
import javax.annotation.Nonnull;
6468
import javax.annotation.Nullable;
65-
import org.threeten.bp.Duration;
6669

6770
/**
6871
* GrpcCallContext encapsulates context data used to make a grpc call.
@@ -84,9 +87,9 @@ public final class GrpcCallContext implements ApiCallContext {
8487
private final Channel channel;
8588
@Nullable private final Credentials credentials;
8689
private final CallOptions callOptions;
87-
@Nullable private final Duration timeout;
88-
@Nullable private final Duration streamWaitTimeout;
89-
@Nullable private final Duration streamIdleTimeout;
90+
@Nullable private final java.time.Duration timeout;
91+
@Nullable private final java.time.Duration streamWaitTimeout;
92+
@Nullable private final java.time.Duration streamIdleTimeout;
9093
@Nullable private final Integer channelAffinity;
9194
@Nullable private final RetrySettings retrySettings;
9295
@Nullable private final ImmutableSet<StatusCode.Code> retryableCodes;
@@ -132,9 +135,9 @@ private GrpcCallContext(
132135
Channel channel,
133136
@Nullable Credentials credentials,
134137
CallOptions callOptions,
135-
@Nullable Duration timeout,
136-
@Nullable Duration streamWaitTimeout,
137-
@Nullable Duration streamIdleTimeout,
138+
@Nullable java.time.Duration timeout,
139+
@Nullable java.time.Duration streamWaitTimeout,
140+
@Nullable java.time.Duration streamIdleTimeout,
138141
@Nullable Integer channelAffinity,
139142
ImmutableMap<String, List<String>> extraHeaders,
140143
ApiCallContextOptions options,
@@ -228,8 +231,15 @@ public GrpcCallContext withEndpointContext(EndpointContext endpointContext) {
228231
endpointContext);
229232
}
230233

234+
/** This method is obsolete. Use {@link #withTimeoutDuration(java.time.Duration)} instead. */
235+
@Override
236+
@ObsoleteApi("Use withTimeoutDuration(java.time.Duration) instead")
237+
public GrpcCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout) {
238+
return withTimeoutDuration(toJavaTimeDuration(timeout));
239+
}
240+
231241
@Override
232-
public GrpcCallContext withTimeout(@Nullable Duration timeout) {
242+
public GrpcCallContext withTimeoutDuration(@Nullable java.time.Duration timeout) {
233243
// Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts.
234244
if (timeout != null && (timeout.isZero() || timeout.isNegative())) {
235245
timeout = null;
@@ -255,17 +265,37 @@ public GrpcCallContext withTimeout(@Nullable Duration timeout) {
255265
endpointContext);
256266
}
257267

268+
/** This method is obsolete. Use {@link #getTimeoutDuration()} instead. */
258269
@Nullable
259270
@Override
260-
public Duration getTimeout() {
271+
@ObsoleteApi("Use getTimeoutDuration() instead")
272+
public org.threeten.bp.Duration getTimeout() {
273+
return toThreetenDuration(getTimeoutDuration());
274+
}
275+
276+
@Nullable
277+
@Override
278+
public java.time.Duration getTimeoutDuration() {
261279
return timeout;
262280
}
263281

282+
/**
283+
* This method is obsolete. Use {@link #withStreamWaitTimeoutDuration(java.time.Duration)}
284+
* instead.
285+
*/
286+
@Override
287+
@ObsoleteApi("Use withStreamWaitTimeoutDuration(java.time.Duration) instead")
288+
public GrpcCallContext withStreamWaitTimeout(
289+
@Nullable org.threeten.bp.Duration streamWaitTimeout) {
290+
return withStreamWaitTimeoutDuration(toJavaTimeDuration(streamWaitTimeout));
291+
}
292+
264293
@Override
265-
public GrpcCallContext withStreamWaitTimeout(@Nullable Duration streamWaitTimeout) {
294+
public GrpcCallContext withStreamWaitTimeoutDuration(
295+
@Nullable java.time.Duration streamWaitTimeout) {
266296
if (streamWaitTimeout != null) {
267297
Preconditions.checkArgument(
268-
streamWaitTimeout.compareTo(Duration.ZERO) >= 0, "Invalid timeout: < 0 s");
298+
streamWaitTimeout.compareTo(java.time.Duration.ZERO) >= 0, "Invalid timeout: < 0 s");
269299
}
270300

271301
return new GrpcCallContext(
@@ -283,11 +313,23 @@ public GrpcCallContext withStreamWaitTimeout(@Nullable Duration streamWaitTimeou
283313
endpointContext);
284314
}
285315

316+
/**
317+
* This method is obsolete. Use {@link #withStreamIdleTimeoutDuration(java.time.Duration)}
318+
* instead.
319+
*/
320+
@Override
321+
@ObsoleteApi("Use withStreamIdleTimeoutDuration(java.time.Duration) instead")
322+
public GrpcCallContext withStreamIdleTimeout(
323+
@Nullable org.threeten.bp.Duration streamIdleTimeout) {
324+
return withStreamIdleTimeoutDuration(toJavaTimeDuration(streamIdleTimeout));
325+
}
326+
286327
@Override
287-
public GrpcCallContext withStreamIdleTimeout(@Nullable Duration streamIdleTimeout) {
328+
public GrpcCallContext withStreamIdleTimeoutDuration(
329+
@Nullable java.time.Duration streamIdleTimeout) {
288330
if (streamIdleTimeout != null) {
289331
Preconditions.checkArgument(
290-
streamIdleTimeout.compareTo(Duration.ZERO) >= 0, "Invalid timeout: < 0 s");
332+
streamIdleTimeout.compareTo(java.time.Duration.ZERO) >= 0, "Invalid timeout: < 0 s");
291333
}
292334

293335
return new GrpcCallContext(
@@ -424,17 +466,17 @@ public ApiCallContext merge(ApiCallContext inputCallContext) {
424466
newTracer = callOptions.getOption(TRACER_KEY);
425467
}
426468

427-
Duration newTimeout = grpcCallContext.timeout;
469+
java.time.Duration newTimeout = grpcCallContext.timeout;
428470
if (newTimeout == null) {
429471
newTimeout = timeout;
430472
}
431473

432-
Duration newStreamWaitTimeout = grpcCallContext.streamWaitTimeout;
474+
java.time.Duration newStreamWaitTimeout = grpcCallContext.streamWaitTimeout;
433475
if (newStreamWaitTimeout == null) {
434476
newStreamWaitTimeout = streamWaitTimeout;
435477
}
436478

437-
Duration newStreamIdleTimeout = grpcCallContext.streamIdleTimeout;
479+
java.time.Duration newStreamIdleTimeout = grpcCallContext.streamIdleTimeout;
438480
if (newStreamIdleTimeout == null) {
439481
newStreamIdleTimeout = streamIdleTimeout;
440482
}
@@ -496,25 +538,40 @@ public CallOptions getCallOptions() {
496538
return callOptions;
497539
}
498540

541+
/** This method is obsolete. Use {@link #getStreamWaitTimeoutDuration()} instead. */
542+
@Override
543+
@Nullable
544+
@ObsoleteApi("Use getStreamWaitTimeoutDuration() instead")
545+
public org.threeten.bp.Duration getStreamWaitTimeout() {
546+
return toThreetenDuration(getStreamWaitTimeoutDuration());
547+
}
548+
499549
/**
500550
* The stream wait timeout set for this context.
501551
*
502-
* @see ApiCallContext#withStreamWaitTimeout(Duration)
552+
* @see ApiCallContext#withStreamWaitTimeoutDuration(java.time.Duration)
503553
*/
504554
@Override
505555
@Nullable
506-
public Duration getStreamWaitTimeout() {
556+
public java.time.Duration getStreamWaitTimeoutDuration() {
507557
return streamWaitTimeout;
508558
}
509559

560+
/** This method is obsolete. Use {@link #getStreamIdleTimeoutDuration()} instead. */
561+
@Override
562+
@Nullable
563+
@ObsoleteApi("Use getStreamIdleTimeoutDuration() instead")
564+
public org.threeten.bp.Duration getStreamIdleTimeout() {
565+
return toThreetenDuration(getStreamIdleTimeoutDuration());
566+
}
510567
/**
511568
* The stream idle timeout set for this context.
512569
*
513-
* @see ApiCallContext#withStreamIdleTimeout(Duration)
570+
* @see ApiCallContext#withStreamIdleTimeoutDuration(java.time.Duration)
514571
*/
515572
@Override
516573
@Nullable
517-
public Duration getStreamIdleTimeout() {
574+
public java.time.Duration getStreamIdleTimeoutDuration() {
518575
return streamIdleTimeout;
519576
}
520577

gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcClientCalls.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public static <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall(
7474
Preconditions.checkNotNull(callOptions);
7575

7676
// Try to convert the timeout into a deadline and use it if it occurs before the actual deadline
77-
if (grpcContext.getTimeout() != null) {
77+
if (grpcContext.getTimeoutDuration() != null) {
7878
Deadline newDeadline =
79-
Deadline.after(grpcContext.getTimeout().toMillis(), TimeUnit.MILLISECONDS);
79+
Deadline.after(grpcContext.getTimeoutDuration().toMillis(), TimeUnit.MILLISECONDS);
8080
Deadline oldDeadline = callOptions.getDeadline();
8181

8282
if (oldDeadline == null || newDeadline.isBefore(oldDeadline)) {

gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java

+54-11
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@
2929
*/
3030
package com.google.api.gax.grpc;
3131

32+
import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration;
33+
import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration;
34+
3235
import com.google.api.core.ApiFunction;
3336
import com.google.api.core.BetaApi;
3437
import com.google.api.core.InternalApi;
38+
import com.google.api.core.ObsoleteApi;
3539
import com.google.api.gax.core.ExecutorProvider;
3640
import com.google.api.gax.rpc.FixedHeaderProvider;
3741
import com.google.api.gax.rpc.HeaderProvider;
@@ -67,7 +71,6 @@
6771
import java.util.logging.Logger;
6872
import javax.annotation.Nullable;
6973
import javax.net.ssl.KeyManagerFactory;
70-
import org.threeten.bp.Duration;
7174

7275
/**
7376
* InstantiatingGrpcChannelProvider is a TransportChannelProvider which constructs a gRPC
@@ -106,8 +109,8 @@ public final class InstantiatingGrpcChannelProvider implements TransportChannelP
106109
@Nullable private final GrpcInterceptorProvider interceptorProvider;
107110
@Nullable private final Integer maxInboundMessageSize;
108111
@Nullable private final Integer maxInboundMetadataSize;
109-
@Nullable private final Duration keepAliveTime;
110-
@Nullable private final Duration keepAliveTimeout;
112+
@Nullable private final java.time.Duration keepAliveTime;
113+
@Nullable private final java.time.Duration keepAliveTimeout;
111114
@Nullable private final Boolean keepAliveWithoutCalls;
112115
private final ChannelPoolSettings channelPoolSettings;
113116
@Nullable private final Credentials credentials;
@@ -490,13 +493,25 @@ public String getEndpoint() {
490493
return endpoint;
491494
}
492495

496+
/** This method is obsolete. Use {@link #getKeepAliveTimeDuration()} instead. */
497+
@ObsoleteApi("Use getKeepAliveTimeDuration() instead")
498+
public org.threeten.bp.Duration getKeepAliveTime() {
499+
return toThreetenDuration(getKeepAliveTimeDuration());
500+
}
501+
493502
/** The time without read activity before sending a keepalive ping. */
494-
public Duration getKeepAliveTime() {
503+
public java.time.Duration getKeepAliveTimeDuration() {
495504
return keepAliveTime;
496505
}
497506

507+
/** This method is obsolete. Use {@link #getKeepAliveTimeoutDuration()} instead */
508+
@ObsoleteApi("Use getKeepAliveTimeoutDuration() instead")
509+
public org.threeten.bp.Duration getKeepAliveTimeout() {
510+
return toThreetenDuration(getKeepAliveTimeoutDuration());
511+
}
512+
498513
/** The time without read activity after sending a keepalive ping. */
499-
public Duration getKeepAliveTimeout() {
514+
public java.time.Duration getKeepAliveTimeoutDuration() {
500515
return keepAliveTimeout;
501516
}
502517

@@ -540,8 +555,8 @@ public static final class Builder {
540555
@Nullable private GrpcInterceptorProvider interceptorProvider;
541556
@Nullable private Integer maxInboundMessageSize;
542557
@Nullable private Integer maxInboundMetadataSize;
543-
@Nullable private Duration keepAliveTime;
544-
@Nullable private Duration keepAliveTimeout;
558+
@Nullable private java.time.Duration keepAliveTime;
559+
@Nullable private java.time.Duration keepAliveTimeout;
545560
@Nullable private Boolean keepAliveWithoutCalls;
546561
@Nullable private ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator;
547562
@Nullable private Credentials credentials;
@@ -679,25 +694,53 @@ public Integer getMaxInboundMetadataSize() {
679694
return maxInboundMetadataSize;
680695
}
681696

697+
/**
698+
* This method is obsolete. Use {@link #setKeepAliveTimeDuration(java.time.Duration)} instead.
699+
*/
700+
@ObsoleteApi("Use setKeepAliveTimeDuration(java.time.Duration) instead")
701+
public Builder setKeepAliveTime(org.threeten.bp.Duration duration) {
702+
return setKeepAliveTimeDuration(toJavaTimeDuration(duration));
703+
}
682704
/** The time without read activity before sending a keepalive ping. */
683-
public Builder setKeepAliveTime(Duration duration) {
705+
public Builder setKeepAliveTimeDuration(java.time.Duration duration) {
684706
this.keepAliveTime = duration;
685707
return this;
686708
}
687709

710+
/** This method is obsolete. Use {@link #getKeepAliveTimeDuration()} instead. */
711+
@ObsoleteApi("Use getKeepAliveTimeDuration() instead")
712+
public org.threeten.bp.Duration getKeepAliveTime() {
713+
return toThreetenDuration(getKeepAliveTimeDuration());
714+
}
715+
688716
/** The time without read activity before sending a keepalive ping. */
689-
public Duration getKeepAliveTime() {
717+
public java.time.Duration getKeepAliveTimeDuration() {
690718
return keepAliveTime;
691719
}
692720

721+
/**
722+
* This method is obsolete. Use {@link #setKeepAliveTimeoutDuration(java.time.Duration)}
723+
* instead.
724+
*/
725+
@ObsoleteApi("Use setKeepAliveTimeoutDuration(java.time.Duration) instead")
726+
public Builder setKeepAliveTimeout(org.threeten.bp.Duration duration) {
727+
return setKeepAliveTimeoutDuration(toJavaTimeDuration(duration));
728+
}
729+
693730
/** The time without read activity after sending a keepalive ping. */
694-
public Builder setKeepAliveTimeout(Duration duration) {
731+
public Builder setKeepAliveTimeoutDuration(java.time.Duration duration) {
695732
this.keepAliveTimeout = duration;
696733
return this;
697734
}
698735

736+
/** This method is obsolete. Use {@link #getKeepAliveTimeoutDuration()} instead */
737+
@ObsoleteApi("Use getKeepAliveTimeoutDuration() instead")
738+
public org.threeten.bp.Duration getKeepAliveTimeout() {
739+
return toThreetenDuration(getKeepAliveTimeoutDuration());
740+
}
741+
699742
/** The time without read activity after sending a keepalive ping. */
700-
public Duration getKeepAliveTimeout() {
743+
public java.time.Duration getKeepAliveTimeoutDuration() {
701744
return keepAliveTimeout;
702745
}
703746

gax-java/gax-grpc/src/main/java/com/google/longrunning/stub/OperationsStubSettings.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
import com.google.longrunning.WaitOperationRequest;
6464
import com.google.protobuf.Empty;
6565
import java.io.IOException;
66-
import org.threeten.bp.Duration;
6766

6867
/** Settings class to configure an instance of {@link OperationsStub}. */
6968
public class OperationsStubSettings extends StubSettings<OperationsStubSettings> {
@@ -243,13 +242,13 @@ public static class Builder extends StubSettings.Builder<OperationsStubSettings,
243242
RetrySettings settings = null;
244243
settings =
245244
RetrySettings.newBuilder()
246-
.setInitialRetryDelay(Duration.ofMillis(100L))
245+
.setInitialRetryDelayDuration(java.time.Duration.ofMillis(100L))
247246
.setRetryDelayMultiplier(1.3)
248-
.setMaxRetryDelay(Duration.ofMillis(60000L))
249-
.setInitialRpcTimeout(Duration.ofMillis(90000L))
247+
.setMaxRetryDelayDuration(java.time.Duration.ofMillis(60000L))
248+
.setInitialRpcTimeoutDuration(java.time.Duration.ofMillis(90000L))
250249
.setRpcTimeoutMultiplier(1.0)
251-
.setMaxRpcTimeout(Duration.ofMillis(90000L))
252-
.setTotalTimeout(Duration.ofMillis(600000L))
250+
.setMaxRpcTimeoutDuration(java.time.Duration.ofMillis(90000L))
251+
.setTotalTimeoutDuration(java.time.Duration.ofMillis(600000L))
253252
.build();
254253
definitions.put("default", settings);
255254
RETRY_PARAM_DEFINITIONS = definitions.build();

0 commit comments

Comments
 (0)