yanghua commented on a change in pull request #6594: [FLINK-9311] [pubsub] 
Added PubSub source connector with support for checkpointing (ATLEAST_ONCE)
URL: https://github.com/apache/flink/pull/6594#discussion_r211664202
 
 

 ##########
 File path: 
flink-connectors/flink-connector-pubsub/src/main/java/org/apache/flink/streaming/connectors/pubsub/BoundedPubSubSource.java
 ##########
 @@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.connectors.pubsub;
+
+import com.google.cloud.pubsub.v1.AckReplyConsumer;
+import com.google.pubsub.v1.PubsubMessage;
+
+import java.io.IOException;
+
+/**
+ * A bounded PubSub Source, similar to {@link PubSubSource} but this will stop 
at some point. For example after a period of idle or and after n amount of 
messages have been received.
+ *
+ */
+public class BoundedPubSubSource<OUT> extends PubSubSource<OUT> {
+       private Bound<OUT> bound;
+
+       private BoundedPubSubSource() {
+               super();
+       }
+
+       protected void setBound(Bound<OUT> bound) {
+               this.bound = bound;
+       }
+
+       @Override
+       public void run(SourceContext<OUT> sourceContext) {
+               bound.start(this);
+               super.run(sourceContext);
+       }
+
+       @Override
+       public void receiveMessage(PubsubMessage message, AckReplyConsumer 
consumer) {
+               super.receiveMessage(message, consumer);
+               bound.receivedMessage();
+       }
+
+       /**
+        * Creates a {@link BoundedPubSubSourceBuilder}.
+        * @param <OUT> Type of Object which will be read by the produced 
{@link BoundedPubSubSource}
+        */
+       @SuppressWarnings("unchecked")
+       public static <OUT> BoundedPubSubSourceBuilder<OUT, ? extends 
PubSubSource, ? extends BoundedPubSubSourceBuilder> newBuilder() {
+               return new BoundedPubSubSourceBuilder<>(new 
BoundedPubSubSource<OUT>());
+       }
+
+       /**
+        * Builder to create BoundedPubSubSource.
+        * @param <OUT> Type of Object which will be read by the 
BoundedPubSubSource
+        */
+       @SuppressWarnings("unchecked")
+       public static class BoundedPubSubSourceBuilder<OUT, PSS extends 
BoundedPubSubSource<OUT>, BUILDER extends BoundedPubSubSourceBuilder<OUT, PSS, 
BUILDER>> extends PubSubSourceBuilder<OUT, PSS, BUILDER> {
 
 Review comment:
   Too long

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to