public abstract class CommitBarrier extends Object
CyclicBarrier
but
tailored to work with transactions. Based on this functionality, it is possible to create
a 2-phase commit for example.Modifier and Type | Field and Description |
---|---|
protected Lock |
lock |
protected Condition |
statusCondition |
Constructor and Description |
---|
CommitBarrier(org.multiverse.commitbarriers.CommitBarrier.Status status,
boolean fair)
Creates a new CommitBarrier.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Aborts this CommitBarrier.
|
protected void |
addJoiner()
Adds a waiters.
|
void |
awaitOpen()
Awaits for this barrier to open (commit or abort).
|
void |
awaitOpenUninterruptibly()
Awaits for this barrier to open (commit or abort).
|
protected static void |
ensureNotDead(Txn tx,
String operation)
Ensures that a transaction is not dead.
|
protected static void |
executeTasks(List<Runnable> tasks)
Executes the tasks.
|
protected void |
finish(Txn tx)
Finishes a Txn.
|
int |
getNumberWaiting()
Returns the number of Transactions that have prepared and are waiting to commit.
|
protected org.multiverse.commitbarriers.CommitBarrier.Status |
getStatus() |
boolean |
isAborted()
Checks if this CommitBarrier already is aborted.
|
boolean |
isClosed()
Checks if this CommitBarrier is closed.
|
boolean |
isCommitted()
Checks if this CommitBarrier already is committed.
|
protected abstract boolean |
isLastParty() |
void |
joinCommit(Txn tx)
Joins this CommitBarrier with the provided transaction.
|
void |
joinCommitUninterruptibly(Txn tx)
Joins this CommitBarrier with the provided transaction.
|
void |
registerOnAbortTask(Runnable task)
Registers a task that is executed once the CommitBarrier aborts.
|
void |
registerOnCommitTask(Runnable task)
Registers a task that is executed once the CommitBarrier commits.
|
void |
setScheduledExecutorService(ScheduledExecutorService executorService)
Sets the ScheduledExecutorService to be used by this CommitBarrier for the timeout.
|
void |
setTimeout(long timeout,
TimeUnit unit)
Sets the timeout on this CommitBarrier.
|
protected List<Runnable> |
signalAborted()
Only should be made when the lock is acquired.
|
protected List<Runnable> |
signalCommit()
Only should be made when the lock is acquired.
|
boolean |
tryAwaitOpen(long timeout,
TimeUnit unit)
Waits for this barrier to open (abort or commit).
|
boolean |
tryAwaitOpenUninterruptibly(long timeout,
TimeUnit unit)
Tries to await the close of the barrier.
|
boolean |
tryJoinCommit(Txn tx)
Tries to joins this CommitBarrier with the provided transaction.
|
boolean |
tryJoinCommit(Txn tx,
long timeout,
TimeUnit unit)
Tries to joins this CommitBarrier with the provided transaction.
|
boolean |
tryJoinCommitUninterruptibly(Txn tx,
long timeout,
TimeUnit unit)
Tries to joins this CommitBarrier with the provided transaction.
|
protected final Lock lock
protected final Condition statusCondition
public CommitBarrier(org.multiverse.commitbarriers.CommitBarrier.Status status, boolean fair)
status
- the initial status of the CommitBarrier.fair
- if waking up threads is going to be fair.NullPointerException
- if status is null.protected final org.multiverse.commitbarriers.CommitBarrier.Status getStatus()
public final int getNumberWaiting()
public final boolean isClosed()
public final boolean isCommitted()
public final boolean isAborted()
protected final List<Runnable> signalCommit()
protected final List<Runnable> signalAborted()
public final void abort()
CommitBarrierOpenException
- if this CommitBarrier already is committed.protected static void executeTasks(List<Runnable> tasks)
tasks
- the tasks to execute.public final void awaitOpen() throws InterruptedException
InterruptedException
- if the calling thread is interrupted while waiting.public final void awaitOpenUninterruptibly()
public final boolean tryAwaitOpen(long timeout, TimeUnit unit) throws InterruptedException
timeout
- the maximum amount of time to wait for the barrier to close.unit
- the TimeUnit for the timeout argument.InterruptedException
- if the thread is interrupted while waiting.NullPointerException
- if unit is null.public final boolean tryAwaitOpenUninterruptibly(long timeout, TimeUnit unit)
timeout
- the maximum amount of time to wait for the barrier to be closed.unit
- the timeunit for the timeout argument.public void setScheduledExecutorService(ScheduledExecutorService executorService)
executorService
- the ScheduledExecutorService this CommitBarrier is going to use for timeout.NullPointerException
- if executorService is null.public final void setTimeout(long timeout, TimeUnit unit)
timeout
- the maximum amount of time this barrier is allowed to run.unit
- the TimeUnit of the timeout parameter.NullPointerException
- if unit is null.CommitBarrierOpenException
- if the CommitBarrier already is aborted or committed.public final void registerOnAbortTask(Runnable task)
task
- the task that is executed once the CommitBarrier commits.NullPointerException
- if task is null.CommitBarrierOpenException
- if this CommitBarrier already is aborted or committed.public final void registerOnCommitTask(Runnable task)
task
- the task that is executed once the CommitBarrier commits.NullPointerException
- if task is null.CommitBarrierOpenException
- if this CommitBarrier already is aborted or committed.protected final void addJoiner()
IllegalStateException
- if the transaction isn't closed.protected final void finish(Txn tx)
tx
- the transaction to finishprotected static void ensureNotDead(Txn tx, String operation)
tx
- the transaction to check.operation
- the name of the operation to checks if this transaction is not dead. Needed to provide
a useful message.DeadTxnException
- if tx is dead.NullPointerException
- if tx is null.public void joinCommit(Txn tx) throws InterruptedException
tx
- the Txn to commit.InterruptedException
- if the thread is interrupted while waiting.NullPointerException
- if tx is null.IllegalTxnStateException
- if the tx is no in the correct
state for this operation.CommitBarrierOpenException
- if this VetoCommitBarrier is committed or aborted.public void joinCommitUninterruptibly(Txn tx)
tx
- the Txn to join in the commit.NullPointerException
- if tx is null.IllegalTxnStateException
- if the tx is not in the correct
state for the operation.CommitBarrierOpenException
- if this VetoCommitBarrier is committed or aborted.public boolean tryJoinCommit(Txn tx)
tx
- the Txn that wants to join the other parties to commit with.CommitBarrierOpenException
- if tx or this CountDownCommitBarrier is aborted or committed.NullPointerException
- if tx is null.public boolean tryJoinCommit(Txn tx, long timeout, TimeUnit unit) throws InterruptedException
tx
- the Txn that wants to join the other parties to commit with.timeout
- the maximum time to wait.unit
- the TimeUnit for the timeout argument.CommitBarrierOpenException
- if tx or this CountDownCommitBarrier is aborted or committed.NullPointerException
- if tx or unit is null is null.InterruptedException
- if the calling thread is interrupted while waiting.public boolean tryJoinCommitUninterruptibly(Txn tx, long timeout, TimeUnit unit)
tx
- the Txn that wants to join the other parties to commit with.timeout
- the maximum time to wait.unit
- the TimeUnit for the timeout argument.CommitBarrierOpenException
- if tx or this CountDownCommitBarrier is aborted or committed.NullPointerException
- if tx or unit is null is null.protected abstract boolean isLastParty()
Copyright © 2020. All rights reserved.