org.multiverse.stms.gamma.transactionalobjects
Class GammaTxnRef<E>

java.lang.Object
  extended by org.multiverse.stms.gamma.transactionalobjects.AbstractGammaObject
      extended by org.multiverse.stms.gamma.transactionalobjects.BaseGammaTxnRef
          extended by org.multiverse.stms.gamma.transactionalobjects.GammaTxnRef<E>
Type Parameters:
E -
All Implemented Interfaces:
Lock, TxnRef<E>, TxnObject, MultiverseConstants, GammaConstants, GammaObject

public class GammaTxnRef<E>
extends BaseGammaTxnRef
implements TxnRef<E>

A TxnRef tailored for the GammaStm.

Author:
Peter Veentjer.

Field Summary
 
Fields inherited from class org.multiverse.stms.gamma.transactionalobjects.BaseGammaTxnRef
long_value, ref_value, type
 
Fields inherited from class org.multiverse.stms.gamma.transactionalobjects.AbstractGammaObject
___unsafe, identityHashCode, listeners, listenersOffset, MASK_OREC_EXCLUSIVELOCK, MASK_OREC_READBIASED, MASK_OREC_READLOCKS, MASK_OREC_READONLY_COUNT, MASK_OREC_SURPLUS, MASK_OREC_UPDATELOCK, orec, stm, valueOffset, version
 
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
GammaTxnRef(E value)
           
GammaTxnRef(GammaStm stm)
           
GammaTxnRef(GammaStm stm, E value)
           
GammaTxnRef(GammaTxn tx)
           
GammaTxnRef(GammaTxn tx, E value)
           
 
Method Summary
 E alterAndGet(Function<E> function)
          Alters the value stored in this Ref using the provided function and returns the result.
 E alterAndGet(GammaTxn tx, Function<E> function)
           
 E alterAndGet(Txn tx, Function<E> function)
          Alters the value stored in this Ref using the provided function and lifting on the provided txn.
 E atomicAlterAndGet(Function<E> function)
          Atomically applies the function to the current value in this ref and returns the new value.
 boolean atomicCompareAndSet(E expectedValue, E newValue)
          Executes a compare and set atomically.
 E atomicGet()
          Atomically gets the value.
 E atomicGetAndAlter(Function<E> function)
          Atomically applies the function to alter the value stored in this ref and returns the old value.
 E atomicGetAndSet(E newValue)
          Atomically sets the value and returns the previous value.
 boolean atomicIsNull()
          Atomically check if the current value is null.
 E atomicSet(E newValue)
          Atomically sets the value and returns the new value.
 String atomicToString()
          Returns a String representation of the object using the provided transaction without looking at a TxnThreadLocal.
 E atomicWeakGet()
          Atomically gets the value without providing any ordering guarantees.
 void await(E value)
          Awaits for the value to become the given value.
 void await(GammaTxn tx, E value)
           
 void await(GammaTxn tx, Predicate<E> predicate)
           
 void await(Predicate<E> predicate)
          Awaits until the predicate holds.
 void await(Txn tx, E value)
          Awaits for the reference to become the given value.
 void await(Txn tx, Predicate<E> predicate)
          Awaits until the predicate holds using the provided txn.
 E awaitNotNullAndGet()
          Awaits for the value to become not null.
 E awaitNotNullAndGet(GammaTxn tx)
           
 E awaitNotNullAndGet(Txn tx)
          Awaits for the value to become not null using the provided txn.
 void awaitNull()
          Awaits for the value to become null.
 void awaitNull(GammaTxn tx)
           
 void awaitNull(Txn tx)
          Awaits for the value to become not null using the provided txn.
 void commute(Function<E> function)
          Applies the function on the ref in a commuting manner.
 void commute(GammaTxn tx, Function<E> function)
           
 void commute(Txn tx, Function<E> function)
          Applies the function on the ref in a commuting manner.
 E get()
          Gets the value using the provided txn.
 E get(GammaTxn tx)
           
 E get(Txn tx)
          Gets the value using the provided txn.
 E getAndAlter(Function<E> function)
          Alters the value stored in this Ref using the provided function amd returns the old value.
 E getAndAlter(GammaTxn tx, Function<E> function)
           
 E getAndAlter(Txn tx, Function<E> function)
          Alters the value stored in this Ref using the function and returns the old value, using the provided txn.
 E getAndLock(GammaTxn tx, LockMode lockMode)
           
 E getAndLock(LockMode lockMode)
          Gets the value and applies the lock.
 E getAndLock(Txn tx, LockMode lockMode)
          Gets the value using the provided txn and acquired the lock with the specified LockMode.
 E getAndSet(E value)
          Sets the value the value and returns the new value.
 E getAndSet(GammaTxn tx, E value)
           
 E getAndSet(Txn tx, E value)
          Sets the value using the provided txn.
 E getAndSetAndLock(E value, LockMode lockMode)
          Sets the value, acquired the Lock with the specified Lockmode and returns the previous value.
 E getAndSetAndLock(GammaTxn tx, E value, LockMode lockMode)
           
 E getAndSetAndLock(Txn tx, E value, LockMode lockMode)
          Sets the value and acquired the Lock with the provided LockMode.
 boolean isNull()
          Checks if the current value is null.
 boolean isNull(GammaTxn tx)
           
 boolean isNull(Txn tx)
          Checks if the current value is null using the provided txn.
 E set(E value)
          Sets the new value.
 E set(GammaTxn tx, E value)
           
 E set(Txn tx, E value)
          Sets the new value using the provided txn.
 E setAndLock(E value, LockMode lockMode)
          Sets the new value and applies the lock.
 E setAndLock(GammaTxn tx, E value, LockMode lockMode)
           
 E setAndLock(Txn tx, E value, LockMode lockMode)
          Sets the new value using the provided txn.
 String toDebugString()
          Returns a debug representation of the TxnObject.
 String toString()
          Returns a String representation of the Object using the Txn on the TxnThreadLocal.
 String toString(GammaTxn tx)
           
 String toString(Txn tx)
          Returns a String representation of the object using the provided Txn.
 
