org.terracotta.util
Class TerracottaAtomicLong

java.lang.Object
  extended by java.lang.Number
      extended by org.terracotta.util.TerracottaAtomicLong
All Implemented Interfaces:
Serializable, ClusteredAtomicLong

public class TerracottaAtomicLong
extends Number
implements ClusteredAtomicLong

A Terracotta specific implementation of ClusteredAtomicLong. This implementation uses shared read/write locks to achieve atomicity. As such users should not expect performance to be on a par with the local volatile read/write based AtomicLong.

See Also:
Serialized Form

Constructor Summary
TerracottaAtomicLong()
          Constructs a TerracottaAtomicLong whose initial long value is zero.
TerracottaAtomicLong(long value)
          Constructs a TerracottaAtomicLong with the supplied initial long value.
 
Method Summary
 long addAndGet(long delta)
          Atomically add the supplied value to the current value.
 boolean compareAndSet(long expect, long update)
          Atomically set the value to the new value if the current value == the given value.
 long decrementAndGet()
          Atomically decrement the current value.
 double doubleValue()
          Number.doubleValue()
 float floatValue()
          Number.floatValue()
 long get()
          Get the current value.
 long getAndAdd(long delta)
          Atomically add the supplied value to the current value.
 long getAndDecrement()
          Atomically decrement the current value.
 long getAndIncrement()
          Atomically increment the current value.
 long getAndSet(long newValue)
          Atomically: set to the given value and return the previous value.
 long incrementAndGet()
          Atomically increment the current value
 int intValue()
          Number.intValue()
 long longValue()
          Number.longValue()
 void set(long newValue)
          Set to the given value
 String toString()
           
 boolean weakCompareAndSet(long expect, long update)
          Atomically set the value to the new value if the current value == the given value.
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.terracotta.util.ClusteredAtomicLong
byteValue, shortValue
 

Constructor Detail

TerracottaAtomicLong

public TerracottaAtomicLong()
Constructs a TerracottaAtomicLong whose initial long value is zero.


TerracottaAtomicLong

public TerracottaAtomicLong(long value)
Constructs a TerracottaAtomicLong with the supplied initial long value.

Parameters:
value - the initial value
Method Detail

addAndGet

public long addAndGet(long delta)
Description copied from interface: ClusteredAtomicLong
Atomically add the supplied value to the current value.

Specified by:
addAndGet in interface ClusteredAtomicLong
Parameters:
delta - the value to add
Returns:
the new value

compareAndSet

public boolean compareAndSet(long expect,
                             long update)
Description copied from interface: ClusteredAtomicLong
Atomically set the value to the new value if the current value == the given value.

Specified by:
compareAndSet in interface ClusteredAtomicLong
Parameters:
expect - the expected value
update - the new value
Returns:
true if successful, false if the comparison failed

decrementAndGet

public long decrementAndGet()
Description copied from interface: ClusteredAtomicLong
Atomically decrement the current value.

Specified by:
decrementAndGet in interface ClusteredAtomicLong
Returns:
the new value

get

public long get()
Description copied from interface: ClusteredAtomicLong
Get the current value.

Specified by:
get in interface ClusteredAtomicLong
Returns:
the current value

getAndAdd

public long getAndAdd(long delta)
Description copied from interface: ClusteredAtomicLong
Atomically add the supplied value to the current value.

Specified by:
getAndAdd in interface ClusteredAtomicLong
Parameters:
delta - the value to add
Returns:
the previous value

getAndDecrement

public long getAndDecrement()
Description copied from interface: ClusteredAtomicLong
Atomically decrement the current value.

Specified by:
getAndDecrement in interface ClusteredAtomicLong
Returns:
the previous value

getAndIncrement

public long getAndIncrement()
Description copied from interface: ClusteredAtomicLong
Atomically increment the current value.

Specified by:
getAndIncrement in interface ClusteredAtomicLong
Returns:
the previous value

getAndSet

public long getAndSet(long newValue)
Description copied from interface: ClusteredAtomicLong
Atomically: set to the given value and return the previous value.

Specified by:
getAndSet in interface ClusteredAtomicLong
Parameters:
newValue - the new value
Returns:
the previous value

incrementAndGet

public long incrementAndGet()
Description copied from interface: ClusteredAtomicLong
Atomically increment the current value

Specified by:
incrementAndGet in interface ClusteredAtomicLong
Returns:
the new value

set

public void set(long newValue)
Description copied from interface: ClusteredAtomicLong
Set to the given value

Specified by:
set in interface ClusteredAtomicLong
Parameters:
newValue - the new value

weakCompareAndSet

public boolean weakCompareAndSet(long expect,
                                 long update)
Description copied from interface: ClusteredAtomicLong
Atomically set the value to the new value if the current value == the given value.

May fail spuriously. Repeated uncontended valid calls will eventually succeed however.

Specified by:
weakCompareAndSet in interface ClusteredAtomicLong
Parameters:
expect - the expected value
update - the new value
Returns:
true if successful, false if the comparison failed

intValue

public int intValue()
Description copied from interface: ClusteredAtomicLong
Number.intValue()

Specified by:
intValue in interface ClusteredAtomicLong
Specified by:
intValue in class Number

longValue

public long longValue()
Description copied from interface: ClusteredAtomicLong
Number.longValue()

Specified by:
longValue in interface ClusteredAtomicLong
Specified by:
longValue in class Number

floatValue

public float floatValue()
Description copied from interface: ClusteredAtomicLong
Number.floatValue()

Specified by:
floatValue in interface ClusteredAtomicLong
Specified by:
floatValue in class Number

doubleValue

public double doubleValue()
Description copied from interface: ClusteredAtomicLong
Number.doubleValue()

Specified by:
doubleValue in interface ClusteredAtomicLong
Specified by:
doubleValue in class Number

toString

public String toString()
Specified by:
toString in interface ClusteredAtomicLong
Overrides:
toString in class Object


Copyright © 2015 Terracotta, Inc.. All Rights Reserved.