|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.multiverse.commitbarriers.CommitBarrier
public abstract class CommitBarrier
A CommitBarrier is a blocking structure like the CyclicBarrier but
tailored to work with transactions. Based on this functionality, it is possible to create
a 2-phase commit for example.
| Field Summary | |
|---|---|
protected Lock |
lock
|
protected Condition |
statusCondition
|
| Constructor Summary | |
|---|---|
CommitBarrier(org.multiverse.commitbarriers.CommitBarrier.Status status,
boolean fair)
Creates a new CommitBarrier. |
|
| Method Summary | |
|---|---|
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 void |
ensureNotDead(Transaction tx)
Ensures that a transaction is not dead. |
protected static void |
executeTasks(List<Runnable> tasks)
Executes the tasks. |
protected void |
finish(Transaction tx)
Finishes a Transaction. |
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(Transaction tx)
Joins this CommitBarrier with the provided transaction. |
void |
joinCommitUninterruptibly(Transaction 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(Transaction tx)
Tries to joins this CommitBarrier with the provided transaction. |
boolean |
tryJoinCommit(Transaction tx,
long timeout,
TimeUnit unit)
Tries to joins this CommitBarrier with the provided transaction. |
boolean |
tryJoinCommitUninterruptibly(Transaction tx,
long timeout,
TimeUnit unit)
Tries to joins this CommitBarrier with the provided transaction. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final Lock lock
protected final Condition statusCondition
| Constructor Detail |
|---|
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.| Method Detail |
|---|
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(Transaction tx)
tx - the transaction to finishprotected final void ensureNotDead(Transaction tx)
tx - the transaction to check.
DeadTransactionException - if tx is dead.
NullPointerException - if tx is null.
public void joinCommit(Transaction tx)
throws InterruptedException
tx - the Transaction to commit.
InterruptedException - if the thread is interrupted while waiting.
NullPointerException - if tx is null.
DeadTransactionException - if tx is committed/aborted.
CommitBarrierOpenException - if this VetoCommitBarrier is committed or aborted.public void joinCommitUninterruptibly(Transaction tx)
tx - the Transaction to join in the commit.
NullPointerException - if tx is null.
DeadTransactionException - if tx is committed/aborted.
CommitBarrierOpenException - if this VetoCommitBarrier is committed or aborted.public boolean tryJoinCommit(Transaction tx)
tx - the Transaction 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(Transaction tx,
long timeout,
TimeUnit unit)
throws InterruptedException
tx - the Transaction 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(Transaction tx,
long timeout,
TimeUnit unit)
tx - the Transaction 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()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||