@Override @SuppressWarnings("unchecked") protected AbstractFetcher<T, ?> createFetcher( SourceContext<T> sourceContext, Map<KafkaTopicPartition, Long> thisSubtaskPartitionsWithStartOffsets, SerializedValue<AssignerWithPeriodicWatermarks<T>> watermarksPeriodic, SerializedValue<AssignerWithPunctuatedWatermarks<T>> watermarksPunctuated, StreamingRuntimeContext runtimeContext, OffsetCommitMode offsetCommitMode, MetricGroup consumerMetricGroup, boolean useMetrics) throws Exception { return testFetcherSupplier.get(); }
/** * 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); } } }
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); }
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); }
final T out = streamOpener.get();
protected static void waitUntilCondition(SupplierWithException<Boolean, Exception> condition, Deadline timeout) throws Exception { while (timeout.hasTimeLeft() && !condition.get()) { Thread.sleep(Math.min(RETRY_TIMEOUT, timeout.timeLeft().toMillis())); } if (!timeout.hasTimeLeft()) { throw new TimeoutException("Condition was not met in given timeout."); } }
private T attemptCreateAndRestore(Collection<S> restoreState) throws Exception { final T backendInstance = instanceSupplier.get();
OperatorStateBackend originalBackend = backendSupplier.get(); SnapshotResult<OperatorStateHandle> snapshotResult;
/** * 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; } } } }
/** * 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; } } } }
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); } return stateFactory.get(); }
@Override protected void acquireResources() throws Exception { streamAndResultExtractor = checkpointStreamSupplier.get(); cancelStreamRegistry.registerCloseable(streamAndResultExtractor); }
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); } return stateFactory.get(); }
/** * 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); } } }
/** * 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); } } }
/** * Returns a future which is completed with the result of the {@link SupplierWithException}. * * @param supplier to provide the future's value * @param executor to execute the supplier * @param <T> type of the result * @return Future which is completed with the value of the supplier */ public static <T> CompletableFuture<T> supplyAsync(SupplierWithException<T, ?> supplier, Executor executor) { return CompletableFuture.supplyAsync( () -> { try { return supplier.get(); } catch (Throwable e) { throw new CompletionException(e); } }, executor); }
/** * Returns a future which is completed with the result of the {@link SupplierWithException}. * * @param supplier to provide the future's value * @param executor to execute the supplier * @param <T> type of the result * @return Future which is completed with the value of the supplier */ public static <T> CompletableFuture<T> supplyAsync(SupplierWithException<T, ?> supplier, Executor executor) { return CompletableFuture.supplyAsync( () -> { try { return supplier.get(); } catch (Throwable e) { throw new CompletionException(e); } }, executor); }
/** * Returns a future which is completed with the result of the {@link SupplierWithException}. * * @param supplier to provide the future's value * @param executor to execute the supplier * @param <T> type of the result * @return Future which is completed with the value of the supplier */ public static <T> CompletableFuture<T> supplyAsync(SupplierWithException<T, ?> supplier, Executor executor) { return CompletableFuture.supplyAsync( () -> { try { return supplier.get(); } catch (Throwable e) { throw new CompletionException(e); } }, executor); }
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); }
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); }