org.multiverse.stms.gamma.transactions

## Class GammaTxn

- java.lang.Object
- - org.multiverse.stms.gamma.transactions.GammaTxn

All Implemented Interfaces:
  Txn, MultiverseConstants, GammaConstants

Direct Known Subclasses:
  FatFixedLengthGammaTxn, FatMonoGammaTxn, FatVariableLengthGammaTxn, LeanFixedLengthGammaTxn, LeanMonoGammaTxn

    public abstract class GammaTxn
    extends java.lang.Object
    implements GammaConstants, Txn

Abstract GammaTxn to be used by all the concrete GammaTxn implementations.

### Field Summary

Fields
`boolean` `abortOnly`
`int` `attempt`
`boolean` `commitConflict`
`GammaTxnConfig` `config`
`boolean` `evaluatingCommute`
`boolean` `hasWrites`
`java.util.ArrayList<TxnListener>` `listeners`
`GammaObjectPool` `pool`
`long` `remainingTimeoutNs`
`RetryLatch` `retryListener`
`boolean` `richmansMansConflictScan`
`int` `status`
`int` `transactionType`

### Fields inherited from interface org.multiverse.stms.gamma.GammaConstants

`FAILURE, MASK_CONFLICT, MASK_SUCCESS, MASK_UNREGISTERED, REGISTRATION_DONE, REGISTRATION_NONE, REGISTRATION_NOT_NEEDED, TRANLOCAL_COMMUTING, TRANLOCAL_CONSTRUCTING, TRANLOCAL_READ, TRANLOCAL_WRITE, TRANSACTIONTYPE_FAT_FIXED_LENGTH, TRANSACTIONTYPE_FAT_MONO, TRANSACTIONTYPE_FAT_VARIABLE_LENGTH, TRANSACTIONTYPE_LEAN_FIXED_LENGTH, TRANSACTIONTYPE_LEAN_MONO, TX_ABORTED, TX_ACTIVE, TX_COMMITTED, TX_PREPARED, TYPE_BOOLEAN, TYPE_DOUBLE, TYPE_INT, TYPE_LONG, TYPE_REF, VERSION_UNCOMMITTED`

### Fields inherited from interface org.multiverse.MultiverseConstants

`LOCKMODE_EXCLUSIVE, LOCKMODE_NONE, LOCKMODE_READ, LOCKMODE_WRITE, SHAKE_BUGS, SPIN_YIELD, TRACING_ENABLED`

### Constructor Summary

Constructors
Constructor and Description
`GammaTxn(GammaTxnConfig config, int transactionType)`

### Method Summary

