Codota Logo
SourceFunction$SourceContext
Code IndexAdd Codota to your IDE (free)

How to use
SourceFunction$SourceContext
in
org.apache.flink.streaming.api.functions.source

Best Java code snippets using org.apache.flink.streaming.api.functions.source.SourceFunction$SourceContext (Showing top 20 results out of 540)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
StringBuilder s =
  • Codota Iconnew StringBuilder()
  • Codota Iconnew StringBuilder(32)
  • Codota IconString str;new StringBuilder(str)
  • Smart code suggestions by Codota
}
origin: apache/flink

@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);
  }
}
origin: apache/flink

@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);
  }
}
origin: apache/flink

@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);
}
origin: apache/flink

  public void close() {
    this.shouldClose = true;
  }
}
origin: apache/flink

@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);
}
origin: apache/flink

@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);
  }
}
origin: apache/flink

@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));
}
origin: apache/flink

@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);
  }
}
origin: apache/flink

@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);
  }
}
origin: apache/flink

@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));
}
origin: apache/flink

@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);
    }
  }
}
origin: apache/flink

@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));
    }
  }
}
origin: apache/flink

@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);
  }
}
origin: apache/flink

@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);
  }
}
origin: apache/flink

@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);
  }
}
origin: apache/flink

@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");
}
origin: apache/flink

@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);
  }
}
origin: apache/flink

  @Override
  public boolean process() throws IOException, InterruptedException {
    String line = reader.readLine();
    ctx.collect(line);
    return true;
  }
})
origin: apache/flink

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);
    }
  }
}
origin: apache/flink

@Override
public void run(SourceContext<T> ctx) throws Exception {
  while (isRunning && iterator.hasNext()) {
    ctx.collect(iterator.next());
  }
}
org.apache.flink.streaming.api.functions.sourceSourceFunction$SourceContext

Javadoc

Interface that source functions use to emit elements, and possibly watermarks.

Most used methods

  • collect
    Emits one element from the source, without attaching a timestamp. In most cases, this is the default
  • getCheckpointLock
    Returns the checkpoint lock. Please refer to the class-level comment in SourceFunction for details a
  • emitWatermark
    Emits the given Watermark. A Watermark of value t declares that no elements with a timestamp t' late
  • collectWithTimestamp
    Emits one element from the source, and attaches the given timestamp. This method is relevant for pro
  • close
    This method is called by the system to shut down the context.
  • markAsTemporarilyIdle
    Marks the source to be temporarily idle. This tells the system that this source will temporarily sto

Popular in Java

  • Making http requests using okhttp
  • compareTo (BigDecimal)
  • scheduleAtFixedRate (Timer)
    Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.
  • getApplicationContext (Context)
  • InputStreamReader (java.io)
    An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • JTable (javax.swing)
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now