com.netflix.curator.framework.recipes.atomic
Interface DistributedAtomicNumber<T>

All Known Implementing Classes:
DistributedAtomicInteger, DistributedAtomicLong

public interface DistributedAtomicNumber<T>


Method Summary
 AtomicValue<T> add(T delta)
          Add delta to the current value and return the new value information.
 AtomicValue<T> compareAndSet(T expectedValue, T newValue)
          Atomically sets the value to the given updated value if the current value == the expected value.
 AtomicValue<T> decrement()
          Subtract 1 from the current value and return the new value information.
 void forceSet(T newValue)
          Forcibly sets the value of the counter without any guarantees of atomicity.
 AtomicValue<T> get()
          Returns the current value of the counter.
 AtomicValue<T> increment()
          Add 1 to the current value and return the new value information.
 AtomicValue<T> subtract(T delta)
          Subtract delta from the current value and return the new value information.
 AtomicValue<T> trySet(T newValue)
          Attempt to atomically set the value to the given value.
 

Method Detail

get

AtomicValue<T> get()
                   throws Exception
Returns the current value of the counter. NOTE: if the value has never been set, 0 is returned.

Returns:
value info
Throws:
Exception - ZooKeeper errors

compareAndSet

AtomicValue<T> compareAndSet(T expectedValue,
                             T newValue)
                             throws Exception
Atomically sets the value to the given updated value if the current value == the expected value. Remember to always check AtomicValue.succeeded().

Parameters:
expectedValue - the expected value
newValue - the new value for the counter
Returns:
value info
Throws:
Exception - ZooKeeper errors

trySet

AtomicValue<T> trySet(T newValue)
                      throws Exception
Attempt to atomically set the value to the given value. Remember to always check AtomicValue.succeeded().

Parameters:
newValue - the value to set
Returns:
value info
Throws:
Exception - ZooKeeper errors

forceSet

void forceSet(T newValue)
              throws Exception
Forcibly sets the value of the counter without any guarantees of atomicity.

Parameters:
newValue - the new value
Throws:
Exception - ZooKeeper errors

increment

AtomicValue<T> increment()
                         throws Exception
Add 1 to the current value and return the new value information. Remember to always check AtomicValue.succeeded().

Returns:
value info
Throws:
Exception - ZooKeeper errors

decrement

AtomicValue<T> decrement()
                         throws Exception
Subtract 1 from the current value and return the new value information. Remember to always check AtomicValue.succeeded().

Returns:
value info
Throws:
Exception - ZooKeeper errors

add

AtomicValue<T> add(T delta)
                   throws Exception
Add delta to the current value and return the new value information. Remember to always check AtomicValue.succeeded().

Parameters:
delta - amount to add
Returns:
value info
Throws:
Exception - ZooKeeper errors

subtract

AtomicValue<T> subtract(T delta)
                        throws Exception
Subtract delta from the current value and return the new value information. Remember to always check AtomicValue.succeeded().

Parameters:
delta - amount to subtract
Returns:
value info
Throws:
Exception - ZooKeeper errors


Copyright © 2012. All Rights Reserved.