Methods
`abstract void` `abort()` Aborts this Txn.
`java.lang.NullPointerException` `abortAcquireOnNullLockMode(GammaObject o)`
`AbortOnlyException` `abortCommitOnAbortOnly()`
`IllegalTxnStateException` `abortCommitOnBadStatus()`
`IllegalTxnStateException` `abortCommuteOnBadStatus(GammaObject object, Function function)`
`StmMismatchException` `abortCommuteOnBadStm(GammaObject object)`
`SpeculativeConfigurationError` `abortCommuteOnCommuteDetected(BaseGammaTxnRef ref)`
`java.lang.NullPointerException` `abortCommuteOnNullFunction(GammaObject object)`
`ReadonlyException` `abortCommuteOnReadonly(GammaObject object)`
`IllegalTxnStateException` `abortEnsureOnBadStatus(BaseGammaTxnRef o)`
`SpeculativeConfigurationError` `abortEnsureOnEnsureDetected(GammaObject o)`
`void` `abortIfAlive()`
`IllegalTxnStateException` `abortLocateOnBadStatus(GammaObject object)`
`java.lang.NullPointerException` `abortLocateOnNullArgument()`
`TxnExecutionException` `abortOnOpenForCommuteWhileEvaluatingCommute(GammaObject o)`
`TxnExecutionException` `abortOnOpenForConstructionWhileEvaluatingCommute(GammaObject o)`
`TxnExecutionException` `abortOnOpenForReadWhileEvaluatingCommute(GammaObject o)`
`ReadWriteConflict` `abortOnReadWriteConflict(GammaObject object)`
`SpeculativeConfigurationError` `abortOnRichmanConflictScanDetected()`
`SpeculativeConfigurationError` `abortOnTransactionTooSmall(int minimalSize)`
`java.lang.IllegalArgumentException` `abortOpenForConstructionOnBadReference(GammaObject ref)`
`IllegalTxnStateException` `abortOpenForConstructionOnBadStatus(GammaObject o)`
`StmMismatchException` `abortOpenForConstructionOnBadStm(GammaObject o)`
`ReadonlyException` `abortOpenForConstructionOnReadonly(GammaObject o)`
`SpeculativeConfigurationError` `abortOpenForConstructionRequired(BaseGammaTxnRef ref)`
`IllegalTxnStateException` `abortOpenForReadOnBadStatus(GammaObject object)`
`StmMismatchException` `abortOpenForReadOnBadStm(GammaObject o)`
`SpeculativeConfigurationError` `abortOpenForReadOnNonRefTypeDetected(BaseGammaTxnRef ref)`
`IllegalTxnStateException` `abortOpenForReadOnNullLockMode(BaseGammaTxnRef object)`
`SpeculativeConfigurationError` `abortOpenForReadOrWriteOnExplicitLockingDetected(BaseGammaTxnRef ref)`
`ReadonlyException` `abortOpenForWriteOnReadonly(GammaObject object)`
`AbortOnlyException` `abortPrepareOnAbortOnly()`
`IllegalTxnStateException` `abortPrepareOnBadStatus()`
`SpeculativeConfigurationError` `abortRegisterOnListenerRequired()`
`IllegalTxnStateException` `abortRetryOnBadStatus()`
`RetryNotAllowedException` `abortRetryOnNoBlockingAllowed()`
`IllegalTxnStateException` `abortRetryOnNoRetryPossible()`
`void` `awaitUpdate()`
`abstract void` `commit()` Commits this Txn.
`void` `copyForSpeculativeFailure(GammaTxn failingTx)`
`DeadTxnException` `failAbortOnAlreadyCommitted()`
`int` `getAttempt()` Gets the current attempt (so the number of tries this transaction already had).
`GammaTxnConfig` `getConfig()` Returns the TxnConfig used by this Txn.
`abstract Tranlocal` `getRefTranlocal(BaseGammaTxnRef ref)` Gets the Tranlocal for a specific AbstractGammaTxnRef.
`long` `getRemainingTimeoutNs()` Gets the remaining timeout in nanoseconds.
`TxnStatus` `getStatus()` Returns the status of this Txn.
`abstract void` `hardReset()` Does a hard reset of an aborted/committed transaction.
`boolean` `hasWrites()`
`void` `init(GammaTxnConfig config)`
`abstract void` `initLocalConflictCounter()` Initializes the local conflict counter if the transaction has a need for it.
`boolean` `isAbortOnly()` Checks if this Txn is abort only (so will always fail when committing or preparing).
`boolean` `isAlive()`
`boolean` `isLean()`
`abstract boolean` `isReadConsistent(Tranlocal justAdded)`
`abstract Tranlocal` `locate(BaseGammaTxnRef o)`
`protected RetryError` `newRetryError()`
`protected void` `notifyListeners(TxnEvent event)`
`void` `register(TxnListener listener)` Registers a TxnListener.
`void` `setAbortOnly()` Signals that the only possible outcome of the Txn is one that aborts.
`boolean` `skipPrepare()`
`abstract boolean` `softReset()` Does a soft reset of an aborted/committed transaction.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.multiverse.api.Txn

`prepare, retry`

### Field Detail

#### pool

    public final GammaObjectPool pool

#### status

    public int status

#### config

    public GammaTxnConfig config

#### attempt

    public int attempt

#### remainingTimeoutNs

    public long remainingTimeoutNs

#### hasWrites

    public boolean hasWrites

#### transactionType

    public final int transactionType

#### richmansMansConflictScan

    public boolean richmansMansConflictScan

#### abortOnly

    public boolean abortOnly

#### retryListener

    public final RetryLatch retryListener

#### listeners

    public java.util.ArrayList<TxnListener> listeners

#### commitConflict

    public boolean commitConflict

#### evaluatingCommute

    public boolean evaluatingCommute

### Constructor Detail

#### GammaTxn

    public GammaTxn(GammaTxnConfig config,
            int transactionType)

### Method Detail

#### notifyListeners

    protected void notifyListeners(TxnEvent event)

#### newRetryError

    protected RetryError newRetryError()

#### isLean

    public final boolean isLean()

#### abortIfAlive

    public final void abortIfAlive()

#### abortPrepareOnAbortOnly

    public AbortOnlyException abortPrepareOnAbortOnly()

#### abortCommitOnAbortOnly

    public AbortOnlyException abortCommitOnAbortOnly()

#### abortOnReadWriteConflict

    public final ReadWriteConflict abortOnReadWriteConflict(GammaObject object)

#### failAbortOnAlreadyCommitted

    public DeadTxnException failAbortOnAlreadyCommitted()

#### abortOpenForReadOrWriteOnExplicitLockingDetected

    public SpeculativeConfigurationError abortOpenForReadOrWriteOnExplicitLockingDetected(BaseGammaTxnRef ref)

#### abortOpenForReadOnNonRefTypeDetected

    public SpeculativeConfigurationError abortOpenForReadOnNonRefTypeDetected(BaseGammaTxnRef ref)

