-
- All Superinterfaces:
Bucket
- All Known Implementing Classes:
LockFreeBucket,SynchronizedBucket,ThreadUnsafeBucket
public interface LocalBucket extends Bucket
Represents the bucket inside current JVM.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static LocalBucketfromBinarySnapshot(byte[] snapshot)Reconstructs a bucket from binary snapshot.static LocalBucketfromJsonCompatibleSnapshot(Map<String,Object> snapshot)Reconstructs a bucket from JSON snapshot.BucketConfigurationgetConfiguration()Returns configuration of this bucket.SynchronizationStrategygetSynchronizationStrategy()Returns the synchronization strategy that is used by this bucketTimeMetergetTimeMeter()Returns the clock that is used by this bucketdefault byte[]toBinarySnapshot()Takes the binary snapshot of this bucket that later can be used as parameter forfromBinarySnapshot(byte[])to restore bucket from snapshot.default Map<String,Object>toJsonCompatibleSnapshot()Takes the JSON snapshot of this bucket that later can be used as parameter forfromJsonCompatibleSnapshot(Map)to restore bucket from snapshot.-
Methods inherited from interface io.github.bucket4j.Bucket
addTokens, asBlocking, asScheduler, asVerbose, consumeIgnoringRateLimits, estimateAbilityToConsume, forceAddTokens, getAvailableTokens, replaceConfiguration, reset, toListenable, tryConsume, tryConsumeAndReturnRemaining, tryConsumeAsMuchAsPossible, tryConsumeAsMuchAsPossible
-
-
-
-
Method Detail
-
getConfiguration
BucketConfiguration getConfiguration()
Returns configuration of this bucket.- Returns:
- configuration
-
getTimeMeter
TimeMeter getTimeMeter()
Returns the clock that is used by this bucket- Returns:
- the clock that is used by this bucket
-
getSynchronizationStrategy
SynchronizationStrategy getSynchronizationStrategy()
Returns the synchronization strategy that is used by this bucket- Returns:
- synchronization strategy that is used by this bucket
-
toBinarySnapshot
default byte[] toBinarySnapshot() throws IOExceptionTakes the binary snapshot of this bucket that later can be used as parameter forfromBinarySnapshot(byte[])to restore bucket from snapshot.- Returns:
- the binary snapshot of this bucket
- Throws:
IOException
-
fromBinarySnapshot
static LocalBucket fromBinarySnapshot(byte[] snapshot) throws IOException
Reconstructs a bucket from binary snapshot.- Parameters:
snapshot- binary snapshot- Returns:
- bucket reconstructed from binary snapshot
- Throws:
IOException
-
toJsonCompatibleSnapshot
default Map<String,Object> toJsonCompatibleSnapshot() throws IOException
Takes the JSON snapshot of this bucket that later can be used as parameter forfromJsonCompatibleSnapshot(Map)to restore bucket from snapshot.- Returns:
- the map that transparently can be serialized to JSON via any JSON library
- Throws:
IOException
-
fromJsonCompatibleSnapshot
static LocalBucket fromJsonCompatibleSnapshot(Map<String,Object> snapshot) throws IOException
Reconstructs a bucket from JSON snapshot.- Parameters:
snapshot- the snapshot Map that was deserialized from JSON via any JSON library- Returns:
- bucket reconstructed from binary snapshot
- Throws:
IOException
-
-