public final class TransactionCoordinator extends Object
TransactionCoordinator per group of TransactionalComponents.
TransactionalComponents can not be shared across TransactionCoordinators.
This is a general engine although tested and most used for multiple-reader
and single-writer (MR+SW). TransactionalComponentLifecycle provides the
per-thread style.
Contrast to MRSW: multiple-reader or single-writer.
See blockWriters(), enableWriters(), execAsWriter(Runnable)
See startExclusiveMode()/tryExclusiveMode() finishExclusiveMode(), execExclusive(Runnable)
Transaction,
TransactionalComponent,
TransactionalSystem| Modifier and Type | Class and Description |
|---|---|
static interface |
TransactionCoordinator.ShutdownHook |
| Constructor and Description |
|---|
TransactionCoordinator(Journal journal)
Create a TransactionCoordinator, initially with no associated
TransactionalComponents. |
TransactionCoordinator(Journal journal,
List<TransactionalComponent> components)
Create a TransactionCoordinator, initially with
TransactionalComponents in the ComponentGroup |
TransactionCoordinator(Location location)
Create a TransactionCoordinator, initially with no associated
TransactionalComponents |
| Modifier and Type | Method and Description |
|---|---|
TransactionCoordinator |
add(TransactionalComponent elt)
Add a
TransactionalComponent. |
void |
add(TransactionCoordinator.ShutdownHook hook)
Add a shutdown hook.
|
TransactionCoordinator |
addListener(TransactionListener listener) |
void |
attach(TransactionCoordinatorState coordinatorState) |
Transaction |
begin(TxnType txnType)
Start a transaction.
|
Transaction |
begin(TxnType txnType,
boolean canBlock)
Start a transaction.
|
void |
blockWriters()
Block until no writers are active.
|
long |
countActive() |
long |
countActiveReaders() |
long |
countActiveWriter() |
long |
countBegin() |
long |
countBeginRead() |
long |
countBeginWrite() |
long |
countFinished() |
TransactionCoordinatorState |
detach(Transaction txn) |
void |
enableWriters()
Allow writers.
|
void |
execAsWriter(Runnable action)
Execute an action in as if a Write but no write transaction started.
|
void |
execExclusive(Runnable action)
Execute an action in exclusive mode.
|
void |
finishExclusiveMode()
Return to normal (release waiting transactions, allow new transactions).
|
Journal |
getJournal() |
Location |
getLocation() |
void |
modifyConfig(Runnable action)
Perform modification of this
TransactionCoordiator after it has been
started. |
TransactionCoordinator |
remove(TransactionalComponent elt)
Remove a
TransactionalComponent. |
void |
remove(TransactionCoordinator.ShutdownHook hook)
Remove a shutdown hook
|
TransactionCoordinator |
removeListener(TransactionListener listener) |
void |
setQuorumGenerator(QuorumGenerator qGen) |
void |
setTxnIdGenerator(TxnIdGenerator generator) |
void |
shutdown() |
void |
shutdown(boolean silent) |
void |
start() |
void |
startExclusiveMode()
Enter exclusive mode; block if necessary.
|
boolean |
tryBlockWriters()
Try to block all writers, or return if can't at the moment.
|
boolean |
tryBlockWriters(boolean canBlock)
Block until no writers are active, optionally blocking or returning if can't at the moment.
|
boolean |
tryExclusiveMode()
Try to enter exclusive mode.
|
boolean |
tryExclusiveMode(boolean canBlock)
Try to enter exclusive mode.
|
public TransactionCoordinator(Location location)
TransactionalComponentspublic TransactionCoordinator(Journal journal)
TransactionalComponents.public TransactionCoordinator(Journal journal, List<TransactionalComponent> components)
TransactionalComponents in the ComponentGrouppublic TransactionCoordinator add(TransactionalComponent elt)
TransactionalComponent.
Safe to call at any time but it is good practice is to add all the
components before any transactions start.
Internally, the coordinator ensures the add will safely happen but it
does not add the component to existing transactions.
This must be setup before recovery is attempted.public TransactionCoordinator remove(TransactionalComponent elt)
TransactionalComponent.public TransactionCoordinator addListener(TransactionListener listener)
public TransactionCoordinator removeListener(TransactionListener listener)
public void modifyConfig(Runnable action)
TransactionCoordiator after it has been
started.
This operation enters exclusive mode, releases the
configuration lock, then calls the action. On exit from the action,
it resets the configuration lock, and exits exclusive mode.
Do not call inside a transaction, it may cause a deadlock.
Use with care!
public void add(TransactionCoordinator.ShutdownHook hook)
public void remove(TransactionCoordinator.ShutdownHook hook)
public void setQuorumGenerator(QuorumGenerator qGen)
public void start()
public void setTxnIdGenerator(TxnIdGenerator generator)
public Journal getJournal()
public Location getLocation()
public TransactionCoordinatorState detach(Transaction txn)
public void attach(TransactionCoordinatorState coordinatorState)
public void shutdown()
public void shutdown(boolean silent)
public void startExclusiveMode()
finishExclusiveMode().
Do not call inside an existing transaction.
public boolean tryExclusiveMode()
finishExclusiveMode().
Do not call inside an existing transaction.
public boolean tryExclusiveMode(boolean canBlock)
finishExclusiveMode().
Do not call inside an existing transaction.
canBlock - Allow the operation block and wait for the exclusive mode lock.public void finishExclusiveMode()
startExclusiveMode().public void execExclusive(Runnable action)
startExclusiveMode();
try { action.run(); }
finally { finishExclusiveMode(); }
action - public void blockWriters()
The application must call enableWriters() later.
This operation must not be nested (it will block).
tryBlockWriters(),
enableWriters()public boolean tryBlockWriters()
Unlike a write transction, there is no associated transaction.
If it returns true, the application must call enableWriters() later.
blockWriters(),
enableWriters()public boolean tryBlockWriters(boolean canBlock)
Unlike a write transaction, there is no associated transaction.
If it returns true, the application must call enableWriters() later.
canBlock - public void enableWriters()
blockWriters() or tryBlockWriters()blockWriters(),
tryBlockWriters()public void execAsWriter(Runnable action)
Equivalent to:
blockWriters();
try { action.run(); }
finally { enableWriters(); }
action - public Transaction begin(TxnType txnType)
public Transaction begin(TxnType txnType, boolean canBlock)
public long countActiveReaders()
public long countActiveWriter()
public long countActive()
public long countBegin()
public long countBeginRead()
public long countBeginWrite()
public long countFinished()
Licensed under the Apache License, Version 2.0