#### abortOpenForReadOnBadStm

    public final StmMismatchException abortOpenForReadOnBadStm(GammaObject o)

#### abortOpenForReadOnNullLockMode

    public IllegalTxnStateException abortOpenForReadOnNullLockMode(BaseGammaTxnRef object)

#### abortOpenForReadOnBadStatus

    public final IllegalTxnStateException abortOpenForReadOnBadStatus(GammaObject object)

#### abortOpenForWriteOnReadonly

    public final ReadonlyException abortOpenForWriteOnReadonly(GammaObject object)

#### abortRetryOnNoRetryPossible

    public final IllegalTxnStateException abortRetryOnNoRetryPossible()

#### abortRetryOnNoBlockingAllowed

    public final RetryNotAllowedException abortRetryOnNoBlockingAllowed()

#### abortRetryOnBadStatus

    public final IllegalTxnStateException abortRetryOnBadStatus()

#### abortOpenForConstructionOnBadReference

    public final java.lang.IllegalArgumentException abortOpenForConstructionOnBadReference(GammaObject ref)

#### abortOpenForConstructionOnBadStatus

    public final IllegalTxnStateException abortOpenForConstructionOnBadStatus(GammaObject o)

#### abortOpenForConstructionOnBadStm

    public final StmMismatchException abortOpenForConstructionOnBadStm(GammaObject o)

#### abortOpenForConstructionOnReadonly

    public ReadonlyException abortOpenForConstructionOnReadonly(GammaObject o)

#### abortOpenForConstructionRequired

    public SpeculativeConfigurationError abortOpenForConstructionRequired(BaseGammaTxnRef ref)

#### abortCommuteOnCommuteDetected

    public SpeculativeConfigurationError abortCommuteOnCommuteDetected(BaseGammaTxnRef ref)

#### abortCommuteOnBadStatus

    public IllegalTxnStateException abortCommuteOnBadStatus(GammaObject object,
                                                   Function function)

#### abortCommuteOnBadStm

    public StmMismatchException abortCommuteOnBadStm(GammaObject object)

#### abortCommuteOnReadonly

    public ReadonlyException abortCommuteOnReadonly(GammaObject object)

#### abortCommuteOnNullFunction

    public java.lang.NullPointerException abortCommuteOnNullFunction(GammaObject object)

#### abortLocateOnBadStatus

    public final IllegalTxnStateException abortLocateOnBadStatus(GammaObject object)

#### abortLocateOnNullArgument

    public final java.lang.NullPointerException abortLocateOnNullArgument()

#### abortRegisterOnListenerRequired

    public SpeculativeConfigurationError abortRegisterOnListenerRequired()

#### abortPrepareOnBadStatus

    public final IllegalTxnStateException abortPrepareOnBadStatus()

#### abortCommitOnBadStatus

    public final IllegalTxnStateException abortCommitOnBadStatus()

#### abortOnOpenForConstructionWhileEvaluatingCommute

    public TxnExecutionException abortOnOpenForConstructionWhileEvaluatingCommute(GammaObject o)

#### abortOnOpenForReadWhileEvaluatingCommute

    public TxnExecutionException abortOnOpenForReadWhileEvaluatingCommute(GammaObject o)

#### abortOnOpenForCommuteWhileEvaluatingCommute

    public TxnExecutionException abortOnOpenForCommuteWhileEvaluatingCommute(GammaObject o)

#### abortEnsureOnBadStatus

    public IllegalTxnStateException abortEnsureOnBadStatus(BaseGammaTxnRef o)

#### abortOnTransactionTooSmall

    public final SpeculativeConfigurationError abortOnTransactionTooSmall(int minimalSize)

#### abortOnRichmanConflictScanDetected

    public final SpeculativeConfigurationError abortOnRichmanConflictScanDetected()

#### abortEnsureOnEnsureDetected

    public SpeculativeConfigurationError abortEnsureOnEnsureDetected(GammaObject o)

#### abortAcquireOnNullLockMode

    public final java.lang.NullPointerException abortAcquireOnNullLockMode(GammaObject o)

#### hasWrites

    public final boolean hasWrites()

#### commit

    public abstract void commit()

Description copied from interface: `Txn`
Commits this Txn. If the Txn is:

1. active: it is prepared for commit and then committed
2. prepared: it is committed. Once it is prepared, the commit is guaranteed to succeed.
3. aborted: a DeadTxnException is thrown
4. committed: the call is ignored

Txn will always be aborted if the commit does not succeed.

Commit will not throw a `ReadWriteConflict` after the transaction is prepared. So if prepared successfully, a commit will always succeed.

If there are TxnListeners (either normal ones or permanent ones) and they thrown a `RuntimeException` or `Error`, this will be re-thrown. If a listener fails after the prepare/commit the transaction still is committed.

