Java Code Examples for org.apache.flink.util.function.ThrowingRunnable#run()

The following examples show how to use org.apache.flink.util.function.ThrowingRunnable#run() . 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: AbstractTtlDecorator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
<SE extends Throwable, CE extends Throwable, CLE extends Throwable, V> TtlValue<V> getWrappedWithTtlCheckAndUpdate(
	SupplierWithException<TtlValue<V>, SE> getter,
	ThrowingConsumer<TtlValue<V>, CE> updater,
	ThrowingRunnable<CLE> stateClear) throws SE, CE, CLE {
	TtlValue<V> ttlValue = getter.get();
	if (ttlValue == null) {
		return null;
	} else if (expired(ttlValue)) {
		stateClear.run();
		if (!returnExpired) {
			return null;
		}
	} else if (updateTsOnRead) {
		updater.accept(rewrapWithNewTs(ttlValue));
	}
	return ttlValue;
}
 
Example 2
Source File: LambdaUtil.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Runs the given runnable with the given ClassLoader as the thread's
 * {@link Thread#setContextClassLoader(ClassLoader) context class loader}.
 *
 * <p>The method will make sure to set the context class loader of the calling thread
 * back to what it was before after the runnable completed.
 */
public static <E extends Throwable> void withContextClassLoader(
		final ClassLoader cl,
		final ThrowingRunnable<E> r) throws E {

	final Thread currentThread = Thread.currentThread();
	final ClassLoader oldClassLoader = currentThread.getContextClassLoader();

	try {
		currentThread.setContextClassLoader(cl);
		r.run();
	}
	finally {
		currentThread.setContextClassLoader(oldClassLoader);
	}
}
 
Example 3
Source File: AbstractTtlDecorator.java    From flink with Apache License 2.0 6 votes vote down vote up
<SE extends Throwable, CE extends Throwable, CLE extends Throwable, V> TtlValue<V> getWrappedWithTtlCheckAndUpdate(
	SupplierWithException<TtlValue<V>, SE> getter,
	ThrowingConsumer<TtlValue<V>, CE> updater,
	ThrowingRunnable<CLE> stateClear) throws SE, CE, CLE {
	TtlValue<V> ttlValue = getter.get();
	if (ttlValue == null) {
		return null;
	} else if (expired(ttlValue)) {
		stateClear.run();
		if (!returnExpired) {
			return null;
		}
	} else if (updateTsOnRead) {
		updater.accept(rewrapWithNewTs(ttlValue));
	}
	return ttlValue;
}
 
Example 4
Source File: AbstractTtlDecorator.java    From flink with Apache License 2.0 6 votes vote down vote up
<SE extends Throwable, CE extends Throwable, CLE extends Throwable, V> TtlValue<V> getWrappedWithTtlCheckAndUpdate(
	SupplierWithException<TtlValue<V>, SE> getter,
	ThrowingConsumer<TtlValue<V>, CE> updater,
	ThrowingRunnable<CLE> stateClear) throws SE, CE, CLE {
	TtlValue<V> ttlValue = getter.get();
	if (ttlValue == null) {
		return null;
	} else if (expired(ttlValue)) {
		stateClear.run();
		if (!returnExpired) {
			return null;
		}
	} else if (updateTsOnRead) {
		updater.accept(rewrapWithNewTs(ttlValue));
	}
	return ttlValue;
}
 
Example 5
Source File: CheckpointBarrierUnalignerCancellationTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <E extends Exception> void executeInTaskThread(
		ThrowingRunnable<E> runnable,
		String descriptionFormat,
		Object... descriptionArgs) {
	try {
		runnable.run();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example 6
Source File: CheckpointBarrierUnalignerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <E extends Exception> void executeInTaskThread(
		ThrowingRunnable<E> runnable,
		String descriptionFormat,
		Object... descriptionArgs) throws E {
	runnable.run();
}
 
Example 7
Source File: StreamTask.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <E extends Exception> void executeInTaskThread(
		ThrowingRunnable<E> runnable,
		String descriptionFormat,
		Object... descriptionArgs) throws E {
	if (mailboxProcessor.isMailboxThread()) {
		runnable.run();
	} else {
		mainMailboxExecutor.execute(runnable, descriptionFormat, descriptionArgs);
	}
}
 
Example 8
Source File: StreamTask.java    From flink with Apache License 2.0 5 votes vote down vote up
private Exception runAndSuppressThrowable(ThrowingRunnable<?> runnable, @Nullable Exception originalException) {
	try {
		runnable.run();
	} catch (Throwable t) {
		// TODO: investigate why Throwable instead of Exception is used here.
		Exception e = t instanceof Exception ? (Exception) t : new Exception(t);
		return ExceptionUtils.firstOrSuppressed(e, originalException);
	}

	return originalException;
}
 
Example 9
Source File: CoordinatorTestUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
static void verifyException(ThrowingRunnable<Throwable> runnable, String failureMessage, String errorMessage) {
	try {
		runnable.run();
		fail(failureMessage);
	} catch (Throwable t) {
		Throwable rootCause = t;
		while (rootCause.getCause() != null) {
			rootCause = rootCause.getCause();
		}
		assertThat(rootCause.getMessage(), Matchers.startsWith(errorMessage));
	}
}
 
Example 10
Source File: DummyInvokable.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <E extends Exception> void executeInTaskThread(
		ThrowingRunnable<E> runnable,
		String descriptionFormat,
		Object... descriptionArgs) throws E {
	runnable.run();
}
 
Example 11
Source File: FileSystemTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static <E extends Throwable> E assertThatCode(ThrowingRunnable<E> runnable) throws E {
	try {
		runnable.run();
		fail("No exception thrown");
		return null;
	} catch (Throwable e) {
		try {
			return (E) e;
		} catch (ClassCastException c) {
			throw e;
		}
	}
}
 
Example 12
Source File: OptionalConsumer.java    From flink with Apache License 2.0 5 votes vote down vote up
public <E extends Exception> OptionalConsumer<T> ifNotPresent(ThrowingRunnable<E> r) throws E {
	if (!optional.isPresent()) {
		r.run();
	}

	return this;
}
 
Example 13
Source File: LambdaUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Runs the given runnable with the given ClassLoader as the thread's
 * {@link Thread#setContextClassLoader(ClassLoader) context class loader}.
 *
 * <p>The method will make sure to set the context class loader of the calling thread
 * back to what it was before after the runnable completed.
 */
public static <E extends Throwable> void withContextClassLoader(
		final ClassLoader cl,
		final ThrowingRunnable<E> r) throws E {

	try (TemporaryClassLoaderContext ignored = TemporaryClassLoaderContext.of(cl)) {
		r.run();
	}
}
 
Example 14
Source File: LambdaUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Runs the given runnable with the given ClassLoader as the thread's
 * {@link Thread#setContextClassLoader(ClassLoader) context class loader}.
 *
 * <p>The method will make sure to set the context class loader of the calling thread
 * back to what it was before after the runnable completed.
 */
public static <E extends Throwable> void withContextClassLoader(
		final ClassLoader cl,
		final ThrowingRunnable<E> r) throws E {

	try (TemporaryClassLoaderContext tmpCl = new TemporaryClassLoaderContext(cl)) {
		r.run();
	}
}
 
Example 15
Source File: StreamTaskActionExecutor.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public <E extends Throwable> void runThrowing(ThrowingRunnable<E> runnable) throws E {
	runnable.run();
}
 
Example 16
Source File: StreamTaskActionExecutor.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public <E extends Throwable> void runThrowing(ThrowingRunnable<E> runnable) throws E {
	synchronized (mutex) {
		runnable.run();
	}
}
 
Example 17
Source File: StreamTaskExecutionDecorationTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public <E extends Throwable> void runThrowing(ThrowingRunnable<E> runnable) throws E {
	calls.incrementAndGet();
	runnable.run();
}
 
Example 18
Source File: AlternatingCheckpointBarrierHandlerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public <E extends Exception> void executeInTaskThread(ThrowingRunnable<E> runnable, String descriptionFormat, Object... descriptionArgs) throws E {
	runnable.run();
}