Methods inherited from class org.multiverse.stms.gamma.transactionalobjects.BaseGammaTxnRef
acquire, acquire, acquire, arriveAndExclusiveLockOrBackoff, atomicCompareAndSetLong, atomicGetLong, atomicObjectGet, atomicSetLong, atomicSetObject, commit, ensure, ensure, ensure, flattenCommute, getLong, getObject, hasReadConflict, leanCommit, load, openForCommute, openForCommute, openForCommute, openForCommute, openForConstruction, openForConstruction, openForConstruction, openForConstruction, openForRead, openForRead, openForRead, openForRead, openForRead, openForRead, openForWrite, openForWrite, openForWrite, openForWrite, openForWrite, openForWrite, prepare, registerChangeListener, releaseAfterFailure, releaseAfterReading, releaseAfterUpdate, setLong, setObject, tryLockAndCheckConflict
 
Methods inherited from class org.multiverse.stms.gamma.transactionalobjects.AbstractGammaObject
___removeListenersAfterWrite, ___toOrecString, arrive, arriveAndExclusiveLock, arriveAndLock, atomicGetLockMode, atomicGetLockModeAsInt, departAfterFailure, departAfterFailureAndUnlock, departAfterReading, departAfterReadingAndUnlock, departAfterUpdateAndUnlock, getLock, getLockMode, getLockMode, getLockMode, getReadBiasedThreshold, getReadLockCount, getReadLockCount, getReadonlyCount, getReadonlyCount, getStm, getSurplus, getSurplus, getVersion, hasAnyLock, hasExclusiveLock, hasExclusiveLock, hasWriteLock, hasWriteLock, hasWriteOrExclusiveLock, identityHashCode, isReadBiased, isReadBiased, lockAfterArrive, setExclusiveLock, setIsReadBiased, setReadLockCount, setReadonlyCount, setSurplus, setWriteLock, unlockByUnregistered, upgradeReadLock, upgradeWriteLock, waitForExclusiveLockToBecomeFree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.multiverse.api.TxnObject
ensure, ensure, getLock, getStm, getVersion
 

Constructor Detail

GammaTxnRef

public GammaTxnRef(E value)

GammaTxnRef

public GammaTxnRef(GammaTxn tx)

GammaTxnRef

public GammaTxnRef(GammaTxn tx,
                   E value)

GammaTxnRef

public GammaTxnRef(GammaStm stm)

GammaTxnRef

public GammaTxnRef(GammaStm stm,
                   E value)
Method Detail

get

public final E get()
Description copied from interface: TxnRef
Gets the value using the provided txn.

Specified by:
get in interface TxnRef<E>
Returns:
the current value.
See Also:
TxnRef.atomicGet()

get

public final E get(Txn tx)
Description copied from interface: TxnRef
Gets the value using the provided txn.

Specified by:
get in interface TxnRef<E>
Parameters:
tx - the Txn used for this operation.
Returns:
the value stored in the ref.

get

public final E get(GammaTxn tx)

getAndLock

public final E getAndLock(LockMode lockMode)
Description copied from interface: TxnRef
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 TxnRef<E>
Parameters:
lockMode - the LockMode applied.
Returns:
the current value.
See Also:
TxnRef.atomicGet()

getAndLock

public final E getAndLock(Txn tx,
                          LockMode lockMode)
