/** * 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(); }
/** * 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(); }
@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()); }
/** * Wraps the given {@link Callable} in a {@link RetryerCallable}, which can * be submitted to an executor. The returned {@link RetryerCallable} uses * this {@link Retryer} instance to call the given {@link Callable}. * * @param callable the callable to wrap * @param <T> the return type of the Callable * @return a {@link RetryerCallable} that behaves like the given {@link Callable} with retry behavior defined by this {@link Retryer} */ @SuppressWarnings("WeakerAccess") public <T> RetryerCallable<T> wrap(Callable<T> callable) { return new RetryerCallable<>(this, callable); }
private void callWithRetry(Callable<Void> callable) throws IOException { try { this.retryer.wrap(callable).call(); } catch (ExecutionException | RetryException e) { throw new IOException(e); } }
/** * Wraps the given {@link Callable} in a {@link RetryerCallable}, which can * be submitted to an executor. The returned {@link RetryerCallable} uses * this {@link Retryer} instance to call the given {@link Callable}. * * @param callable the callable to wrap * @return a {@link RetryerCallable} that behaves like the given {@link Callable} with retry behavior defined by this {@link Retryer} */ public RetryerCallable<V> wrap(Callable<V> callable) { return new RetryerCallable<V>(this, callable); }
private void callWithRetry(Callable<Void> callable) throws IOException { try { this.retryer.wrap(callable).call(); } catch (ExecutionException | RetryException e) { throw new IOException(e); } }