1717package com .google .cloud .pubsublite .beam ;
1818
1919import com .google .auto .value .AutoValue ;
20- import com .google .cloud .pubsublite .AdminClient ;
21- import com .google .cloud .pubsublite .AdminClientSettings ;
2220import com .google .cloud .pubsublite .Partition ;
2321import com .google .cloud .pubsublite .PartitionLookupUtils ;
2422import com .google .cloud .pubsublite .SubscriptionPath ;
25- import com .google .cloud .pubsublite .TopicPath ;
2623import com .google .cloud .pubsublite .cloudpubsub .FlowControlSettings ;
27- import com .google .cloud .pubsublite .internal .ExtractStatus ;
28- import com .google .cloud .pubsublite .internal .TopicStatsClient ;
29- import com .google .cloud .pubsublite .internal .TopicStatsClientSettings ;
3024import com .google .cloud .pubsublite .internal .wire .Committer ;
3125import com .google .cloud .pubsublite .internal .wire .CommitterBuilder ;
3226import com .google .cloud .pubsublite .internal .wire .PubsubContext ;
4034import com .google .common .collect .ImmutableSet ;
4135import io .grpc .StatusException ;
4236import java .io .Serializable ;
43- import java .util .concurrent .ExecutionException ;
4437
4538@ AutoValue
4639public abstract class SubscriberOptions implements Serializable {
@@ -57,8 +50,8 @@ public abstract class SubscriberOptions implements Serializable {
5750 /** A set of partitions. If empty, retrieve the set of partitions using an admin client. */
5851 public abstract ImmutableSet <Partition > partitions ();
5952
60- /** The class used to read backlog for the subscription described by subscriptionPath() */
61- public abstract TopicBacklogReader topicBacklogReader ();
53+ /** The class used to read backlog for the subscription described by subscriptionPath(). */
54+ public abstract TopicBacklogReaderSettings topicBacklogReaderSettings ();
6255
6356 /** A supplier for the subscriber stub to be used. */
6457 public abstract Optional <SerializableSupplier <SubscriberServiceStub >> subscriberStubSupplier ();
@@ -143,7 +136,8 @@ public abstract Builder setSubscriberStubSupplier(
143136 public abstract Builder setCommitterStubSupplier (
144137 SerializableSupplier <CursorServiceStub > stubSupplier );
145138
146- public abstract Builder setTopicBacklogReader (TopicBacklogReader topicBacklogReader );
139+ public abstract Builder setTopicBacklogReaderSettings (
140+ TopicBacklogReaderSettings topicBacklogReaderSettings );
147141
148142 // Used in unit tests
149143 abstract Builder setSubscriberFactory (SubscriberFactory subscriberFactory );
@@ -155,41 +149,29 @@ public abstract Builder setCommitterStubSupplier(
155149
156150 abstract ImmutableSet <Partition > partitions ();
157151
158- abstract Optional <TopicBacklogReader > topicBacklogReader ();
152+ abstract Optional <TopicBacklogReaderSettings > topicBacklogReaderSettings ();
159153
160154 abstract SubscriberOptions autoBuild ();
161155
162156 public SubscriberOptions build () throws StatusException {
163- if (!partitions ().isEmpty () && topicBacklogReader ().isPresent ()) {
157+ if (!partitions ().isEmpty () && topicBacklogReaderSettings ().isPresent ()) {
164158 return autoBuild ();
165159 }
166- TopicPath path ;
167- try (AdminClient adminClient =
168- AdminClient .create (
169- AdminClientSettings .newBuilder ()
170- .setRegion (subscriptionPath ().location ().region ())
171- .build ())) {
172- path = TopicPath .parse (adminClient .getSubscription (subscriptionPath ()).get ().getTopic ());
173- } catch (ExecutionException e ) {
174- throw ExtractStatus .toCanonical (e .getCause ());
175- } catch (Throwable t ) {
176- throw ExtractStatus .toCanonical (t );
177- }
178160
179161 if (partitions ().isEmpty ()) {
180- int partition_count = PartitionLookupUtils .numPartitions (path );
162+ int partitionCount = PartitionLookupUtils .numPartitions (subscriptionPath () );
181163 ImmutableSet .Builder <Partition > partitions = ImmutableSet .builder ();
182- for (int i = 0 ; i < partition_count ; i ++) {
164+ for (int i = 0 ; i < partitionCount ; i ++) {
183165 partitions .add (Partition .of (i ));
184166 }
185167 setPartitions (partitions .build ());
186168 }
187- if (!topicBacklogReader ().isPresent ()) {
188- setTopicBacklogReader (
189- new TopicBacklogReaderImpl (
190- TopicStatsClient .create (TopicStatsClientSettings .newBuilder ().build ()), path ));
169+ if (!topicBacklogReaderSettings ().isPresent ()) {
170+ setTopicBacklogReaderSettings (
171+ TopicBacklogReaderSettings .newBuilder ()
172+ .setTopicPathFromSubscriptionPath (subscriptionPath ())
173+ .build ());
191174 }
192-
193175 return autoBuild ();
194176 }
195177 }
0 commit comments