All Implemented Interfaces:
Lock, TxnLong, TxnObject, MultiverseConstants, GammaConstants, GammaObject

public class GammaTxnLong extends BaseGammaTxnRef implements TxnLong
A TxnLong for the GammaStm.
  • Constructor Details

    • GammaTxnLong

      public GammaTxnLong(long value)
    • GammaTxnLong

      public GammaTxnLong(GammaStm stm)
    • GammaTxnLong

      public GammaTxnLong(GammaStm stm, long initialValue)
    • GammaTxnLong

      public GammaTxnLong(GammaTxn tx)
    • GammaTxnLong

      public GammaTxnLong(GammaTxn tx, long value)
  • Method Details

    • get

      public final long get()
      Description copied from interface: TxnLong
      Gets the value using the provided txn.
      Specified by:
      get in interface TxnLong
      Returns:
      the current value.
      See Also:
    • get

      public final long get(Txn tx)
      Description copied from interface: TxnLong
      Gets the value using the provided txn.
      Specified by:
      get in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      Returns:
      the value stored in the ref.
    • get

      public final long get(GammaTxn tx)
    • getAndLock

      public final long getAndLock(LockMode lockMode)
      Description copied from interface: TxnLong
      Gets the value and applies the lock. If the current lockMode already is higher than the provided lockMode the Lock is not upgraded to a higher value.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      getAndLock in interface TxnLong
      Parameters:
      lockMode - the LockMode applied.
      Returns:
      the current value.
      See Also:
    • getAndLock

      public final long getAndLock(Txn tx, LockMode lockMode)
      Description copied from interface: TxnLong
      Gets the value using the provided txn and acquired the lock with the specified LockMode.
      Specified by:
      getAndLock in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      lockMode - the LockMode used
      Returns:
      the value stored in the ref.
    • getAndLock

      public final long getAndLock(GammaTxn tx, LockMode lockMode)
    • set

      public final long set(long value)
      Description copied from interface: TxnLong
      Sets the new value.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      set in interface TxnLong
      Parameters:
      value - the new value.
      Returns:
      the new value.
    • set

      public final long set(Txn tx, long value)
      Description copied from interface: TxnLong
      Sets the new value using the provided txn.
      Specified by:
      set in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      value - the new value
      Returns:
      the old value
    • set

      public final long set(GammaTxn tx, long value)
    • setAndLock

      public final long setAndLock(long value, LockMode lockMode)
      Description copied from interface: TxnLong
      Sets the new value and applies the lock.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      setAndLock in interface TxnLong
      Parameters:
      value - the new value.
      lockMode - the used LockMode.
      Returns:
      the new value.
    • setAndLock

      public final long setAndLock(Txn tx, long value, LockMode lockMode)
      Description copied from interface: TxnLong
      Sets the new value using the provided txn.
      Specified by:
      setAndLock in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      value - the new value
      lockMode - the lockMode used.
      Returns:
      the old value
    • setAndLock

      public final long setAndLock(GammaTxn tx, long value, LockMode lockMode)
    • getAndSet

      public final long getAndSet(long value)
      Description copied from interface: TxnLong
      Sets the value the value and returns the new value.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      getAndSet in interface TxnLong
      Parameters:
      value - the new value.
      Returns:
      the old value.
    • getAndSet

      public final long getAndSet(Txn tx, long value)
      Description copied from interface: TxnLong
      Sets the value using the provided txn.
      Specified by:
      getAndSet in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      value - the new value.
      Returns:
      the old value.
    • getAndSet

      public final long getAndSet(GammaTxn tx, long value)
    • getAndSetAndLock

      public final long getAndSetAndLock(long value, LockMode lockMode)
      Description copied from interface: TxnLong
      Sets the value, acquired the Lock with the specified Lockmode and returns the previous value.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      getAndSetAndLock in interface TxnLong
      Parameters:
      value - the new value.
      lockMode - the LockMode used.
      Returns:
      the old value.
    • getAndSetAndLock

      public final long getAndSetAndLock(Txn tx, long value, LockMode lockMode)
      Description copied from interface: TxnLong
      Sets the value and acquired the Lock with the provided LockMode.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      getAndSetAndLock in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      value - the new value.
      lockMode - the LockMode used.
      Returns:
      the old value.
    • getAndSetLock

      public final long getAndSetLock(GammaTxn tx, long value, LockMode lockMode)
    • atomicGet

      public final long atomicGet()
      Description copied from interface: TxnLong
      Atomically gets the value. The value could be stale as soon as it is returned. This method doesn't care about any running txns. It could be that this call fails e.g. when a ref is locked. If you don't care about correct orderings, see the TxnLong.atomicWeakGet().
      Specified by:
      atomicGet in interface TxnLong
      Returns:
      the current value.
    • atomicWeakGet

      public final long atomicWeakGet()
      Description copied from interface: TxnLong
      Atomically gets the value without providing any ordering guarantees. This method is extremely cheap and will never fail. So even if the ref is privatized, this call will still complete.

      It is the best method to call if you just want to get the current value stored.

      Specified by:
      atomicWeakGet in interface TxnLong
      Returns:
      the value.
    • atomicSet

      public final long atomicSet(long newValue)
      Description copied from interface: TxnLong
      Atomically sets the value and returns the new value. This method doesn't care about any running txns.
      Specified by:
      atomicSet in interface TxnLong
      Parameters:
      newValue - the new value.
      Returns:
      the new value.
    • atomicGetAndSet

      public final long atomicGetAndSet(long newValue)
      Description copied from interface: TxnLong
      Atomically sets the value and returns the previous value. This method doesn't care about any running txns.
      Specified by:
      atomicGetAndSet in interface TxnLong
      Parameters:
      newValue - the new value.
      Returns:
      the old value.
    • commute

      public final void commute(LongFunction function)
      Description copied from interface: TxnLong
      Applies the function on the ref in a commuting manner. So if there are no dependencies, the function will commute. If somehow there already is a dependency or a dependency is formed on the result of the commuting function, the function will not commute and will be exactly the same as an alter.

      This is different than the behavior in Clojure where the commute will be re-applied at the end of the txn, even though some dependency is introduced, which can lead to inconsistencies.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      commute in interface TxnLong
      Parameters:
      function - the function to apply to this reference.
    • commute

      public final void commute(Txn tx, LongFunction function)
      Description copied from interface: TxnLong
      Applies the function on the ref in a commuting manner. So if there are no dependencies, the function will commute. If somehow there already is a dependency or a dependency is formed on the result of the commuting function, the function will not commute and will be exactly the same as an alter.

      This is different than the behavior in Clojure where the commute will be re-applied at the end of the txn, even though some dependency is introduced, which can lead to inconsistencies.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      commute in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      function - the function to apply to this reference.
    • commute

      public final void commute(GammaTxn tx, LongFunction function)
    • atomicAlterAndGet

      public final long atomicAlterAndGet(LongFunction function)
      Description copied from interface: TxnLong
      Atomically applies the function to the current value in this ref and returns the new value. This method doesn't care about any running txns.
      Specified by:
      atomicAlterAndGet in interface TxnLong
      Parameters:
      function - the Function used
      Returns:
      the new value.
    • atomicAlter

      private long atomicAlter(LongFunction function, boolean returnOld)
    • alterAndGet

      public final long alterAndGet(LongFunction function)
      Description copied from interface: TxnLong
      Alters the value stored in this Ref using the provided function and returns the result.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      alterAndGet in interface TxnLong
      Parameters:
      function - the function that alters the value stored in this Ref.
      Returns:
      the new value.
    • alterAndGet

      public final long alterAndGet(Txn tx, LongFunction function)
      Description copied from interface: TxnLong
      Alters the value stored in this Ref using the provided function and lifting on the provided txn.
      Specified by:
      alterAndGet in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      function - the function that alters the value stored in this Ref.
      Returns:
      the new value.
    • alterAndGet

      public final long alterAndGet(GammaTxn tx, LongFunction function)
    • atomicGetAndAlter

      public final long atomicGetAndAlter(LongFunction function)
      Description copied from interface: TxnLong
      Atomically applies the function to alter the value stored in this ref and returns the old value. This method doesn't care about any running txns.
      Specified by:
      atomicGetAndAlter in interface TxnLong
      Parameters:
      function - the Function used
      Returns:
      the old value.
    • getAndAlter

      public final long getAndAlter(LongFunction function)
      Description copied from interface: TxnLong
      Alters the value stored in this Ref using the provided function amd returns the old value.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      getAndAlter in interface TxnLong
      Parameters:
      function - the function that alters the value stored in this Ref.
      Returns:
      the old value.
    • getAndAlter

      public final long getAndAlter(Txn tx, LongFunction function)
      Description copied from interface: TxnLong
      Alters the value stored in this Ref using the function and returns the old value, using the provided txn.
      Specified by:
      getAndAlter in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      function - the function that alters the value stored in this Ref.
      Returns:
      the old value
    • getAndAlter

      public final long getAndAlter(GammaTxn tx, LongFunction function)
    • alter

      private long alter(GammaTxn tx, LongFunction function, boolean returnOld)
    • atomicCompareAndSet

      public final boolean atomicCompareAndSet(long expectedValue, long newValue)
      Description copied from interface: TxnLong
      Executes a compare and set atomically. This method doesn't care about any running txns.
      Specified by:
      atomicCompareAndSet in interface TxnLong
      Parameters:
      expectedValue - the expected value.
      newValue - the new value.
      Returns:
      true if the compareAndSwap was a success, false otherwise.
    • atomicGetAndIncrement

      public final long atomicGetAndIncrement(long amount)
      Description copied from interface: TxnLong
      Atomically increments the value and returns the old value. This method doesn't care about any running txns.
      Specified by:
      atomicGetAndIncrement in interface TxnLong
      Parameters:
      amount - the amount to increase with.
      Returns:
      the old value.
    • getAndIncrement

      public final long getAndIncrement(long amount)
      Description copied from interface: TxnLong
      Increments the value and returns the old value.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      getAndIncrement in interface TxnLong
      Parameters:
      amount - the amount to increment with.
      Returns:
      the old value.
    • getAndIncrement

      public final long getAndIncrement(Txn tx, long amount)
      Description copied from interface: TxnLong
      Increments the value and returns the old value using the provided txn.
      Specified by:
      getAndIncrement in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      amount - the amount to increment with.
      Returns:
      the old value.
    • getAndIncrement

      public final long getAndIncrement(GammaTxn tx, long amount)
    • atomicIncrementAndGet

      public final long atomicIncrementAndGet(long amount)
      Description copied from interface: TxnLong
      Atomically increments the value and returns the old value. This method doesn't care about any running txns.
      Specified by:
      atomicIncrementAndGet in interface TxnLong
      Parameters:
      amount - the amount to increment with.
      Returns:
      the new value.
    • incrementAndGet

      public final long incrementAndGet(long amount)
      Description copied from interface: TxnLong
      Increments and gets the new value.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      incrementAndGet in interface TxnLong
      Parameters:
      amount - the amount to increment with.
      Returns:
      the new value.
    • incrementAndGet

      public final long incrementAndGet(Txn tx, long amount)
      Description copied from interface: TxnLong
      Increments and gets the new value using the provided txn.
      Specified by:
      incrementAndGet in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      amount - the amount to increment with.
      Returns:
      the new value.
    • incrementAndGet

      public final long incrementAndGet(GammaTxn tx, long amount)
    • increment

      public final void increment()
      Description copied from interface: TxnLong
      Increments the value by one.

      This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return value.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      increment in interface TxnLong
    • increment

      public final void increment(Txn tx)
      Description copied from interface: TxnLong
      Increments the value by one using the provided txn.

      This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return value.

      Specified by:
      increment in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
    • increment

      public final void increment(GammaTxn tx)
    • increment

      public final void increment(long amount)
      Description copied from interface: TxnLong
      Increments the value by the given amount.

      This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return value.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      increment in interface TxnLong
      Parameters:
      amount - the amount to increase with
    • increment

      public final void increment(Txn tx, long amount)
      Description copied from interface: TxnLong
      Increments the value by the given amount using the provided txn.

      This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return value.

      Specified by:
      increment in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      amount - the amount to increment with
    • decrement

      public final void decrement()
      Description copied from interface: TxnLong
      Decrements the value by one.

      This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return value.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      decrement in interface TxnLong
    • decrement

      public final void decrement(Txn tx)
      Description copied from interface: TxnLong
      Decrements the value by one using the provided txn.

      This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return value.

      Specified by:
      decrement in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
    • decrement

      public final void decrement(long amount)
      Description copied from interface: TxnLong
      Decrements the value by the given amount.

      This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return value.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      decrement in interface TxnLong
      Parameters:
      amount - the amount to decrement with
    • decrement

      public final void decrement(Txn tx, long amount)
      Description copied from interface: TxnLong
      Decrements the value by the given amount using the provided txn.

      This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return value.

      Specified by:
      decrement in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      amount - the amount to decrement with
    • await

      public final void await(long value)
      Description copied from interface: TxnLong
      Awaits for the value to become the given value. If the value already has the the specified value, the call continues, else a retry is done.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      await in interface TxnLong
      Parameters:
      value - the value to wait for.
    • await

      public final void await(Txn tx, long value)
      Description copied from interface: TxnLong
      Awaits for the reference to become the given value. If the value already has the the specified value, the call continues, else a retry is done.
      Specified by:
      await in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      value - the value to wait for.
    • await

      public final void await(GammaTxn tx, long value)
    • await

      public final void await(LongPredicate predicate)
      Description copied from interface: TxnLong
      Awaits until the predicate holds. If the value already evaluates to true, the call continues else a retry is done. If the predicate throws an exception, the txn is aborted and the throwable is propagated.

      This call lifts on the Txn stored in the TxnThreadLocal.

      Specified by:
      await in interface TxnLong
      Parameters:
      predicate - the predicate to evaluate.
    • await

      public final void await(Txn tx, LongPredicate predicate)
      Description copied from interface: TxnLong
      Awaits until the predicate holds using the provided txn. If the value already evaluates to true, the call continues else a retry is done. If the predicate throws an exception, the txn is aborted and the throwable is propagated.
      Specified by:
      await in interface TxnLong
      Parameters:
      tx - the Txn used for this operation.
      predicate - the predicate to evaluate.
    • await

      public final void await(GammaTxn tx, LongPredicate predicate)
    • toDebugString

      public final String toDebugString()
      Description copied from interface: TxnObject
      Returns a debug representation of the TxnObject. The data used doesn't have to be consistent, it is a best effort. This method doesn't rely on a running transaction.
      Specified by:
      toDebugString in interface TxnObject
      Returns:
      the debug representation of the TxnObject.
    • toString

      public final String toString()
      Description copied from interface: TxnObject
      Returns a String representation of the Object using the Txn on the TxnThreadLocal.
      Specified by:
      toString in interface TxnObject
      Overrides:
      toString in class Object
      Returns:
      the toString representation
    • toString

      public final String toString(Txn tx)
      Description copied from interface: TxnObject
      Returns a String representation of the object using the provided Txn.
      Specified by:
      toString in interface TxnObject
      Parameters:
      tx - the Txn used.
      Returns:
      the String representation of the object.
    • toString

      public final String toString(GammaTxn tx)
    • atomicToString

      public final String atomicToString()
      Description copied from interface: TxnObject
      Returns a String representation of the object using the provided transaction without looking at a TxnThreadLocal. The outputted value doesn't need to be consistent from some point in time, only a best effort is made.
      Specified by:
      atomicToString in interface TxnObject
      Returns:
      the String representation.