Java Code Examples for org.apache.flink.streaming.api.environment.StreamExecutionEnvironment#executeAsync()

The following examples show how to use org.apache.flink.streaming.api.environment.StreamExecutionEnvironment#executeAsync() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File:    From flink with Apache License 2.0 6 votes vote down vote up
public void testExecuteAsyncCallsJobListenerOnMainThreadOnStreamEnvironment() throws Exception {
	AtomicReference<Thread> threadReference = new AtomicReference<>();

	StreamExecutionEnvironment env = new StreamExecutionEnvironment(getClientConfiguration());

	env.registerJobListener(new JobListener() {
		public void onJobSubmitted(JobClient jobClient, Throwable t) {

		public void onJobExecuted(JobExecutionResult jobExecutionResult, Throwable throwable) {

	env.fromElements(1, 2, 3, 4, 5).addSink(new DiscardingSink<>());

	assertThat(Thread.currentThread(), is(threadReference.get()));
Example 2
Source File:    From flink with Apache License 2.0 6 votes vote down vote up
 * Returns an iterator to iterate over the elements of the DataStream.
 * @return The iterator
public static <OUT> Iterator<OUT> collect(DataStream<OUT> stream) {
	TypeSerializer<OUT> serializer = stream.getType().createSerializer(
	String accumulatorName = "dataStreamCollect_" + UUID.randomUUID().toString();

	CollectSinkOperatorFactory<OUT> factory = new CollectSinkOperatorFactory<>(serializer, accumulatorName);
	CollectSinkOperator<OUT> operator = (CollectSinkOperator<OUT>) factory.getOperator();
	CollectResultIterator<OUT> iterator = new CollectResultIterator<>(
		operator.getOperatorIdFuture(), serializer, accumulatorName);
	CollectStreamSink<OUT> sink = new CollectStreamSink<>(stream, factory);"Data stream collect sink");

	StreamExecutionEnvironment env = stream.getExecutionEnvironment();

	try {
		JobClient jobClient = env.executeAsync("Data Stream Collect");
	} catch (Exception e) {
		throw new RuntimeException("Failed to execute data stream", e);

	return iterator;
Example 3
Source File:    From flink with Apache License 2.0 4 votes vote down vote up
private static JobClient submitJobInitially(StreamExecutionEnvironment env) throws Exception {
	return env.executeAsync(dag(FIRST_RUN_EL_COUNT, true, FIRST_RUN_BACKPRESSURE_MS, env));