public class IndexShardOperationsLock
extends java.lang.Object
implements java.io.Closeable
Constructor and Description |
---|
IndexShardOperationsLock(ShardId shardId,
org.apache.logging.log4j.Logger logger,
ThreadPool threadPool) |
Modifier and Type | Method and Description |
---|---|
void |
acquire(ActionListener<Releasable> onAcquired,
java.lang.String executorOnDelay,
boolean forceExecution)
Acquires a permit whenever permit acquisition is not blocked.
|
void |
blockOperations(long timeout,
java.util.concurrent.TimeUnit timeUnit,
java.lang.Runnable onBlocked)
Wait for in-flight operations to finish and executes onBlocked under the guarantee that no new operations are started.
|
void |
close() |
int |
getActiveOperationsCount() |
public IndexShardOperationsLock(ShardId shardId, org.apache.logging.log4j.Logger logger, ThreadPool threadPool)
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public void blockOperations(long timeout, java.util.concurrent.TimeUnit timeUnit, java.lang.Runnable onBlocked) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
timeout
- the maximum time to wait for the in-flight operations blocktimeUnit
- the time unit of the timeout
argumentonBlocked
- the action to run once the block has been acquiredjava.lang.InterruptedException
- if calling thread is interruptedjava.util.concurrent.TimeoutException
- if timed out waiting for in-flight operations to finishIndexShardClosedException
- if operation lock has been closedpublic void acquire(ActionListener<Releasable> onAcquired, java.lang.String executorOnDelay, boolean forceExecution)
ActionListener
will be called on the calling thread. During calls of
blockOperations(long, TimeUnit, Runnable)
, permit acquisition can be delayed.
The ActionListener.onResponse(Object)
method will then be called using the provided executor once operations are no
longer blocked. Note that the executor will not be used for ActionListener.onFailure(Exception)
calls. Those will run
directly on the calling thread, which in case of delays, will be a generic thread. Callers should thus make sure
that the ActionListener.onFailure(Exception)
method provided here only contains lightweight operations.onAcquired
- ActionListener
that is invoked once acquisition is successful or failedexecutorOnDelay
- executor to use for the possibly delayed ActionListener.onResponse(Object)
callforceExecution
- whether the runnable should force its execution in case it gets rejectedpublic int getActiveOperationsCount()