Class AbstractThreadedTransaction
- java.lang.Object
-
- org.apache.tinkerpop.gremlin.structure.util.AbstractTransaction
-
- org.apache.tinkerpop.gremlin.structure.util.AbstractThreadedTransaction
-
- All Implemented Interfaces:
AutoCloseable
,Transaction
public abstract class AbstractThreadedTransaction extends AbstractTransaction
A base implementation ofTransaction
that provides core functionality for transaction listeners using a shared set of transaction listeners. Therefore, whenAbstractTransaction.commit()
is called from any thread, all listeners get notified. This implementation would be useful for graph implementations that support threaded transactions, specifically in theGraph
instance returned fromTransaction.createThreadedTx()
.- Author:
- Stephen Mallette (http://stephen.genoprime.com)
- See Also:
AbstractThreadLocalTransaction
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.tinkerpop.gremlin.structure.Transaction
Transaction.CLOSE_BEHAVIOR, Transaction.Exceptions, Transaction.READ_WRITE_BEHAVIOR, Transaction.Status
-
-
Field Summary
Fields Modifier and Type Field Description protected List<Consumer<Transaction.Status>>
transactionListeners
-
Fields inherited from interface org.apache.tinkerpop.gremlin.structure.Transaction
NO_OP
-
-
Constructor Summary
Constructors Constructor Description AbstractThreadedTransaction(Graph g)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.protected void
doClose()
Clears transaction listenersprotected void
doReadWrite()
Threaded transactions should be open immediately upon creation so most implementations should do nothing with this method.protected void
fireOnCommit()
Called withinAbstractTransaction.commit()
just after the internal call toAbstractTransaction.doCommit()
.protected void
fireOnRollback()
Called withinAbstractTransaction.rollback()
just after the internal call toAbstractTransaction.doRollback()
()}.Transaction
onClose(Consumer<Transaction> consumer)
The nature of threaded transactions are such that they are always open when created and manual in nature, therefore setting this value is not required.Transaction
onReadWrite(Consumer<Transaction> consumer)
The nature of threaded transactions are such that they are always open when created and manual in nature, therefore setting this value is not required.void
removeTransactionListener(Consumer<Transaction.Status> listener)
Removes a transaction listener.-
Methods inherited from class org.apache.tinkerpop.gremlin.structure.util.AbstractTransaction
begin, close, commit, createThreadedTx, doCommit, doOpen, doRollback, open, readWrite, rollback
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.tinkerpop.gremlin.structure.Transaction
begin, isOpen
-
-
-
-
Field Detail
-
transactionListeners
protected final List<Consumer<Transaction.Status>> transactionListeners
-
-
Constructor Detail
-
AbstractThreadedTransaction
public AbstractThreadedTransaction(Graph g)
-
-
Method Detail
-
fireOnCommit
protected void fireOnCommit()
Description copied from class:AbstractTransaction
Called withinAbstractTransaction.commit()
just after the internal call toAbstractTransaction.doCommit()
. Implementations of this method should raiseTransaction.Status.COMMIT
events to any listeners added viaTransaction.addTransactionListener(Consumer)
.- Specified by:
fireOnCommit
in classAbstractTransaction
-
fireOnRollback
protected void fireOnRollback()
Description copied from class:AbstractTransaction
Called withinAbstractTransaction.rollback()
just after the internal call toAbstractTransaction.doRollback()
()}. Implementations of this method should raiseTransaction.Status.ROLLBACK
events to any listeners added viaTransaction.addTransactionListener(Consumer)
.- Specified by:
fireOnRollback
in classAbstractTransaction
-
addTransactionListener
public void addTransactionListener(Consumer<Transaction.Status> listener)
Description copied from interface:Transaction
Adds a listener that is called back with a status when a commit or rollback is successful. It is expected that listeners be bound to the current thread as is standard for transactions. Therefore a listener registered in the current thread will not get callback events from a commit or rollback call in a different thread.
-
removeTransactionListener
public void removeTransactionListener(Consumer<Transaction.Status> listener)
Description copied from interface:Transaction
Removes a transaction listener.
-
clearTransactionListeners
public void clearTransactionListeners()
Description copied from interface:Transaction
Removes all transaction listeners.
-
doReadWrite
protected void doReadWrite()
Threaded transactions should be open immediately upon creation so most implementations should do nothing with this method.- Specified by:
doReadWrite
in classAbstractTransaction
-
doClose
protected void doClose()
Clears transaction listeners- Specified by:
doClose
in classAbstractTransaction
-
onReadWrite
public Transaction onReadWrite(Consumer<Transaction> consumer)
The nature of threaded transactions are such that they are always open when created and manual in nature, therefore setting this value is not required.- Throws:
UnsupportedOperationException
-
onClose
public Transaction onClose(Consumer<Transaction> consumer)
The nature of threaded transactions are such that they are always open when created and manual in nature, therefore setting this value is not required.- Throws:
UnsupportedOperationException
-
-