Description copied from interface: TxnRef
Gets the value using the provided txn and acquired the lock with the specified LockMode.

Specified by:
getAndLock in interface TxnRef<E>
Parameters:
tx - the Txn used for this operation.
lockMode - the LockMode used
Returns:
the value stored in the ref.

getAndLock

public final E getAndLock(GammaTxn tx,
                          LockMode lockMode)

set

public final E set(E value)
Description copied from interface: TxnRef
Sets the new value.

This call lifts on the Txn stored in the TxnThreadLocal.

Specified by:
set in interface TxnRef<E>
Parameters:
value - the new value.
Returns:
the new value.

set

public final E set(Txn tx,
                   E value)
Description copied from interface: TxnRef
Sets the new value using the provided txn.

Specified by:
set in interface TxnRef<E>
Parameters:
tx - the Txn used for this operation.
value - the new value
Returns:
the old value

set

public final E set(GammaTxn tx,
                   E value)

setAndLock

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

This call lifts on the Txn stored in the TxnThreadLocal.

Specified by:
setAndLock in interface TxnRef<E>
Parameters:
value - the new value.
lockMode - the used LockMode.
Returns:
the new value.

setAndLock

public final E setAndLock(Txn tx,
                          E value,
                          LockMode lockMode)
Description copied from interface: TxnRef
Sets the new value using the provided txn.

Specified by:
setAndLock in interface TxnRef<E>
Parameters:
tx - the Txn used for this operation.
value - the new value
lockMode - the lockMode used.
Returns:
the old value

setAndLock

public final E setAndLock(GammaTxn tx,
                          E value,
                          LockMode lockMode)

getAndSet

public final E getAndSet(E value)
Description copied from interface: TxnRef
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 TxnRef<E>
Parameters:
value - the new value.
Returns:
the old value.

getAndSet

public final E getAndSet(Txn tx,
                         E value)
Description copied from interface: TxnRef
Sets the value using the provided txn.

Specified by:
getAndSet in interface TxnRef<E>
Parameters:
tx - the Txn used for this operation.
value - the new value.
Returns:
the old value.

getAndSet

public final E getAndSet(GammaTxn tx,
                         E value)

getAndSetAndLock

public final E getAndSetAndLock(E value,
                                LockMode lockMode)
Description copied from interface: TxnRef
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 TxnRef<E>
Parameters:
value - the new value.
lockMode - the LockMode used.
Returns:
the old value.

getAndSetAndLock

public final E getAndSetAndLock(Txn tx,
                                E value,
                                LockMode lockMode)
Description copied from interface: TxnRef
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 TxnRef<E>
Parameters:
tx - the Txn used for this operation.
value - the new value.
lockMode - the LockMode used.
Returns:
the old value.

getAndSetAndLock

public final E getAndSetAndLock(GammaTxn tx,
                                E value,
                                LockMode lockMode)

atomicGet

public final E atomicGet()
Description copied from interface: TxnRef
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 TxnRef.atomicWeakGet().

Specified by:
atomicGet in interface TxnRef<E>
Returns:
the current value.

atomicWeakGet

public final E atomicWeakGet()
Description copied from interface: TxnRef
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 TxnRef<E>
Returns:
the value.

atomicSet

public final E atomicSet(E newValue)
Description copied from interface: TxnRef
Atomically sets the value and returns the new value. This method doesn't care about any running txns.

Specified by:
atomicSet in interface TxnRef<E>
Parameters:
newValue - the new value.
Returns:
the new value.

atomicGetAndSet

public final E atomicGetAndSet(E newValue)
Description copied from interface: TxnRef
Atomically sets the value and returns the previous value. This method doesn't care about any running txns.

Specified by:
atomicGetAndSet in interface TxnRef<E>
Parameters:
newValue - the new value.
Returns:
the old value.

commute

public final void commute(Function<E> function)
Description copied from interface: TxnRef
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 TxnRef<E>
Parameters:
function - the function to apply to this reference.

commute

public final void commute(Txn tx,
                          Function<E> function)
Description copied from interface: TxnRef
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 TxnRef<E>
Parameters:
tx - the Txn used for this operation.
function - the function to apply to this reference.

commute

public final void commute(GammaTxn tx,
                          Function<E> function)

atomicAlterAndGet

public final E atomicAlterAndGet(Function<E> function)
Description copied from interface: TxnRef
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 TxnRef<E>
Parameters:
function - the Function used
Returns:
the new value.

atomicGetAndAlter

public final E atomicGetAndAlter(Function<E> function)
Description copied from interface: TxnRef
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 TxnRef<E>
Parameters:
function - the Function used
Returns:
the old value.

alterAndGet

