@Override public void run(SourceContext<T> ctx) throws Exception { while (isRunning && iterator.hasNext()) { ctx.collect(iterator.next()); } }
@Override public void run(SourceContext<Object> ctx) throws Exception { try { while (isRunning && this.fun.hasNext()) { ctx.collect(this.fun.next()); } } catch (PyException pe) { throw AbstractPythonUDF.createAndLogException(pe, LOG); } }
@Override public void run(SourceContext<Long> ctx) throws Exception { while (isRunning && !this.valuesToEmit.isEmpty()) { synchronized (ctx.getCheckpointLock()) { ctx.collect(this.valuesToEmit.poll()); } } }
@Override public void run(SourceContext<Integer> ctx) throws Exception { while (!cancel) { synchronized (ctx.getCheckpointLock()) { ctx.collect(1); } Thread.sleep(100L); } }
@Override public void emitEvent(SourceFunction.SourceContext<Tuple2<Long, IntType>> ctx, int eventSequenceNo) { ctx.collect(new Tuple2<>((long) eventSequenceNo, new IntType(eventSequenceNo))); } }
@Override public void run(SourceContext<Integer> collector) throws Exception { while (counter < 8200) { collector.collect(getTrainingData()); } }
@Override public void run(SourceContext<Tuple2<Integer, Integer>> ctx) throws Exception { int cnt = 0; int partition = getRuntimeContext().getIndexOfThisSubtask(); while (running && cnt < numElements) { ctx.collect(new Tuple2<>(partition, cnt)); cnt++; } }
@Override public void run(SourceContext<Tuple2<String, Integer>> out) throws Exception { Random random = new Random(42); while (running) { Tuple2<String, Integer> tuple = new Tuple2<String, Integer>("Tuple " + (random.nextInt(numKeys)), 1); out.collect(tuple); } }
@Override public void run(SourceContext<Tuple3<String, String, Integer>> ctx) throws Exception { ctx.collect(Tuple3.of("a", "x", 0)); ctx.collect(Tuple3.of("a", "y", 1)); ctx.collect(Tuple3.of("a", "z", 2)); ctx.collect(Tuple3.of("b", "u", 3)); ctx.collect(Tuple3.of("b", "w", 5)); ctx.collect(Tuple3.of("a", "i", 6)); ctx.collect(Tuple3.of("a", "j", 7)); ctx.collect(Tuple3.of("a", "k", 8)); // source is finite, so it will have an implicit MAX watermark when it finishes }
@Override public void run(SourceContext<Tuple3<String, String, Integer>> ctx) throws Exception { ctx.collect(Tuple3.of("a", "u", 0)); ctx.collect(Tuple3.of("a", "w", 1)); ctx.collect(Tuple3.of("b", "i", 3)); ctx.collect(Tuple3.of("b", "k", 5)); ctx.collect(Tuple3.of("a", "x", 6)); ctx.collect(Tuple3.of("a", "z", 8)); // source is finite, so it will have an implicit MAX watermark when it finishes }
@Override public void run(SourceContext<Tuple3<String, String, Integer>> ctx) throws Exception { ctx.collect(Tuple3.of("a", "x", 0)); ctx.collect(Tuple3.of("a", "y", 1)); ctx.collect(Tuple3.of("a", "z", 2)); ctx.collect(Tuple3.of("b", "u", 3)); ctx.collect(Tuple3.of("b", "w", 5)); ctx.collect(Tuple3.of("a", "i", 6)); ctx.collect(Tuple3.of("a", "j", 7)); ctx.collect(Tuple3.of("a", "k", 8)); // source is finite, so it will have an implicit MAX watermark when it finishes }
@Override public void run(SourceContext<Tuple2<String, Integer>> ctx) throws Exception { ctx.collect(Tuple2.of("a", 0)); ctx.collect(Tuple2.of("a", 1)); ctx.collect(Tuple2.of("b", 3)); ctx.collect(Tuple2.of("c", 6)); ctx.collect(Tuple2.of("c", 7)); ctx.collect(Tuple2.of("c", 8)); // source is finite, so it will have an implicit MAX watermark when it finishes }
@Override public void run(SourceContext<String> ctx) throws Exception { if (!openCalled) { Assert.fail("Open was not called before run."); } for (int i = 0; i < 10; i++) { ctx.collect("Hello" + i); } }
@Override public void run(SourceContext<Tuple2<Integer, Long>> ctx) throws Exception { Object lock = ctx.getCheckpointLock(); while (count < NUM_INPUT){ synchronized (lock){ for (int i = 0; i < PARALLELISM; i++) { ctx.collect(Tuple2.of(i, count + 1)); } count++; } } }
@Override public void run(SourceContext<String> ctx) throws Exception { while (running && !CheckpointBlockingFunction.afterMessWithZooKeeper.get()) { ctx.collect("hello"); // don't overdo it ... ;-) Thread.sleep(50); } }
@Override public void run(SourceContext<Integer> ctx) throws Exception { Thread.sleep(15); while (counter < 50) { ctx.collect(getNewData()); } }
@Override public void run(SourceContext<Tuple2<Long, String>> ctx) throws InterruptedException { int cnt = getRuntimeContext().getIndexOfThisSubtask() * elementsPerPartition; int limit = cnt + elementsPerPartition; while (running && cnt < limit) { ctx.collect(new Tuple2<>(1000L + cnt, "kafka-" + cnt)); cnt++; // we delay data generation a bit so that we are sure that some checkpoints are // triggered (for FLINK-3156) Thread.sleep(50); } }
@Override public void run(SourceContext<Tuple2<Integer, Integer>> out) throws Exception { Random random = new Random(42); while (--remainingEvents >= 0) { synchronized (out.getCheckpointLock()) { out.collect(new Tuple2<>(random.nextInt(numKeys), 1)); } } }
@Override public void run(SourceContext<String> ctx) throws Exception { while (isRunning) { if (readyToFail && getRuntimeContext().getIndexOfThisSubtask() == 0) { throw new Exception("Artificial failure."); } synchronized (ctx.getCheckpointLock()) { ctx.collect("test-element"); } Thread.sleep(1); } }
@Override public void run(SourceContext<Tuple3<Integer, Long, String>> ctx) throws Exception { while (ms < durationMs) { synchronized (ctx.getCheckpointLock()) { for (int i = 0; i < numKeys; i++) { ctx.collect(Tuple3.of(i, ms, "Some payload...")); } ms += idlenessMs; } Thread.sleep(idlenessMs); } }