16
16
17
17
package com .google .cloud .storage ;
18
18
19
+ import static com .google .api .gax .util .TimeConversionUtils .toJavaTimeDuration ;
20
+ import static com .google .api .gax .util .TimeConversionUtils .toThreetenDuration ;
19
21
import static com .google .common .base .Preconditions .checkArgument ;
20
22
import static java .util .Objects .requireNonNull ;
21
23
22
24
import com .google .api .core .ApiClock ;
23
25
import com .google .api .core .BetaApi ;
24
26
import com .google .api .core .InternalApi ;
27
+ import com .google .api .core .ObsoleteApi ;
25
28
import com .google .api .gax .core .CredentialsProvider ;
26
29
import com .google .api .gax .core .FixedCredentialsProvider ;
27
30
import com .google .api .gax .core .NoCredentialsProvider ;
97
100
import java .util .Objects ;
98
101
import java .util .Set ;
99
102
import org .checkerframework .checker .nullness .qual .NonNull ;
100
- import org .threeten .bp .Duration ;
101
103
102
104
/** @since 2.14.0 */
103
105
@ TransportCompatibility (Transport .GRPC )
@@ -110,7 +112,7 @@ public final class GrpcStorageOptions extends StorageOptions
110
112
private static final String DEFAULT_HOST = "https://storage.googleapis.com" ;
111
113
112
114
private final GrpcRetryAlgorithmManager retryAlgorithmManager ;
113
- private final Duration terminationAwaitDuration ;
115
+ private final java . time . Duration terminationAwaitDuration ;
114
116
private final boolean attemptDirectPath ;
115
117
private final boolean enableGrpcClientMetrics ;
116
118
@@ -126,7 +128,8 @@ private GrpcStorageOptions(Builder builder, GrpcStorageDefaults serviceDefaults)
126
128
builder .storageRetryStrategy , serviceDefaults .getStorageRetryStrategy ()));
127
129
this .terminationAwaitDuration =
128
130
MoreObjects .firstNonNull (
129
- builder .terminationAwaitDuration , serviceDefaults .getTerminationAwaitDuration ());
131
+ builder .terminationAwaitDuration ,
132
+ serviceDefaults .getTerminationAwaitDurationJavaTime ());
130
133
this .attemptDirectPath = builder .attemptDirectPath ;
131
134
this .enableGrpcClientMetrics = builder .enableGrpcClientMetrics ;
132
135
this .grpcClientMetricsManuallyEnabled = builder .grpcMetricsManuallyEnabled ;
@@ -145,7 +148,7 @@ GrpcRetryAlgorithmManager getRetryAlgorithmManager() {
145
148
}
146
149
147
150
@ InternalApi
148
- Duration getTerminationAwaitDuration () {
151
+ java . time . Duration getTerminationAwaitDuration () {
149
152
return terminationAwaitDuration ;
150
153
}
151
154
@@ -314,17 +317,17 @@ private Tuple<StorageSettings, Opts<UserProject>> resolveSettingsAndOpts() throw
314
317
// seconds.
315
318
// To allow read streams to have longer lifespans, crank up their timeouts, instead rely
316
319
// on idleTimeout below.
317
- .setLogicalTimeout (Duration .ofDays (28 ))
320
+ .setLogicalTimeout (java . time . Duration .ofDays (28 ))
318
321
.build ();
319
- Duration totalTimeout = baseRetrySettings .getTotalTimeout ();
322
+ java . time . Duration totalTimeout = baseRetrySettings .getTotalTimeoutDuration ();
320
323
Set <Code > startResumableWriteRetryableCodes =
321
324
builder .startResumableWriteSettings ().getRetryableCodes ();
322
325
323
326
// retries for unary methods are generally handled at a different level, except
324
327
// StartResumableWrite
325
328
builder .applyToAllUnaryMethods (
326
329
input -> {
327
- input .setSimpleTimeoutNoRetries (totalTimeout );
330
+ input .setSimpleTimeoutNoRetriesDuration (totalTimeout );
328
331
return null ;
329
332
});
330
333
@@ -342,7 +345,7 @@ private Tuple<StorageSettings, Opts<UserProject>> resolveSettingsAndOpts() throw
342
345
// for reads, the stream can be held open for a long time in order to read all bytes,
343
346
// this is totally valid. instead we want to monitor if the stream is doing work and if not
344
347
// timeout.
345
- .setIdleTimeout (totalTimeout );
348
+ .setIdleTimeoutDuration (totalTimeout );
346
349
return Tuple .of (builder .build (), defaultOpts );
347
350
}
348
351
@@ -412,7 +415,7 @@ protected boolean shouldRefreshService(Storage cachedService) {
412
415
public static final class Builder extends StorageOptions .Builder {
413
416
414
417
private StorageRetryStrategy storageRetryStrategy ;
415
- private Duration terminationAwaitDuration ;
418
+ private java . time . Duration terminationAwaitDuration ;
416
419
private boolean attemptDirectPath = GrpcStorageDefaults .INSTANCE .isAttemptDirectPath ();
417
420
private boolean enableGrpcClientMetrics =
418
421
GrpcStorageDefaults .INSTANCE .isEnableGrpcClientMetrics ();
@@ -436,6 +439,15 @@ public static final class Builder extends StorageOptions.Builder {
436
439
this .blobWriteSessionConfig = gso .blobWriteSessionConfig ;
437
440
}
438
441
442
+ /**
443
+ * This method is obsolete. Use {@link #setTerminationAwaitJavaTimeDuration(java.time.Duration)}
444
+ * instead.
445
+ */
446
+ @ ObsoleteApi ("Use setTerminationAwaitJavaTimeDuration(java.time.Duration) instead" )
447
+ public Builder setTerminationAwaitDuration (org .threeten .bp .Duration terminationAwaitDuration ) {
448
+ return setTerminationAwaitJavaTimeDuration (toJavaTimeDuration (terminationAwaitDuration ));
449
+ }
450
+
439
451
/**
440
452
* Set the maximum duration in which to await termination of any outstanding requests when
441
453
* calling {@link Storage#close()}
@@ -444,7 +456,8 @@ public static final class Builder extends StorageOptions.Builder {
444
456
* @return the builder
445
457
* @since 2.14.0
446
458
*/
447
- public Builder setTerminationAwaitDuration (Duration terminationAwaitDuration ) {
459
+ public Builder setTerminationAwaitJavaTimeDuration (
460
+ java .time .Duration terminationAwaitDuration ) {
448
461
this .terminationAwaitDuration =
449
462
requireNonNull (terminationAwaitDuration , "terminationAwaitDuration must be non null" );
450
463
return this ;
@@ -652,9 +665,15 @@ public StorageRetryStrategy getStorageRetryStrategy() {
652
665
return StorageRetryStrategy .getDefaultStorageRetryStrategy ();
653
666
}
654
667
668
+ /** This method is obsolete. Use {@link #getTerminationAwaitDurationJavaTime()} instead. */
669
+ @ ObsoleteApi ("Use getTerminationAwaitDurationJavaTime() instead" )
670
+ public org .threeten .bp .Duration getTerminationAwaitDuration () {
671
+ return toThreetenDuration (getTerminationAwaitDurationJavaTime ());
672
+ }
673
+
655
674
/** @since 2.14.0 */
656
- public Duration getTerminationAwaitDuration () {
657
- return Duration .ofMinutes (1 );
675
+ public java . time . Duration getTerminationAwaitDurationJavaTime () {
676
+ return java . time . Duration .ofMinutes (1 );
658
677
}
659
678
660
679
/** @since 2.14.0 */
0 commit comments