public final E alterAndGet(Function<E> function)
Description copied from interface: TxnRef
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 TxnRef<E>
Parameters:
function - the function that alters the value stored in this Ref.
Returns:
the new value.

alterAndGet

public final E alterAndGet(Txn tx,
                           Function<E> function)
Description copied from interface: TxnRef
Alters the value stored in this Ref using the provided function and lifting on the provided txn.

Specified by:
alterAndGet in interface TxnRef<E>
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 E alterAndGet(GammaTxn tx,
                           Function<E> function)

getAndAlter

public final E getAndAlter(Function<E> function)
Description copied from interface: TxnRef
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 TxnRef<E>
Parameters:
function - the function that alters the value stored in this Ref.
Returns:
the old value.

getAndAlter

public final E getAndAlter(Txn tx,
                           Function<E> function)
Description copied from interface: TxnRef
Alters the value stored in this Ref using the function and returns the old value, using the provided txn.

Specified by:
getAndAlter in interface TxnRef<E>
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 E getAndAlter(GammaTxn tx,
                           Function<E> function)

atomicCompareAndSet

public final boolean atomicCompareAndSet(E expectedValue,
                                         E newValue)
Description copied from interface: TxnRef
Executes a compare and set atomically. This method doesn't care about any running txns.

Specified by:
atomicCompareAndSet in interface TxnRef<E>
Parameters:
expectedValue - the expected value.
newValue - the new value.
Returns:
true if the compareAndSwap was a success, false otherwise.

isNull

public final boolean isNull()
Description copied from interface: TxnRef
Checks if the current value is null.

This call lifts on the Txn stored in the TxnThreadLocal.

Specified by:
isNull in interface TxnRef<E>
Returns:
true if null, false otherwise.

isNull

public final boolean isNull(Txn tx)
Description copied from interface: TxnRef
Checks if the current value is null using the provided txn.

Specified by:
isNull in interface TxnRef<E>
Parameters:
tx - the Txn used for this operation.
Returns:
true if the value is null, false otherwise.

isNull

public final boolean isNull(GammaTxn tx)

atomicIsNull

public final boolean atomicIsNull()
Description copied from interface: TxnRef
Atomically check if the current value is null. This method doesn't care about any running txns.

Specified by:
atomicIsNull in interface TxnRef<E>
Returns:
true if null, false otherwise.

awaitNotNullAndGet

public final E awaitNotNullAndGet()
Description copied from interface: TxnRef
Awaits for the value to become not null. If the value already is not null, this call returns the stored value. If the value is null, a retry is done.

This call lifts on the Txn stored in the TxnThreadLocal.

Specified by:
awaitNotNullAndGet in interface TxnRef<E>
Returns:
the stored value.

awaitNotNullAndGet

public final E awaitNotNullAndGet(Txn tx)
Description copied from interface: TxnRef
Awaits for the value to become not null using the provided txn. If the value already is not null, this call returns the stored value. If the value is null, a retry is done.

Specified by:
awaitNotNullAndGet in interface TxnRef<E>
Parameters:
tx - the Txn used for this operation.
Returns:
the stored value.

awaitNotNullAndGet

public final E awaitNotNullAndGet(GammaTxn tx)

awaitNull

public final void awaitNull()
Description copied from interface: TxnRef
Awaits for the value to become null. If the value already is null, this call continues. If the reference is not null, a retry is done.

This call lifts on the Txn stored in the TxnThreadLocal.

Specified by:
awaitNull in interface TxnRef<E>

awaitNull

public final void awaitNull(Txn tx)
Description copied from interface: TxnRef
Awaits for the value to become not null using the provided txn. If the value already is null, this call continues. If the value is not null, a retry is done.

Specified by:
awaitNull in interface TxnRef<E>
Parameters:
tx - the Txn used for this operation.

awaitNull

public final void awaitNull(GammaTxn tx)

await

public final void await(E value)
Description copied from interface: TxnRef
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 TxnRef<E>
Parameters:
value - the value to wait for.

await

public final void await(Txn tx,
                        E value)
Description copied from interface: TxnRef
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 TxnRef<E>
Parameters:
tx - the Txn used for this operation.
value - the value to wait for.

await

public final void await(GammaTxn tx,
                        E value)

await

public final void await(Predicate<E> predicate)
Description copied from interface: TxnRef
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 TxnRef<E>
Parameters:
predicate - the predicate to evaluate.

await

public final void await(Txn tx,
                        Predicate<E> predicate)
Description copied from interface: TxnRef
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 TxnRef<E>
Parameters:
tx - the Txn used for this operation.
predicate - the predicate to evaluate.

await

public final void await(GammaTxn tx,
                        Predicate<E> 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.


Copyright © 2012. All Rights Reserved.