public abstract class AbstractTransaction extends Object implements Transaction
Transaction that provides some common functionality and default behavior. Vendors
can use this class as a starting point for their own implementations. Implementers should note that this
class assumes that threaded transactions are not enabled. Vendors should explicitly override
createThreadedTx() to implement that functionality if required.
Note that transaction listeners are registered in a ThreadLocal fashion which matches the pattern
expected of vendor implementations of a Transaction.| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractTransaction.TransactionException
An "internal" exception thrown by vendors when calls to
doCommit() or
doRollback() fail. |
Transaction.CLOSE_BEHAVIOR, Transaction.Exceptions, Transaction.READ_WRITE_BEHAVIOR, Transaction.Status, Transaction.Workload<R>| Modifier and Type | Field and Description |
|---|---|
protected Consumer<Transaction> |
closeConsumer |
protected Consumer<Transaction> |
readWriteConsumer |
| Constructor and Description |
|---|
AbstractTransaction(Graph g) |
| Modifier and Type | Method and Description |
|---|---|
void |
addTransactionListener(Consumer<Transaction.Status> listener)
Adds a listener that is called back with a status when a commit or rollback is successful.
|
void |
clearTransactionListeners()
Removes all transaction listeners.
|
void |
close()
Closes the transaction where the default close behavior defined by {
Transaction.onClose(Consumer)} will be
executed. |
void |
commit()
Commits a transaction.
|
<G extends Graph> |
createThreadedTx()
Creates a transaction that can be executed across multiple threads.
|
protected abstract void |
doCommit()
Called with
commit() after the readWriteConsumer has been notified. |
protected abstract void |
doOpen()
Called within
open() if it is determined that the transaction is not yet open given Transaction.isOpen(). |
protected abstract void |
doRollback()
Called with
rollback() after the readWriteConsumer has been notified. |
Transaction |
onClose(Consumer<Transaction> consumer)
Describes what happens to a transaction on a call to
Graph.close(). |
Transaction |
onReadWrite(Consumer<Transaction> consumer)
Describes how a transaction is started when a read or a write occurs.
|
void |
open()
Opens a transaction.
|
void |
readWrite()
An internal function that signals a read or a write has occurred - not meant to be called directly by end users.
|
void |
removeTransactionListener(Consumer<Transaction.Status> listener)
Removes a transaction listener.
|
void |
rollback()
Rolls back a transaction.
|
<R> Transaction.Workload<R> |
submit(Function<Graph,R> work)
Submit a unit of work that represents a transaction returning a
Transaction.Workload that can be automatically
retried in the event of failure. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitisOpenprotected Consumer<Transaction> readWriteConsumer
protected Consumer<Transaction> closeConsumer
public AbstractTransaction(Graph g)
protected abstract void doOpen()
open() if it is determined that the transaction is not yet open given Transaction.isOpen().
Implementers should assume the transaction is not yet started and should thus open one.protected abstract void doCommit()
throws AbstractTransaction.TransactionException
commit() after the readWriteConsumer has been notified. Implementers should
include their commit logic here.protected abstract void doRollback()
throws AbstractTransaction.TransactionException
rollback() after the readWriteConsumer has been notified. Implementers should
include their rollback logic here.public void open()
Transactionopen in interface Transactionpublic void commit()
Transactioncommit in interface Transactionpublic void rollback()
Transactionrollback in interface Transactionpublic <R> Transaction.Workload<R> submit(Function<Graph,R> work)
TransactionTransaction.Workload that can be automatically
retried in the event of failure.submit in interface Transactionpublic <G extends Graph> G createThreadedTx()
TransactionGraph returned from this
method is not meant to represent some form of child transaction that can be committed from this object.
A threaded transaction is a Graph instance that has a transaction context that enables multiple
threads to collaborate on the same transaction. A standard transactional context tied to a Graph
that supports transactions will typically bind a transaction to a single thread via ThreadLocal.createThreadedTx in interface Transactionpublic void readWrite()
TransactionreadWrite in interface Transactionpublic void close()
Transaction.onClose(Consumer)} will be
executed.close in interface AutoCloseableclose in interface Transactionpublic Transaction onReadWrite(Consumer<Transaction> consumer)
TransactionTransaction.READ_WRITE_BEHAVIOR or a mapper Consumer function.onReadWrite in interface Transactionpublic Transaction onClose(Consumer<Transaction> consumer)
TransactionGraph.close(). This value can be set using
standard behavior defined in Transaction.CLOSE_BEHAVIOR or a mapper Consumer function.onClose in interface Transactionpublic void addTransactionListener(Consumer<Transaction.Status> listener)
TransactionaddTransactionListener in interface Transactionpublic void removeTransactionListener(Consumer<Transaction.Status> listener)
TransactionremoveTransactionListener in interface Transactionpublic void clearTransactionListeners()
TransactionclearTransactionListeners in interface TransactionCopyright © 2013–2015 Apache Software Foundation. All rights reserved.