public static RefCountedBufferingFileStream openNew( final FunctionWithException<File, RefCountedFile, IOException> tmpFileProvider) throws IOException { return new RefCountedBufferingFileStream( tmpFileProvider.apply(null), BUFFER_SIZE); }
public static RefCountedBufferingFileStream restore( final FunctionWithException<File, RefCountedFile, IOException> tmpFileProvider, final File initialTmpFile) throws IOException { return new RefCountedBufferingFileStream( tmpFileProvider.apply(initialTmpFile), BUFFER_SIZE); } }
/** * Convert at {@link FunctionWithException} into a {@link Function}. * * @param functionWithException function with exception to convert into a function * @param <A> input type * @param <B> output type * @return {@link Function} which throws all checked exception as an unchecked exception. */ public static <A, B> Function<A, B> uncheckedFunction(FunctionWithException<A, B, ?> functionWithException) { return (A value) -> { try { return functionWithException.apply(value); } catch (Throwable t) { ExceptionUtils.rethrow(t); // we need this to appease the compiler :-( return null; } }; }
private Optional<File> recoverInProgressPart(S3Recoverable recoverable) throws IOException { final String objectKey = recoverable.incompleteObjectName(); if (objectKey == null) { return Optional.empty(); } // download the file (simple way) final RefCountedFile refCountedFile = tmpFileSupplier.apply(null); final File file = refCountedFile.getFile(); final long numBytes = s3AccessHelper.getObject(objectKey, file); if (numBytes != recoverable.incompleteObjectLength()) { throw new IOException(String.format("Error recovering writer: " + "Downloading the last data chunk file gives incorrect length." + "File length is %d bytes, RecoveryData indicates %d bytes", numBytes, recoverable.incompleteObjectLength())); } return Optional.of(file); }
/** * Convert at {@link FunctionWithException} into a {@link Function}. * * @param functionWithException function with exception to convert into a function * @param <A> input type * @param <B> output type * @return {@link Function} which throws all checked exception as an unchecked exception. */ public static <A, B> Function<A, B> uncheckedFunction(FunctionWithException<A, B, ?> functionWithException) { return (A value) -> { try { return functionWithException.apply(value); } catch (Throwable t) { ExceptionUtils.rethrow(t); // we need this to appease the compiler :-( return null; } }; }
private CompletableFuture<Void> waitForTerminatingJobManager(JobID jobId, JobGraph jobGraph, FunctionWithException<JobGraph, CompletableFuture<Void>, ?> action) { final CompletableFuture<Void> jobManagerTerminationFuture = getJobTerminationFuture(jobId) .exceptionally((Throwable throwable) -> { throw new CompletionException( new DispatcherException( String.format("Termination of previous JobManager for job %s failed. Cannot submit job under the same job id.", jobId), throwable)); }); return jobManagerTerminationFuture.thenComposeAsync( FunctionUtils.uncheckedFunction((ignored) -> { jobManagerTerminationFutures.remove(jobId); return action.apply(jobGraph); }), getMainThreadExecutor()); }
private CompletableFuture<Void> waitForTerminatingJobManager(JobID jobId, JobGraph jobGraph, FunctionWithException<JobGraph, CompletableFuture<Void>, ?> action) { final CompletableFuture<Void> jobManagerTerminationFuture = getJobTerminationFuture(jobId) .exceptionally((Throwable throwable) -> { throw new CompletionException( new DispatcherException( String.format("Termination of previous JobManager for job %s failed. Cannot submit job under the same job id.", jobId), throwable)); }); return jobManagerTerminationFuture.thenComposeAsync( FunctionUtils.uncheckedFunction((ignored) -> { jobManagerTerminationFutures.remove(jobId); return action.apply(jobGraph); }), getMainThreadExecutor()); }