@Override public V allocate(final Slot slot) throws Exception { return retryer.call(new Callable<V>() { @Override public V call() throws Exception { return allocator.allocate(slot); } }); }
private void callWithRetry(Callable<Void> callable) throws IOException { try { this.retryer.wrap(callable).call(); } catch (ExecutionException | RetryException e) { throw new IOException(e); } }
/** * Builds the retryer. * * @return the built retryer. */ public Retryer<V> build() { AttemptTimeLimiter<V> theAttemptTimeLimiter = attemptTimeLimiter == null ? AttemptTimeLimiters.<V>noTimeLimit() : attemptTimeLimiter; StopStrategy theStopStrategy = stopStrategy == null ? StopStrategies.neverStop() : stopStrategy; WaitStrategy theWaitStrategy = waitStrategy == null ? WaitStrategies.noWait() : waitStrategy; BlockStrategy theBlockStrategy = blockStrategy == null ? BlockStrategies.threadSleepStrategy() : blockStrategy; return new Retryer<V>(theAttemptTimeLimiter, theStopStrategy, theWaitStrategy, theBlockStrategy, rejectionPredicate, listeners); }
/** * Builds the retryer. * * @return the built retryer. */ public Retryer build() { AttemptTimeLimiter theAttemptTimeLimiter = attemptTimeLimiter == null ? AttemptTimeLimiters.noTimeLimit() : attemptTimeLimiter; StopStrategy theStopStrategy = stopStrategy == null ? StopStrategies.neverStop() : stopStrategy; WaitStrategy theWaitStrategy = waitStrategy == null ? WaitStrategies.noWait() : waitStrategy; BlockStrategy theBlockStrategy = blockStrategy == null ? BlockStrategies.threadSleepStrategy() : blockStrategy; return new Retryer( theAttemptTimeLimiter, theStopStrategy, theWaitStrategy, theBlockStrategy, retryPredicates, listeners); }
private BulkResult runBulkRequest(final Bulk request, int count) { try { return BULK_REQUEST_RETRYER.call(() -> client.execute(request)); } catch (ExecutionException | RetryException e) { if (e instanceof RetryException) { LOG.error("Could not bulk index {} messages. Giving up after {} attempts.", count, ((RetryException) e).getNumberOfFailedAttempts()); } else { LOG.error("Couldn't bulk index " + count + " messages.", e); } throw new RuntimeException(e); } }
/** Calls to submit will block until a permit is available to process the request @param callable */ public void submit(Callable<Integer> callable) { try { //System.out.println("Execute called"); m_semaphore.acquire(); //System.out.println("Submitting"); m_internalExecutor.submit( new IngestFutureTask(m_retryer.wrap(callable))); //System.out.println("Done submitting"); } //Potentially thrown by acquire catch (InterruptedException e) { e.printStackTrace(); } }
JOURNAL_WRITE_RETRYER.call(new Callable<Void>() { @Override public Void call() throws Exception {
/** * Submits the user defined {@link #insertBatch(PreparedStatement)} call to the {@link Retryer} which takes care * of resubmitting the records according to {@link #WRITER_JDBC_INSERT_RETRY_TIMEOUT} and {@link #WRITER_JDBC_INSERT_RETRY_MAX_ATTEMPT} * when failure happens. * * @param pstmt PreparedStatement object */ protected void executeBatchInsert(final PreparedStatement pstmt) { try { // Need a Callable interface to be wrapped by Retryer. this.retryer.wrap(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return insertBatch(pstmt); } }).call(); } catch (Exception e) { throw new RuntimeException("Failed to insert.", e); } resetBatch(); }
public static void mkdirsWithRecursivePermissionWithRetry(final FileSystem fs, final Path path, FsPermission perm, Config retrierConfig) throws IOException { if (fs.exists(path)) { return; } if (path.getParent() != null && !fs.exists(path.getParent())) { mkdirsWithRecursivePermissionWithRetry(fs, path.getParent(), perm, retrierConfig); } if (!fs.mkdirs(path, perm)) { throw new IOException(String.format("Unable to mkdir %s with permission %s", path, perm)); } if (retrierConfig != NO_RETRY_CONFIG) { //Wait until file is not there as it can happen the file fail to exist right away on eventual consistent fs like Amazon S3 Retryer<Void> retryer = RetryerFactory.newInstance(retrierConfig); try { retryer.call(() -> { if (!fs.exists(path)) { throw new IOException("Path " + path + " does not exist however it should. Will wait more."); } return null; }); } catch (Exception e) { throw new IOException("Path " + path + "does not exist however it should. Giving up..."+ e); } } // Double check permission, since fs.mkdirs() may not guarantee to set the permission correctly if (!fs.getFileStatus(path).getPermission().equals(perm)) { fs.setPermission(path, perm); } }
private void callWithRetry(Callable<Void> callable) throws IOException { try { this.retryer.wrap(callable).call(); } catch (ExecutionException | RetryException e) { throw new IOException(e); } }
retryer.call(checkForEmptyBuffers); } catch (RetryException e) { LOG.info("Buffers not empty after {} {}. Giving up.", maxWait, timeUnit.name().toLowerCase(Locale.ENGLISH));
/** * Submits the user defined {@link #insertBatch(PreparedStatement)} call to the {@link Retryer} which takes care * of resubmitting the records according to {@link #WRITER_JDBC_INSERT_RETRY_TIMEOUT} and {@link #WRITER_JDBC_INSERT_RETRY_MAX_ATTEMPT} * when failure happens. * * @param pstmt PreparedStatement object */ protected void executeBatchInsert(final PreparedStatement pstmt) { try { // Need a Callable interface to be wrapped by Retryer. this.retryer.wrap(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return insertBatch(pstmt); } }).call(); } catch (Exception e) { throw new RuntimeException("Failed to insert.", e); } resetBatch(); }
private void moveTmpPathToOutputPath() throws IOException { Retryer<Void> retryer = RetryerFactory.newInstance(this.retrierConfig); LOG.info(String.format("Moving %s to %s", this.dataset.outputTmpPath(), this.dataset.outputPath())); this.fs.delete(this.dataset.outputPath(), true); if (this.isRetryEnabled) { try { retryer.call(() -> { if (fs.exists(this.dataset.outputPath())) { throw new IOException("Path " + this.dataset.outputPath() + " exists however it should not. Will wait more."); } return null; }); } catch (Exception e) { throw new IOException(e); } } WriterUtils.mkdirsWithRecursivePermissionWithRetry(MRCompactorJobRunner.this.fs, this.dataset.outputPath().getParent(), this.perm, this.retrierConfig); Log.info("Moving from fs: ("+MRCompactorJobRunner.this.tmpFs.getUri()+") path: "+ this.dataset.outputTmpPath() + " to "+ "fs: ("+ FileSystem.get(this.dataset.outputPath().getParent().toUri(), this.fs.getConf()).getUri()+") output path: " + this.dataset.outputPath()); HadoopUtils.movePath (MRCompactorJobRunner.this.tmpFs, this.dataset.outputTmpPath(), FileSystem.get(this.dataset.outputPath().getParent().toUri(), this.fs.getConf()), this.dataset.outputPath(), false, this.fs.getConf()) ; }
@Test public void testWrap() throws Exception { Callable<Boolean> callable = notNullAfter5Attempts(); Retryer retryer = RetryerBuilder.newBuilder() .retryIfResult(Objects::isNull) .build(); RetryerCallable<Boolean> wrapped = retryer.wrap(callable); assertTrue(wrapped.call()); }
UnsampledReport result = null; try { result = retryer.call(new Callable<UnsampledReport>() {
return retryer.call(supplierCommand::get); } catch (ExecutionException executionException) { String errorMessage = String.format("Operation '%s:%s' failed for the %d time in RetryUtil", operationName,
.build(); try { retryer.call(() -> mongoDBSessionService.saveWithoutValidation(dbSession)); } catch (ExecutionException e) { LOG.warn("Unexpected exception when saving session to MongoDB. Failed to update session.", e);
/** * Retry to execute callable command. * * @param callable callable command * @param <T> return type * @return execute result */ public <T> Optional<T> execute(final Callable<T> callable) { Retryer<T> retryer = RetryerBuilder.<T>newBuilder() .retryIfExceptionOfType(TimeoutException.class) .retryIfExceptionOfType(ExecutionException.class) .retryIfExceptionOfType(InterruptedException.class) .withWaitStrategy(WaitStrategies.fixedWait(config.getRetryIntervalMilliseconds(), TimeUnit.MILLISECONDS)) .withStopStrategy(StopStrategies.stopAfterAttempt(config.getMaxRetries())) .build(); try { return Optional.fromNullable(retryer.call(callable)); } catch (final ExecutionException | RetryException ex) { throw new RegistryCenterException(ex); } } }
return retryer.call(new Callable<UnsampledReport>() { @Override public UnsampledReport call() throws Exception {
private HttpResponse executeRequest(Function<String, String> hostToUri, Method method, Optional<?> body, Map<String, ?> queryParams) { HttpRequest.Builder request = HttpRequest.newBuilder().setMethod(method); if (body.isPresent()) { request.setBody(body.get()); } addQueryParams(request, queryParams); addCredentials(request); List<String> hosts = new ArrayList<>(hostsProvider.get()); request .setRetryStrategy(RetryStrategy.NEVER_RETRY) .setMaxRetries(1); try { return httpResponseRetryer.call(() -> { if (hosts.isEmpty()) { // We've tried everything we started with. Look again. hosts.addAll(hostsProvider.get()); } int selection = random.nextInt(hosts.size()); String host = hosts.get(selection); String url = hostToUri.apply(host); hosts.remove(selection); LOG.info("Making {} request to {}", method, url); request.setUrl(url); return httpClient.execute(request.build()); }); } catch (ExecutionException | RetryException exn) { throw new SingularityClientException("Failed request to Singularity", exn); } }