private void callWithRetry(Callable<Void> callable) throws IOException { try { this.retryer.wrap(callable).call(); } catch (ExecutionException | RetryException e) { throw new IOException(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(); } }
/** * 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 callWithRetry(Callable<Void> callable) throws IOException { try { this.retryer.wrap(callable).call(); } catch (ExecutionException | RetryException e) { throw new IOException(e); } }
/** * 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()); }