@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;
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(); }
/** * 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); }
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); }
/** * Uploads the given jars and artifacts required for the execution of the given {@link JobGraph} using the {@link BlobClient} from * the given {@link Supplier}. * * @param jobGraph jobgraph requiring files * @param userJars jars to upload * @param userArtifacts artifacts to upload * @param clientSupplier supplier of blob client to upload files with * @throws FlinkException if the upload fails */ public static void uploadJobGraphFiles( JobGraph jobGraph, Collection<Path> userJars, Collection<Tuple2<String, org.apache.flink.core.fs.Path>> userArtifacts, SupplierWithException<BlobClient, IOException> clientSupplier) throws FlinkException { if (!userJars.isEmpty() || !userArtifacts.isEmpty()) { try (BlobClient client = clientSupplier.get()) { uploadAndSetUserJars(jobGraph, userJars, client); uploadAndSetUserArtifacts(jobGraph, userArtifacts, client); } catch (IOException ioe) { throw new FlinkException("Could not upload job files.", ioe); } } }
<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; } }