com.atlassian.util.concurrent.atomic
Class AtomicLong

java.lang.Object
  extended by java.lang.Number
      extended by java.util.concurrent.atomic.AtomicLong
          extended by com.atlassian.util.concurrent.atomic.AtomicLong
All Implemented Interfaces:
java.io.Serializable

public class AtomicLong
extends java.util.concurrent.atomic.AtomicLong

AtomicLong with richer functionality. This class implements commonly implemented patterns of use of compareAndSet such as #getAndSetIf(long, long) and update(Function).

Since:
0.0.12
See Also:
Serialized Form

Constructor Summary
AtomicLong()
          Creates a new AtomicLong with a zero initial value.
AtomicLong(long initialValue)
          Creates a new AtomicLong with the given initial value.
 
Method Summary
 long getOrSetAndGetIf(long oldValue, long newValue)
          Check the current value and if it matches the old value argument, set it to the new value and return that instead.
 long update(com.google.common.base.Function<java.lang.Long,java.lang.Long> newValueFactory)
          Do the actual update.
 
Methods inherited from class java.util.concurrent.atomic.AtomicLong
addAndGet, compareAndSet, decrementAndGet, doubleValue, floatValue, get, getAndAdd, getAndDecrement, getAndIncrement, getAndSet, incrementAndGet, intValue, lazySet, longValue, set, toString, weakCompareAndSet
 
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
 

Constructor Detail

AtomicLong

public AtomicLong()
Creates a new AtomicLong with a zero initial value.


AtomicLong

public AtomicLong(long initialValue)
Creates a new AtomicLong with the given initial value.

Parameters:
initialValue - the initial value
Method Detail

getOrSetAndGetIf

public final long getOrSetAndGetIf(long oldValue,
                                   long newValue)
Check the current value and if it matches the old value argument, set it to the new value and return that instead. If the old value argument does not match, ignore both and just return the current value.

Parameters:
oldValue - to check the current value against
newValue - the new value to set it to
Returns:
the current reference value if it doesn't match oldValue or a newly created value.

update

public final long update(com.google.common.base.Function<java.lang.Long,java.lang.Long> newValueFactory)
Do the actual update. Calls the factory method with the old value to do the update logic, then sets the value to that if it hasn't changed in the meantime.

Returns:
the new updated value.


Copyright © 2012 Atlassian. All Rights Reserved.