delayOperations(); threadPool.executor(ThreadPool.Names.GENERIC).execute(new AbstractRunnable() {
/** * Wait for in-flight operations to finish and executes {@code onBlocked} under the guarantee that no new operations are started. Queues * operations that are occurring in the meanwhile and runs them once {@code onBlocked} has executed. * * @param timeout the maximum time to wait for the in-flight operations block * @param timeUnit the time unit of the {@code timeout} argument * @param onBlocked the action to run once the block has been acquired * @param <E> the type of checked exception thrown by {@code onBlocked} * @throws InterruptedException if calling thread is interrupted * @throws TimeoutException if timed out waiting for in-flight operations to finish * @throws IndexShardClosedException if operation permit has been closed */ <E extends Exception> void blockOperations( final long timeout, final TimeUnit timeUnit, final CheckedRunnable<E> onBlocked) throws InterruptedException, TimeoutException, E { delayOperations(); try (Releasable ignored = acquireAll(timeout, timeUnit)) { onBlocked.run(); } finally { releaseDelayedOperations(); } }
/** * Immediately delays operations and on another thread waits for in-flight operations to finish and then executes {@code onBlocked} * under the guarantee that no new operations are started. Delayed operations are run after {@code onBlocked} has executed. After * operations are delayed and the blocking is forked to another thread, returns to the caller. If a failure occurs while blocking * operations or executing {@code onBlocked} then the {@code onFailure} handler will be invoked. * * @param timeout the maximum time to wait for the in-flight operations block * @param timeUnit the time unit of the {@code timeout} argument * @param onBlocked the action to run once the block has been acquired * @param onFailure the action to run if a failure occurs while blocking operations * @param <E> the type of checked exception thrown by {@code onBlocked} (not thrown on the calling thread) */ <E extends Exception> void asyncBlockOperations( final long timeout, final TimeUnit timeUnit, final CheckedRunnable<E> onBlocked, final Consumer<Exception> onFailure) { delayOperations(); threadPool.executor(ThreadPool.Names.GENERIC).execute(new AbstractRunnable() { @Override public void onFailure(final Exception e) { onFailure.accept(e); } @Override protected void doRun() throws Exception { doBlockOperations(timeout, timeUnit, onBlocked); } @Override public void onAfter() { releaseDelayedOperations(); } }); }
/** * Immediately delays operations and on another thread waits for in-flight operations to finish and then executes {@code onBlocked} * under the guarantee that no new operations are started. Delayed operations are run after {@code onBlocked} has executed. After * operations are delayed and the blocking is forked to another thread, returns to the caller. If a failure occurs while blocking * operations or executing {@code onBlocked} then the {@code onFailure} handler will be invoked. * * @param timeout the maximum time to wait for the in-flight operations block * @param timeUnit the time unit of the {@code timeout} argument * @param onBlocked the action to run once the block has been acquired * @param onFailure the action to run if a failure occurs while blocking operations * @param <E> the type of checked exception thrown by {@code onBlocked} (not thrown on the calling thread) */ <E extends Exception> void asyncBlockOperations( final long timeout, final TimeUnit timeUnit, final CheckedRunnable<E> onBlocked, final Consumer<Exception> onFailure) { delayOperations(); threadPool.executor(ThreadPool.Names.GENERIC).execute(new AbstractRunnable() { @Override public void onFailure(final Exception e) { onFailure.accept(e); } @Override protected void doRun() throws Exception { doBlockOperations(timeout, timeUnit, onBlocked); } @Override public void onAfter() { releaseDelayedOperations(); } }); }
/** * Wait for in-flight operations to finish and executes {@code onBlocked} under the guarantee that no new operations are started. Queues * operations that are occurring in the meanwhile and runs them once {@code onBlocked} has executed. * * @param timeout the maximum time to wait for the in-flight operations block * @param timeUnit the time unit of the {@code timeout} argument * @param onBlocked the action to run once the block has been acquired * @param <E> the type of checked exception thrown by {@code onBlocked} * @throws InterruptedException if calling thread is interrupted * @throws TimeoutException if timed out waiting for in-flight operations to finish * @throws IndexShardClosedException if operation permit has been closed */ <E extends Exception> void blockOperations( final long timeout, final TimeUnit timeUnit, final CheckedRunnable<E> onBlocked) throws InterruptedException, TimeoutException, E { delayOperations(); try { doBlockOperations(timeout, timeUnit, onBlocked); } finally { releaseDelayedOperations(); } }
/** * Wait for in-flight operations to finish and executes {@code onBlocked} under the guarantee that no new operations are started. Queues * operations that are occurring in the meanwhile and runs them once {@code onBlocked} has executed. * * @param timeout the maximum time to wait for the in-flight operations block * @param timeUnit the time unit of the {@code timeout} argument * @param onBlocked the action to run once the block has been acquired * @param <E> the type of checked exception thrown by {@code onBlocked} * @throws InterruptedException if calling thread is interrupted * @throws TimeoutException if timed out waiting for in-flight operations to finish * @throws IndexShardClosedException if operation permit has been closed */ <E extends Exception> void blockOperations( final long timeout, final TimeUnit timeUnit, final CheckedRunnable<E> onBlocked) throws InterruptedException, TimeoutException, E { delayOperations(); try { doBlockOperations(timeout, timeUnit, onBlocked); } finally { releaseDelayedOperations(); } }