Specified by:
  `commit` in interface `Txn`

#### abort

    public abstract void abort()

Description copied from interface: `Txn`
Aborts this Txn. This means that the changes made in this transaction are not committed. It depends on the implementation if this operation is simple (ditching objects for example), or if changes need to be rolled back. If an exception is thrown while executing the abort, the transaction is still aborted. And example of such a situation is a pre-abort task that fails. So the transaction always is aborted (unless it is committed).

If the Txn already is aborted, the call is ignored.

Specified by:
  `abort` in interface `Txn`

#### locate

    public abstract Tranlocal locate(BaseGammaTxnRef o)

#### getConfig

    public final GammaTxnConfig getConfig()

Description copied from interface: `Txn`
Returns the TxnConfig used by this Txn.

Because the Txn can be reused, the TxnConfig used by this Txn doesn't need to be constant.

Specified by:
  `getConfig` in interface `Txn`
Returns:
  the TxnConfig.

#### getAttempt

    public final int getAttempt()

Description copied from interface: `Txn`
Gets the current attempt (so the number of tries this transaction already had). Value will always be equal or larger than 1 (the first attempt returns 1). The maximum number of attempts for retrying is determined based on the `TxnConfig.getMaxRetries()`

Specified by:
  `getAttempt` in interface `Txn`
Returns:
  the current attempt.

#### getRemainingTimeoutNs

    public final long getRemainingTimeoutNs()

Description copied from interface: `Txn`
Gets the remaining timeout in nanoseconds. Long.MAX_VALUE indicates that no timeout is used.

The remaining timeout only is decreased if a transaction blocks on a retry or when doing a backoff.

Specified by:
  `getRemainingTimeoutNs` in interface `Txn`
Returns:
  the remaining timeout.

#### isAbortOnly

    public boolean isAbortOnly()

Description copied from interface: `Txn`
Checks if this Txn is abort only (so will always fail when committing or preparing).

This method is not threadsafe, so can only be called by the thread that used the transaction.

Specified by:
  `isAbortOnly` in interface `Txn`
Returns:
  true if abort only, false otherwise.

#### setAbortOnly

    public final void setAbortOnly()

Description copied from interface: `Txn`
Signals that the only possible outcome of the Txn is one that aborts. When the transaction prepares or commits it checks if the transaction is marked as abort only. If so, it will automatically aborted and an `AbortOnlyException` is thrown.

This method is not threadsafe, so can only be called by the thread that used the transaction.

Specified by:
  `setAbortOnly` in interface `Txn`

#### register

    public void register(TxnListener listener)

Description copied from interface: `Txn`
Registers a TxnListener. Every time a transaction is retried, the listener needs to be registered again if you want the task to be executed again. If you want a permanent listener, have a look at the `TxnFactoryBuilder.addPermanentListener(org.multiverse.api.lifecycle.TxnListener)`.

If a TxnListener is added more than once, it is executed more than once. No checks are made. The permanent listeners are executed in the order they are added.

If a TxnListener throws an Error/RuntimeException and the transaction still is alive, it is aborted. For compensating and deferred actions this is not an issue, but for the PrePrepare state or the state it could since the transaction is aborted.

Specified by:
  `register` in interface `Txn`
Parameters:
  `listener` - the listener to add.

#### hardReset

    public abstract void hardReset()

Does a hard reset of an aborted/committed transaction. This means that it is made ready to be used by another transaction configuration.

#### softReset

    public abstract boolean softReset()

Does a soft reset of an aborted/committed transaction. This method is called when the execution of a transaction fails, but needs to be retried again.

Returns:
  if another attempt can be made, false otherwise.

#### getRefTranlocal

    public abstract Tranlocal getRefTranlocal(BaseGammaTxnRef ref)

Gets the Tranlocal for a specific AbstractGammaTxnRef. This method doesn't care about the state of a transaction.

Parameters:
  `ref` - the AbstractGammaTxnRef
Returns:
  the found Tranlocal or null if not found.

#### isAlive

    public final boolean isAlive()

#### awaitUpdate

    public final void awaitUpdate()

#### copyForSpeculativeFailure

    public final void copyForSpeculativeFailure(GammaTxn failingTx)

#### init

    public final void init(GammaTxnConfig config)

#### isReadConsistent

    public abstract boolean isReadConsistent(Tranlocal justAdded)

#### getStatus

    public final TxnStatus getStatus()

Description copied from interface: `Txn`
Returns the status of this Txn.

Specified by:
  `getStatus` in interface `Txn`
Returns:
  the status of this Txn.

#### skipPrepare

    public final boolean skipPrepare()

#### initLocalConflictCounter

    public abstract void initLocalConflictCounter()

Initializes the local conflict counter if the transaction has a need for it. It should only be initialized if there are no reads.