You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/05/11 06:25:38 UTC

[GitHub] [flink] JingsongLi commented on a change in pull request #11496: [FLINK-16743][table] Introduce datagen, print, blackhole connectors

JingsongLi commented on a change in pull request #11496:
URL: https://github.com/apache/flink/pull/11496#discussion_r422808127



##########
File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/source/datagen/DataGeneratorSource.java
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.api.functions.source.datagen;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.runtime.state.FunctionInitializationContext;
+import org.apache.flink.runtime.state.FunctionSnapshotContext;
+import org.apache.flink.streaming.api.checkpoint.CheckpointedFunction;
+import org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction;
+
+/**
+ * A data generator source that abstract data generator. It can used to easy startup/test
+ * for streaming job and performance testing.
+ * It is stateful, re-scalable, possibly in parallel.
+ */
+@Experimental
+public class DataGeneratorSource<T> extends RichParallelSourceFunction<T> implements CheckpointedFunction {
+
+	private static final long serialVersionUID = 1L;
+
+	private final DataGenerator<T> generator;
+	private final long rowsPerSecond;
+
+	transient volatile boolean isRunning;
+
+	/**
+	 * Creates a source that emits records by {@link DataGenerator} without controlling emit rate.
+	 *
+	 * @param generator data generator.
+	 */
+	public DataGeneratorSource(DataGenerator<T> generator) {
+		this(generator, Long.MAX_VALUE);
+	}
+
+	/**
+	 * Creates a source that emits records by {@link DataGenerator}.
+	 *
+	 * @param generator data generator.
+	 * @param rowsPerSecond Control the emit rate.
+	 */
+	public DataGeneratorSource(DataGenerator<T> generator, long rowsPerSecond) {
+		this.generator = generator;
+		this.rowsPerSecond = rowsPerSecond;
+	}
+
+	@Override
+	public void initializeState(FunctionInitializationContext context) throws Exception {
+		this.generator.open("TOP_FIELD", context, getRuntimeContext());

Review comment:
       This is just name for generator, I will change to "DataGenerator".




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org