Java Code Examples for org.apache.flink.util.function.SupplierWithException#get()

The following examples show how to use org.apache.flink.util.function.SupplierWithException#get() . 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 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: 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 3
Source File: HandlerRequestUtils.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Returns {@code requestValue} if it is not null, otherwise returns the query parameter value
 * if it is not null, otherwise returns the default value.
 */
public static <T> T fromRequestBodyOrQueryParameter(
		T requestValue,
		SupplierWithException<T, RestHandlerException> queryParameterExtractor,
		T defaultValue,
		Logger log) throws RestHandlerException {
	if (requestValue != null) {
		return requestValue;
	} else {
		T queryParameterValue = queryParameterExtractor.get();
		if (queryParameterValue != null) {
			log.warn("Configuring the job submission via query parameters is deprecated." +
				" Please migrate to submitting a JSON request instead.");
			return queryParameterValue;
		} else {
			return defaultValue;
		}
	}
}
 
Example 4
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 <R, E extends Throwable> R withContextClassLoader(
		final ClassLoader cl,
		final SupplierWithException<R, E> s) throws E {

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

	try {
		currentThread.setContextClassLoader(cl);
		return s.get();
	}
	finally {
		currentThread.setContextClassLoader(oldClassLoader);
	}
}
 
Example 5
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 6
Source File: HandlerRequestUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Returns {@code requestValue} if it is not null, otherwise returns the query parameter value
 * if it is not null, otherwise returns the default value.
 */
public static <T> T fromRequestBodyOrQueryParameter(
		T requestValue,
		SupplierWithException<T, RestHandlerException> queryParameterExtractor,
		T defaultValue,
		Logger log) throws RestHandlerException {
	if (requestValue != null) {
		return requestValue;
	} else {
		T queryParameterValue = queryParameterExtractor.get();
		if (queryParameterValue != null) {
			log.warn("Configuring the job submission via query parameters is deprecated." +
				" Please migrate to submitting a JSON request instead.");
			return queryParameterValue;
		} else {
			return defaultValue;
		}
	}
}
 
Example 7
Source File: TtlStateFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private IS createState() throws Exception {
	SupplierWithException<IS, Exception> stateFactory = stateFactories.get(stateDesc.getClass());
	if (stateFactory == null) {
		String message = String.format("State %s is not supported by %s",
			stateDesc.getClass(), TtlStateFactory.class);
		throw new FlinkRuntimeException(message);
	}
	IS state = stateFactory.get();
	if (incrementalCleanup != null) {
		incrementalCleanup.setTtlState((AbstractTtlState<K, N, ?, TTLSV, ?>) state);
	}
	return state;
}
 
Example 8
Source File: TtlStateFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private IS createState() throws Exception {
	SupplierWithException<IS, Exception> stateFactory = stateFactories.get(stateDesc.getClass());
	if (stateFactory == null) {
		String message = String.format("State %s is not supported by %s",
			stateDesc.getClass(), TtlStateFactory.class);
		throw new FlinkRuntimeException(message);
	}
	IS state = stateFactory.get();
	if (incrementalCleanup != null) {
		incrementalCleanup.setTtlState((AbstractTtlState<K, N, ?, TTLSV, ?>) state);
	}
	return state;
}
 
Example 9
Source File: DefaultJobTable.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <E extends Exception> Job getOrCreateJob(JobID jobId, SupplierWithException<? extends JobTable.JobServices, E> jobServicesSupplier) throws E {
	JobOrConnection job = jobs.get(jobId);

	if (job == null) {
		job = new JobOrConnection(jobId, jobServicesSupplier.get());
		jobs.put(jobId, job);
	}

	return job;
}
 
Example 10
Source File: LimitedConnectionsFileSystem.java    From flink with Apache License 2.0 5 votes vote down vote up
private FSDataInputStream createInputStream(
		final SupplierWithException<FSDataInputStream, IOException> streamOpener) throws IOException {

	final SupplierWithException<InStream, IOException> wrappedStreamOpener =
			() -> new InStream(streamOpener.get(), this);

	return createStream(wrappedStreamOpener, openInputStreams, false);
}
 
