Module io.github.bucket4j.core
Interface LockBasedTransaction
-
public interface LockBasedTransactionDescribes the set of operations thatAbstractLockBasedProxyManagertypically performs in reaction to user request. The typical flow is following:- begin -
begin(Optional) - lock -
lockAndGet(Optional) - update -
update(byte[], RemoteBucketState, Optional) - unlock -
unlock() - commit -
commit(Optional) - release -
release()
- begin -
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidbegin(Optional<Long> timeoutNanos)Begins transaction if underlying storage requires transactions.voidcommit(Optional<Long> timeoutNanos)Commits transaction if underlying storage requires transactionsvoidcreate(byte[] data, RemoteBucketState state, Optional<Long> timeoutNanos)Creates the data by the key associated with this transaction.byte[]lockAndGet(Optional<Long> timeoutNanos)Locks data by the key associated with this transaction and returns data that is associated with the key.voidrelease()Frees resources associated with this transactionvoidrollback()Rollbacks transaction if underlying storage requires transactionsvoidunlock()Unlocks data by the key associated with this transaction.voidupdate(byte[] data, RemoteBucketState newState, Optional<Long> timeoutNanos)Updates the data by the key associated with this transaction.
-
-
-
Method Detail
-
begin
void begin(Optional<Long> timeoutNanos)
Begins transaction if underlying storage requires transactions. There is strong guarantee thatcommit(Optional)orrollback()will be called ifbegin(Optional)returns successfully.- Parameters:
timeoutNanos- optional timeout in nanoseconds
-
rollback
void rollback()
Rollbacks transaction if underlying storage requires transactions
-
commit
void commit(Optional<Long> timeoutNanos)
Commits transaction if underlying storage requires transactions- Parameters:
timeoutNanos- optional timeout in nanoseconds
-
lockAndGet
byte[] lockAndGet(Optional<Long> timeoutNanos)
Locks data by the key associated with this transaction and returns data that is associated with the key. There is strong guarantee thatunlock()will be called iflockAndGet(Optional)returns successfully.- Parameters:
timeoutNanos- optional timeout in nanoseconds- Returns:
- Returns the data by the key associated with this transaction, or null data associated with key does not exist
-
unlock
void unlock()
Unlocks data by the key associated with this transaction.
-
create
void create(byte[] data, RemoteBucketState state, Optional<Long> timeoutNanos)Creates the data by the key associated with this transaction.- Parameters:
data- bucket state to persistsstate- of bucket - can be used to extract additional data is useful for persistence or logging.timeoutNanos- optional timeout in nanoseconds
-
update
void update(byte[] data, RemoteBucketState newState, Optional<Long> timeoutNanos)Updates the data by the key associated with this transaction.- Parameters:
data- bucket state to persistsnewState- new state of bucket - can be used to extract additional data is useful for persistence or logging.
-
release
void release()
Frees resources associated with this transaction
-
-