Module io.github.bucket4j.core
Interface CompareAndSwapOperation
public interface CompareAndSwapOperation
-
Method Summary
Modifier and TypeMethodDescriptionbooleancompareAndSwap(byte[] originalData, byte[] newData, RemoteBucketState newState, Optional<Long> timeoutNanos) Compares and swap data associated with keyOptional<byte[]>getStateData(Optional<Long> timeoutNanos) Reads data if it exists
-
Method Details
-
getStateData
Reads data if it exists- Parameters:
timeoutNanos- optional timeout in nanoseconds- Returns:
- persisted data or empty optional if data not exists
-
compareAndSwap
boolean compareAndSwap(byte[] originalData, byte[] newData, RemoteBucketState newState, Optional<Long> timeoutNanos) Compares and swap data associated with key- Parameters:
originalData- previous bucket state(can be null).newData- new bucket statenewState- new state of bucket - can be used to extract additional data is useful for persistence or logging.timeoutNanos- optional timeout in nanoseconds- Returns:
trueif data changed,falseif another parallel transaction achieved success instead of current transaction
-