Example 11
Source File: LimitedConnectionsFileSystem.java    From flink with Apache License 2.0 5 votes vote down vote up
private FSDataOutputStream createOutputStream(
		final SupplierWithException<FSDataOutputStream, IOException> streamOpener) throws IOException {

	final SupplierWithException<OutStream, IOException> wrappedStreamOpener =
			() -> new OutStream(streamOpener.get(), this);

	return createStream(wrappedStreamOpener, openOutputStreams, true);
}
 
Example 12
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 <R, E extends Throwable> R withContextClassLoader(
		final ClassLoader cl,
		final SupplierWithException<R, E> s) throws E {

	try (TemporaryClassLoaderContext ignored = TemporaryClassLoaderContext.of(cl)) {
		return s.get();
	}
}
 
Example 13
Source File: CommonTestUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static void waitUntilCondition(SupplierWithException<Boolean, Exception> condition, Deadline timeout, long retryIntervalMillis) throws Exception {
	while (timeout.hasTimeLeft() && !condition.get()) {
		final long timeLeft = Math.max(0, timeout.timeLeft().toMillis());
		Thread.sleep(Math.min(retryIntervalMillis, timeLeft));
	}

	if (!timeout.hasTimeLeft()) {
		throw new TimeoutException("Condition was not met in given timeout.");
	}
}
 
Example 14
Source File: LimitedConnectionsFileSystem.java    From flink with Apache License 2.0 5 votes vote down vote up
private FSDataInputStream createInputStream(
		final SupplierWithException<FSDataInputStream, IOException> streamOpener) throws IOException {

	final SupplierWithException<InStream, IOException> wrappedStreamOpener =
			() -> new InStream(streamOpener.get(), this);

	return createStream(wrappedStreamOpener, openInputStreams, false);
}
 
Example 15
Source File: LimitedConnectionsFileSystem.java    From flink with Apache License 2.0 5 votes vote down vote up
private FSDataOutputStream createOutputStream(
		final SupplierWithException<FSDataOutputStream, IOException> streamOpener) throws IOException {

	final SupplierWithException<OutStream, IOException> wrappedStreamOpener =
			() -> new OutStream(streamOpener.get(), this);

	return createStream(wrappedStreamOpener, openOutputStreams, true);
}
 
Example 16
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 <R, E extends Throwable> R withContextClassLoader(
		final ClassLoader cl,
		final SupplierWithException<R, E> s) throws E {

	try (TemporaryClassLoaderContext tmpCl = new TemporaryClassLoaderContext(cl)) {
		return s.get();
	}
}
 
Example 17
Source File: CommonTestUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public static void waitUntilCondition(SupplierWithException<Boolean, Exception> condition, Deadline timeout, long retryIntervalMillis) throws Exception {
	while (timeout.hasTimeLeft() && !condition.get()) {
		Thread.sleep(Math.min(retryIntervalMillis, timeout.timeLeft().toMillis()));
	}

	if (!timeout.hasTimeLeft()) {
		throw new TimeoutException("Condition was not met in given timeout.");
	}
}
 
Example 18
Source File: TtlStateFactory.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private IS createState() throws Exception {
	SupplierWithException<IS, Exception> stateFactory = stateFactories.get(stateDesc.getClass());
	if (stateFactory == null) {
		String message = String.format("State %s is not supported by %s",
			stateDesc.getClass(), TtlStateFactory.class);
		throw new FlinkRuntimeException(message);
	}
	IS state = stateFactory.get();
	if (incrementalCleanup != null) {
		incrementalCleanup.setTtlState((AbstractTtlState<K, N, ?, TTLSV, ?>) state);
	}
	return state;
}
 
Example 19
Source File: LimitedConnectionsFileSystem.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private FSDataInputStream createInputStream(
		final SupplierWithException<FSDataInputStream, IOException> streamOpener) throws IOException {

	final SupplierWithException<InStream, IOException> wrappedStreamOpener =
			() -> new InStream(streamOpener.get(), this);

	return createStream(wrappedStreamOpener, openInputStreams, false);
}
 
Example 20
Source File: LimitedConnectionsFileSystem.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private FSDataOutputStream createOutputStream(
		final SupplierWithException<FSDataOutputStream, IOException> streamOpener) throws IOException {

	final SupplierWithException<OutStream, IOException> wrappedStreamOpener =
			() -> new OutStream(streamOpener.get(), this);

	return createStream(wrappedStreamOpener, openOutputStreams, true);
}