IgniteAtomicStamped

The IgniteAtomicStamped interface provides a rich API for working with distributed atomic stamped values. It is different from IgniteAtomicReference, as IgniteAtomicStamped keeps both an object reference and a stamp internally. The reference and stamp can both be changed using a single atomic operation.

Atomic stamped can be defined as follows:

IgniteAtomicStamped<String, Integer> stamp = ignite.atomicStamped("myStamp"  , //atomic stamped name
"my init value", //initial value
0, //initial stamp
true // create if doesn't exist
);

Similar to atomic reference, stamped has the compareAndSet(T expVal, T newVal, S expStamp, S newStamp) method to conditionally set the new value and new stamp. It will be set if expVal and expStamp are equal to the current value and current stamp, respectively.

Run the following code to verify the compareAndSet behavior:

IgniteAtomicStamped<String, Integer> stamp = ignite.atomicStamped("myStamp", "my init value", 0, true);
System.out.println(stamp.get());
stamp.set("new value", 1);
System.out.println(stamp.get());
System.out.println("did it update? " +stamp.compareAndSet("value", "2nd update", 1, 2)+" , value is ="+ stamp.get());
System.out.println("did it update? " +stamp.compareAndSet("new value", "2nd update", 1, 2)+" , value is ="+ stamp.get());

The output will look like this:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.22.179