- Add the Codota plugin to your IDE and get smart completions
private void myMethod () {StringBuilder s =
new StringBuilder()
new StringBuilder(32)
String str;new StringBuilder(str)
- Smart code suggestions by Codota
}
@Override public void run(SourceContext<Row> ctx) throws Exception { long offsetMS = offsetSeconds * 2000L; while (ms < durationMs) { synchronized (ctx.getCheckpointLock()) { for (int i = 0; i < numKeys; i++) { ctx.collect(Row.of(i, ms + offsetMS, "Some payload...")); } ms += sleepMs; } Thread.sleep(sleepMs); } }
@Override public void run(SourceContext<Integer> ctx) throws Exception { for (int i = 0; i < numWatermarks; i++) { ctx.collectWithTimestamp(i, initialTime + i); ctx.emitWatermark(new Watermark(initialTime + i)); } while (running) { Thread.sleep(20); } }
@Override public void run(SourceContext<Tuple2<String, Integer>> ctx) { ctx.collectWithTimestamp(Tuple2.of("key", 5), 5L); ctx.collectWithTimestamp(Tuple2.of("key", 1), 1L); ctx.collectWithTimestamp(Tuple2.of("key", 4), 4L); ctx.collectWithTimestamp(Tuple2.of("key", 3), 3L); ctx.collectWithTimestamp(Tuple2.of("key", 2), 2L); ctx.emitWatermark(new Watermark(5)); ctx.collectWithTimestamp(Tuple2.of("key", 9), 9L); ctx.collectWithTimestamp(Tuple2.of("key", 8), 8L); ctx.collectWithTimestamp(Tuple2.of("key", 7), 7L); ctx.collectWithTimestamp(Tuple2.of("key", 6), 6L); }
public void close() { this.shouldClose = true; } }
@Override public void run(SourceContext<Tuple2<String, Integer>> ctx) { ctx.collectWithTimestamp(Tuple2.of("key", 2), 2L); ctx.collectWithTimestamp(Tuple2.of("key", 1), 1L); ctx.collectWithTimestamp(Tuple2.of("key", 3), 3L); ctx.collectWithTimestamp(Tuple2.of("key", 4), 4L); ctx.collectWithTimestamp(Tuple2.of("key", 5), 5L); ctx.emitWatermark(new Watermark(5)); ctx.collectWithTimestamp(Tuple2.of("key", 8), 8L); ctx.collectWithTimestamp(Tuple2.of("key", 7), 7L); ctx.collectWithTimestamp(Tuple2.of("key", 9), 9L); ctx.collectWithTimestamp(Tuple2.of("key", 6), 6L); }
@Override public void run(SourceContext<Tuple2<Long, Long>> ctx) throws Exception { // immediately trigger any set timers ctx.emitWatermark(new Watermark(1000)); synchronized (ctx.getCheckpointLock()) { for (long i = 0; i < numElements; i++) { ctx.collect(new Tuple2<>(i, i)); } } while (isRunning) { Thread.sleep(20); } }
@Override public void run(SourceContext<Integer> ctx) throws Exception { int index = 1; while (index <= numElements) { ctx.collectWithTimestamp(index, index); ctx.collectWithTimestamp(index - 1, index - 1); index++; ctx.emitWatermark(new Watermark(index - 2)); } // emit the final Long.MAX_VALUE watermark, do it twice and verify that // we only see one in the result ctx.emitWatermark(new Watermark(Long.MAX_VALUE)); ctx.emitWatermark(new Watermark(Long.MAX_VALUE)); }
@Override public void run(SourceContext<Tuple2<Long, Long>> ctx) throws Exception { getRuntimeContext().getAccumulator(SUCCESSFUL_RESTORE_CHECK_ACCUMULATOR).add(1); // immediately trigger any set timers ctx.emitWatermark(new Watermark(1000)); synchronized (ctx.getCheckpointLock()) { for (long i = 0; i < numElements; i++) { ctx.collect(new Tuple2<>(i, i)); } } while (isRunning) { Thread.sleep(20); } }
@Override public void run(SourceContext<Tuple2<Long, Long>> ctx) throws Exception { ctx.emitWatermark(new Watermark(0)); synchronized (ctx.getCheckpointLock()) { for (long i = 0; i < numElements; i++) { ctx.collect(new Tuple2<>(i, i)); } } // don't emit a final watermark so that we don't trigger the registered event-time // timers while (isRunning) { Thread.sleep(20); } }
@Override public void run(SourceContext<Integer> ctx) throws Exception { int index = 1; while (index <= numElements) { ctx.collectWithTimestamp(index, index); ctx.collectWithTimestamp(index - 1, index - 1); index++; ctx.emitWatermark(new Watermark(index - 2)); } // emit the final Long.MAX_VALUE watermark, do it twice and verify that // we only see one in the result ctx.emitWatermark(new Watermark(Long.MAX_VALUE)); ctx.emitWatermark(new Watermark(Long.MAX_VALUE)); }
@Override public void run(SourceContext<String> ctx) throws Exception { final Object lockingObject = ctx.getCheckpointLock(); while (isRunning && index < numElements) { char first = (char) ((index % 40) + 40); stringBuilder.setLength(0); stringBuilder.append(first); String result = randomString(stringBuilder, rnd); synchronized (lockingObject) { index += step; ctx.collect(result); } } }
@Override public void run(SourceContext<Tuple3<Integer, Integer, String>> ctx) throws Exception { int partition = getRuntimeContext().getIndexOfThisSubtask(); for (int topicId = 0; topicId < numTopics; topicId++) { for (int i = 0; i < numElements; i++) { ctx.collect(new Tuple3<>(partition, i, "topic-" + topicId)); } } }
@Override public void run(SourceContext<Integer> ctx) throws Exception { while ((start < counter || counter == -1) && isRunning) { synchronized (ctx.getCheckpointLock()) { ctx.collect(start); ++start; // loop back to 0 if (start == Integer.MAX_VALUE) { start = 0; } } Thread.sleep(10L); } }
@Override public void run(SourceContext<Tuple2<Integer, Integer>> ctx) throws Exception { while (isRunning && counter < BOUND) { int first = rnd.nextInt(BOUND / 2 - 1) + 1; int second = rnd.nextInt(BOUND / 2 - 1) + 1; ctx.collect(new Tuple2<>(first, second)); counter++; Thread.sleep(50L); } }
@Override public void run(SourceContext<Integer> ctx) throws Exception { while (running) { synchronized (ctx.getCheckpointLock()) { ctx.collect(emittedCount); } if (emittedCount < 100) { ++emittedCount; } else { emittedCount = 0; } Thread.sleep(1); } }
@Override public void run(SourceContext<String> ctx) throws InterruptedException { int cnt = getRuntimeContext().getIndexOfThisSubtask() * elementsPerPartition; int limit = cnt + elementsPerPartition; while (running && !stopProducer && cnt < limit) { ctx.collect("element-" + cnt); cnt++; Thread.sleep(10); } LOG.info("Stopping producer"); }
@Override public void run(SourceContext<Tuple2<Long, Long>> ctx) throws Exception { // immediately trigger any set timers ctx.emitWatermark(new Watermark(1000)); synchronized (ctx.getCheckpointLock()) { for (long i = 0; i < numElements; i++) { if (i % getRuntimeContext().getNumberOfParallelSubtasks() == getRuntimeContext().getIndexOfThisSubtask()) { ctx.collect(new Tuple2<>(i, i)); } } } while (isRunning) { Thread.sleep(20); } }
@Override public boolean process() throws IOException, InterruptedException { String line = reader.readLine(); ctx.collect(line); return true; } })
private void emitElementsAndWaitForCheckpoints(SourceContext<T> ctx, int checkpointsToWaitFor) throws InterruptedException { final Object lock = ctx.getCheckpointLock(); final int checkpointToAwait; synchronized (lock) { checkpointToAwait = numCheckpointsComplete + checkpointsToWaitFor; for (T t : elements) { ctx.collect(t); } } synchronized (lock) { while (running && numCheckpointsComplete < checkpointToAwait) { lock.wait(1); } } }
@Override public void run(SourceContext<T> ctx) throws Exception { while (isRunning && iterator.hasNext()) { ctx.collect(iterator.next()); } }