org.apache.tinkerpop.gremlin.structure.util

## Class AbstractThreadLocalTransaction

- java.lang.Object
- - org.apache.tinkerpop.gremlin.structure.util.AbstractTransaction
  - - org.apache.tinkerpop.gremlin.structure.util.AbstractThreadLocalTransaction

- All Implemented Interfaces:
    AutoCloseable, Transaction

      public abstract class AbstractThreadLocalTransaction
      extends AbstractTransaction

  A base implementation of `Transaction` that provides core functionality for transaction listeners using `ThreadLocal`. In this implementation, the listeners are bound to the current thread of execution (usually the same as the transaction for most graph database implementations). Therefore, when `AbstractTransaction.commit()` is called on a particular thread, the only listeners that get notified are those bound to that thread.
  Author:
    Stephen Mallette (http://stephen.genoprime.com)
  See Also:
    `AbstractThreadedTransaction`

- - ### 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 and Description
    --- | ---
    `protected ThreadLocal<Consumer<Transaction>>` | `closeConsumerInternal`
    `protected ThreadLocal<Consumer<Transaction>>` | `readWriteConsumerInternal`
    `protected ThreadLocal<List<Consumer<Transaction.Status>>>` | `transactionListeners`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractThreadLocalTransaction(Graph g)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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.
    `protected void` | `doClose()` Called `AbstractTransaction.close()`.
    `protected void` | `doReadWrite()` Called `AbstractTransaction.readWrite()`.
    `protected void` | `fireOnCommit()` Called within `AbstractTransaction.commit()` just after the internal call to `AbstractTransaction.doCommit()`.
    `protected void` | `fireOnRollback()` Called within `AbstractTransaction.rollback()` just after the internal call to `AbstractTransaction.doRollback()` ()}.
    `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` | `removeTransactionListener(Consumer<Transaction.Status> listener)` Removes a transaction listener.

    - ### Methods inherited from class org.apache.tinkerpop.gremlin.structure.util.AbstractTransaction

      `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

      `isOpen`

- - ### Field Detail

    - #### readWriteConsumerInternal

          protected final ThreadLocal<Consumer<Transaction>> readWriteConsumerInternal

    - #### closeConsumerInternal

          protected final ThreadLocal<Consumer<Transaction>> closeConsumerInternal

    - #### transactionListeners

          protected final ThreadLocal<List<Consumer<Transaction.Status>>> transactionListeners

  - ### Constructor Detail

    - #### AbstractThreadLocalTransaction

          public AbstractThreadLocalTransaction(Graph g)

  - ### Method Detail

    - #### fireOnCommit

          protected void fireOnCommit()

      Description copied from class: `AbstractTransaction`
      Called within `AbstractTransaction.commit()` just after the internal call to `AbstractTransaction.doCommit()`. Implementations of this method should raise `Transaction.Status.COMMIT` events to any listeners added via `Transaction.addTransactionListener(Consumer)`.
      Specified by:
        `fireOnCommit` in class `AbstractTransaction`

    - #### fireOnRollback

          protected void fireOnRollback()

      Description copied from class: `AbstractTransaction`
      Called within `AbstractTransaction.rollback()` just after the internal call to `AbstractTransaction.doRollback()` ()}. Implementations of this method should raise `Transaction.Status.ROLLBACK` events to any listeners added via `Transaction.addTransactionListener(Consumer)`.
      Specified by:
        `fireOnRollback` in class `AbstractTransaction`

    - #### 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()

      Description copied from class: `AbstractTransaction`
      Called `AbstractTransaction.readWrite()`. Implementers should run their readWrite consumer here.
      Specified by:
        `doReadWrite` in class `AbstractTransaction`

    - #### doClose

          protected void doClose()

      Description copied from class: `AbstractTransaction`
      Called `AbstractTransaction.close()`. Implementers should run their readWrite consumer here.
      Specified by:
        `doClose` in class `AbstractTransaction`

    - #### onReadWrite

          public Transaction onReadWrite(Consumer<Transaction> consumer)

      Description copied from interface: `Transaction`
      Describes how a transaction is started when a read or a write occurs. This value can be set using standard behaviors defined in `Transaction.READ_WRITE_BEHAVIOR` or a mapper `Consumer` function.

    - #### onClose

          public Transaction onClose(Consumer<Transaction> consumer)

      Description copied from interface: `Transaction`
      Describes what happens to a transaction on a call to `Graph.close()`. This value can be set using standard behavior defined in `Transaction.CLOSE_BEHAVIOR` or a mapper `Consumer` function.

Copyright © 2013–2022 Apache Software Foundation. All rights reserved.