1616
1717package com .google .cloud .pubsub .v1 ;
1818
19+ import static com .google .api .gax .util .TimeConversionUtils .toJavaTimeDuration ;
20+
1921import com .google .api .core .AbstractApiService ;
2022import com .google .api .core .ApiClock ;
2123import com .google .api .core .ApiService ;
2224import com .google .api .core .BetaApi ;
2325import com .google .api .core .CurrentMillisClock ;
2426import com .google .api .core .InternalApi ;
27+ import com .google .api .core .ObsoleteApi ;
2528import com .google .api .gax .batching .FlowControlSettings ;
2629import com .google .api .gax .batching .FlowController ;
2730import com .google .api .gax .batching .FlowController .LimitExceededBehavior ;
5558import java .util .logging .Level ;
5659import java .util .logging .Logger ;
5760import javax .annotation .Nullable ;
58- import org .threeten .bp .Duration ;
5961
6062/**
6163 * 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
98100 private static final int MAX_INBOUND_METADATA_SIZE =
99101 4 * 1024 * 1024 ; // 4MB API maximum metadata size
100102
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 );
102106
103107 @ 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 );
106110
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 );
109114
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 );
112118
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 );
114121
115122 @ 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 );
117124
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 );
119134
120135 private static final Logger logger = Logger .getLogger (Subscriber .class .getName ());
121136
@@ -124,10 +139,10 @@ public class Subscriber extends AbstractApiService implements SubscriberInterfac
124139 private final String subscriptionName ;
125140 private final FlowControlSettings flowControlSettings ;
126141 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 ;
129144 private final boolean maxDurationPerAckExtensionDefaultUsed ;
130- private final Duration minDurationPerAckExtension ;
145+ private final java . time . Duration minDurationPerAckExtension ;
131146 private final boolean minDurationPerAckExtensionDefaultUsed ;
132147
133148 // The ExecutorProvider used to generate executors for processing messages.
@@ -490,10 +505,10 @@ public static final class Builder {
490505 private MessageReceiver receiver ;
491506 private MessageReceiverWithAckResponse receiverWithAckResponse ;
492507
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 ;
495510 private boolean minDurationPerAckExtensionDefaultUsed = true ;
496- private Duration maxDurationPerAckExtension = DEFAULT_MAX_ACK_DEADLINE_EXTENSION ;
511+ private java . time . Duration maxDurationPerAckExtension = DEFAULT_MAX_ACK_DEADLINE_EXTENSION ;
497512 private boolean maxDurationPerAckExtensionDefaultUsed = true ;
498513
499514 private boolean useLegacyFlowControl = false ;
@@ -505,7 +520,7 @@ public static final class Builder {
505520 SubscriptionAdminSettings .defaultGrpcTransportProviderBuilder ()
506521 .setMaxInboundMessageSize (MAX_INBOUND_MESSAGE_SIZE )
507522 .setMaxInboundMetadataSize (MAX_INBOUND_METADATA_SIZE )
508- .setKeepAliveTime ( Duration .ofMinutes (5 ))
523+ .setKeepAliveTimeDuration ( java . time . Duration .ofMinutes (5 ))
509524 .build ();
510525 private HeaderProvider headerProvider = new NoHeaderProvider ();
511526 private CredentialsProvider credentialsProvider =
@@ -596,6 +611,15 @@ public Builder setUseLegacyFlowControl(boolean value) {
596611 return this ;
597612 }
598613
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+
599623 /**
600624 * Set the maximum period a message ack deadline will be extended. Defaults to one hour.
601625 *
@@ -605,12 +629,22 @@ public Builder setUseLegacyFlowControl(boolean value) {
605629 *
606630 * <p>A zero duration effectively disables auto deadline extensions.
607631 */
608- public Builder setMaxAckExtensionPeriod ( Duration maxAckExtensionPeriod ) {
632+ public Builder setMaxAckExtensionPeriodDuration ( java . time . Duration maxAckExtensionPeriod ) {
609633 Preconditions .checkArgument (maxAckExtensionPeriod .toMillis () >= 0 );
610634 this .maxAckExtensionPeriod = maxAckExtensionPeriod ;
611635 return this ;
612636 }
613637
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+
614648 /**
615649 * Set the upper bound for a single mod ack extention period.
616650 *
@@ -621,7 +655,8 @@ public Builder setMaxAckExtensionPeriod(Duration maxAckExtensionPeriod) {
621655 *
622656 * <p>MaxDurationPerAckExtension configuration can be disabled by specifying a zero duration.
623657 */
624- public Builder setMaxDurationPerAckExtension (Duration maxDurationPerAckExtension ) {
658+ public Builder setMaxDurationPerAckExtensionDuration (
659+ java .time .Duration maxDurationPerAckExtension ) {
625660 // If a non-default min is set, make sure min is less than max
626661 Preconditions .checkArgument (
627662 maxDurationPerAckExtension .toMillis () >= 0
@@ -633,6 +668,16 @@ public Builder setMaxDurationPerAckExtension(Duration maxDurationPerAckExtension
633668 return this ;
634669 }
635670
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+
636681 /**
637682 * Set the lower bound for a single mod ack extention period.
638683 *
@@ -643,7 +688,8 @@ public Builder setMaxDurationPerAckExtension(Duration maxDurationPerAckExtension
643688 *
644689 * <p>MinDurationPerAckExtension configuration can be disabled by specifying a zero duration.
645690 */
646- public Builder setMinDurationPerAckExtension (Duration minDurationPerAckExtension ) {
691+ public Builder setMinDurationPerAckExtensionDuration (
692+ java .time .Duration minDurationPerAckExtension ) {
647693 // If a non-default max is set, make sure min is less than max
648694 Preconditions .checkArgument (
649695 minDurationPerAckExtension .toMillis () >= 0
0 commit comments