16
16
17
17
package com .google .cloud .pubsub .v1 ;
18
18
19
+ import static com .google .api .gax .util .TimeConversionUtils .toJavaTimeDuration ;
20
+
19
21
import com .google .api .core .AbstractApiService ;
20
22
import com .google .api .core .ApiClock ;
21
23
import com .google .api .core .ApiService ;
22
24
import com .google .api .core .BetaApi ;
23
25
import com .google .api .core .CurrentMillisClock ;
24
26
import com .google .api .core .InternalApi ;
27
+ import com .google .api .core .ObsoleteApi ;
25
28
import com .google .api .gax .batching .FlowControlSettings ;
26
29
import com .google .api .gax .batching .FlowController ;
27
30
import com .google .api .gax .batching .FlowController .LimitExceededBehavior ;
55
58
import java .util .logging .Level ;
56
59
import java .util .logging .Logger ;
57
60
import javax .annotation .Nullable ;
58
- import org .threeten .bp .Duration ;
59
61
60
62
/**
61
63
* A Cloud Pub/Sub <a href="https://cloud.google.com/pubsub/docs/subscriber">subscriber</a> that is
@@ -98,24 +100,37 @@ public class Subscriber extends AbstractApiService implements SubscriberInterfac
98
100
private static final int MAX_INBOUND_METADATA_SIZE =
99
101
4 * 1024 * 1024 ; // 4MB API maximum metadata size
100
102
101
- @ InternalApi static final Duration DEFAULT_MAX_ACK_EXTENSION_PERIOD = Duration .ofMinutes (60 );
103
+ @ InternalApi
104
+ static final java .time .Duration DEFAULT_MAX_ACK_EXTENSION_PERIOD =
105
+ java .time .Duration .ofMinutes (60 );
102
106
103
107
@ InternalApi
104
- static final Duration DEFAULT_MIN_ACK_DEADLINE_EXTENSION_EXACTLY_ONCE_DELIVERY =
105
- Duration .ofMinutes (1 );
108
+ static final java . time . Duration DEFAULT_MIN_ACK_DEADLINE_EXTENSION_EXACTLY_ONCE_DELIVERY =
109
+ java . time . Duration .ofMinutes (1 );
106
110
107
- @ InternalApi static final Duration DEFAULT_MIN_ACK_DEADLINE_EXTENSION = Duration .ofMinutes (0 );
108
- @ InternalApi static final Duration DEFAULT_MAX_ACK_DEADLINE_EXTENSION = Duration .ofSeconds (0 );
111
+ @ InternalApi
112
+ static final java .time .Duration DEFAULT_MIN_ACK_DEADLINE_EXTENSION =
113
+ java .time .Duration .ofMinutes (0 );
109
114
110
- @ InternalApi static final Duration MIN_STREAM_ACK_DEADLINE = Duration .ofSeconds (10 );
111
- @ InternalApi static final Duration MAX_STREAM_ACK_DEADLINE = Duration .ofSeconds (600 );
115
+ @ InternalApi
116
+ static final java .time .Duration DEFAULT_MAX_ACK_DEADLINE_EXTENSION =
117
+ java .time .Duration .ofSeconds (0 );
112
118
113
- @ InternalApi static final Duration STREAM_ACK_DEADLINE_DEFAULT = Duration .ofSeconds (60 );
119
+ @ InternalApi
120
+ static final java .time .Duration MIN_STREAM_ACK_DEADLINE = java .time .Duration .ofSeconds (10 );
114
121
115
122
@ InternalApi
116
- static final Duration STREAM_ACK_DEADLINE_EXACTLY_ONCE_DELIVERY_DEFAULT = Duration .ofSeconds (60 );
123
+ static final java . time . Duration MAX_STREAM_ACK_DEADLINE = java . time . Duration .ofSeconds (600 );
117
124
118
- @ InternalApi static final Duration ACK_EXPIRATION_PADDING_DEFAULT = Duration .ofSeconds (5 );
125
+ @ InternalApi
126
+ static final java .time .Duration STREAM_ACK_DEADLINE_DEFAULT = java .time .Duration .ofSeconds (60 );
127
+
128
+ @ InternalApi
129
+ static final java .time .Duration STREAM_ACK_DEADLINE_EXACTLY_ONCE_DELIVERY_DEFAULT =
130
+ java .time .Duration .ofSeconds (60 );
131
+
132
+ @ InternalApi
133
+ static final java .time .Duration ACK_EXPIRATION_PADDING_DEFAULT = java .time .Duration .ofSeconds (5 );
119
134
120
135
private static final Logger logger = Logger .getLogger (Subscriber .class .getName ());
121
136
@@ -124,10 +139,10 @@ public class Subscriber extends AbstractApiService implements SubscriberInterfac
124
139
private final String subscriptionName ;
125
140
private final FlowControlSettings flowControlSettings ;
126
141
private final boolean useLegacyFlowControl ;
127
- private final Duration maxAckExtensionPeriod ;
128
- private final Duration maxDurationPerAckExtension ;
142
+ private final java . time . Duration maxAckExtensionPeriod ;
143
+ private final java . time . Duration maxDurationPerAckExtension ;
129
144
private final boolean maxDurationPerAckExtensionDefaultUsed ;
130
- private final Duration minDurationPerAckExtension ;
145
+ private final java . time . Duration minDurationPerAckExtension ;
131
146
private final boolean minDurationPerAckExtensionDefaultUsed ;
132
147
133
148
// The ExecutorProvider used to generate executors for processing messages.
@@ -490,10 +505,10 @@ public static final class Builder {
490
505
private MessageReceiver receiver ;
491
506
private MessageReceiverWithAckResponse receiverWithAckResponse ;
492
507
493
- private Duration maxAckExtensionPeriod = DEFAULT_MAX_ACK_EXTENSION_PERIOD ;
494
- private Duration minDurationPerAckExtension = DEFAULT_MIN_ACK_DEADLINE_EXTENSION ;
508
+ private java . time . Duration maxAckExtensionPeriod = DEFAULT_MAX_ACK_EXTENSION_PERIOD ;
509
+ private java . time . Duration minDurationPerAckExtension = DEFAULT_MIN_ACK_DEADLINE_EXTENSION ;
495
510
private boolean minDurationPerAckExtensionDefaultUsed = true ;
496
- private Duration maxDurationPerAckExtension = DEFAULT_MAX_ACK_DEADLINE_EXTENSION ;
511
+ private java . time . Duration maxDurationPerAckExtension = DEFAULT_MAX_ACK_DEADLINE_EXTENSION ;
497
512
private boolean maxDurationPerAckExtensionDefaultUsed = true ;
498
513
499
514
private boolean useLegacyFlowControl = false ;
@@ -505,7 +520,7 @@ public static final class Builder {
505
520
SubscriptionAdminSettings .defaultGrpcTransportProviderBuilder ()
506
521
.setMaxInboundMessageSize (MAX_INBOUND_MESSAGE_SIZE )
507
522
.setMaxInboundMetadataSize (MAX_INBOUND_METADATA_SIZE )
508
- .setKeepAliveTime ( Duration .ofMinutes (5 ))
523
+ .setKeepAliveTimeDuration ( java . time . Duration .ofMinutes (5 ))
509
524
.build ();
510
525
private HeaderProvider headerProvider = new NoHeaderProvider ();
511
526
private CredentialsProvider credentialsProvider =
@@ -596,6 +611,15 @@ public Builder setUseLegacyFlowControl(boolean value) {
596
611
return this ;
597
612
}
598
613
614
+ /**
615
+ * This method is obsolete. Use {@link #setMaxAckExtensionPeriodDuration(java.time.Duration)}
616
+ * instead.
617
+ */
618
+ @ ObsoleteApi ("Use setMaxAckExtensionPeriodDuration(java.time.Duration) instead" )
619
+ public Builder setMaxAckExtensionPeriod (org .threeten .bp .Duration maxAckExtensionPeriod ) {
620
+ return setMaxAckExtensionPeriodDuration (toJavaTimeDuration (maxAckExtensionPeriod ));
621
+ }
622
+
599
623
/**
600
624
* Set the maximum period a message ack deadline will be extended. Defaults to one hour.
601
625
*
@@ -605,12 +629,22 @@ public Builder setUseLegacyFlowControl(boolean value) {
605
629
*
606
630
* <p>A zero duration effectively disables auto deadline extensions.
607
631
*/
608
- public Builder setMaxAckExtensionPeriod ( Duration maxAckExtensionPeriod ) {
632
+ public Builder setMaxAckExtensionPeriodDuration ( java . time . Duration maxAckExtensionPeriod ) {
609
633
Preconditions .checkArgument (maxAckExtensionPeriod .toMillis () >= 0 );
610
634
this .maxAckExtensionPeriod = maxAckExtensionPeriod ;
611
635
return this ;
612
636
}
613
637
638
+ /**
639
+ * This method is obsolete. Use {@link
640
+ * #setMaxDurationPerAckExtensionDuration(java.time.Duration)} instead.
641
+ */
642
+ @ ObsoleteApi ("Use setMaxDurationPerAckExtensionDuration(java.time.Duration) instead" )
643
+ public Builder setMaxDurationPerAckExtension (
644
+ org .threeten .bp .Duration maxDurationPerAckExtension ) {
645
+ return setMaxDurationPerAckExtensionDuration (toJavaTimeDuration (maxDurationPerAckExtension ));
646
+ }
647
+
614
648
/**
615
649
* Set the upper bound for a single mod ack extention period.
616
650
*
@@ -621,7 +655,8 @@ public Builder setMaxAckExtensionPeriod(Duration maxAckExtensionPeriod) {
621
655
*
622
656
* <p>MaxDurationPerAckExtension configuration can be disabled by specifying a zero duration.
623
657
*/
624
- public Builder setMaxDurationPerAckExtension (Duration maxDurationPerAckExtension ) {
658
+ public Builder setMaxDurationPerAckExtensionDuration (
659
+ java .time .Duration maxDurationPerAckExtension ) {
625
660
// If a non-default min is set, make sure min is less than max
626
661
Preconditions .checkArgument (
627
662
maxDurationPerAckExtension .toMillis () >= 0
@@ -633,6 +668,16 @@ public Builder setMaxDurationPerAckExtension(Duration maxDurationPerAckExtension
633
668
return this ;
634
669
}
635
670
671
+ /**
672
+ * This method is obsolete. Use {@link
673
+ * #setMinDurationPerAckExtensionDuration(java.time.Duration)} instead.
674
+ */
675
+ @ ObsoleteApi ("Use setMinDurationPerAckExtensionDuration(java.time.Duration) instead" )
676
+ public Builder setMinDurationPerAckExtension (
677
+ org .threeten .bp .Duration minDurationPerAckExtension ) {
678
+ return setMinDurationPerAckExtensionDuration (toJavaTimeDuration (minDurationPerAckExtension ));
679
+ }
680
+
636
681
/**
637
682
* Set the lower bound for a single mod ack extention period.
638
683
*
@@ -643,7 +688,8 @@ public Builder setMaxDurationPerAckExtension(Duration maxDurationPerAckExtension
643
688
*
644
689
* <p>MinDurationPerAckExtension configuration can be disabled by specifying a zero duration.
645
690
*/
646
- public Builder setMinDurationPerAckExtension (Duration minDurationPerAckExtension ) {
691
+ public Builder setMinDurationPerAckExtensionDuration (
692
+ java .time .Duration minDurationPerAckExtension ) {
647
693
// If a non-default max is set, make sure min is less than max
648
694
Preconditions .checkArgument (
649
695
minDurationPerAckExtension .toMillis () >= 0
0 commit comments