Module io.github.bucket4j.core
Interface RemoteAsyncBucketBuilder<K>
-
- Type Parameters:
K-
public interface RemoteAsyncBucketBuilder<K>The builder forAsyncBucketProxy
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description AsyncBucketProxybuild(K key, BucketConfiguration configuration)Builds theAsyncBucketProxy.AsyncBucketProxybuild(K key, Supplier<CompletableFuture<BucketConfiguration>> configurationSupplier)Has the same semantic withbuild(Object, BucketConfiguration), but additionally provides ability to provide configuration lazily, that can be helpful when figuring-out the right configuration parameters is costly, for example because parameters for particularkeyare stored in external database,configurationSupplierwill be called if and only if bucket has not been persisted before.RemoteAsyncBucketBuilder<K>withOptimization(Optimization optimization)Configures the optimization strategy that will be applied for buckets that are built by this builder.RemoteAsyncBucketBuilder<K>withRecoveryStrategy(RecoveryStrategy recoveryStrategy)Configures custom recovery strategy instead ofRecoveryStrategy.RECONSTRUCTthat is used by default.
-
-
-
Method Detail
-
withRecoveryStrategy
RemoteAsyncBucketBuilder<K> withRecoveryStrategy(RecoveryStrategy recoveryStrategy)
Configures custom recovery strategy instead ofRecoveryStrategy.RECONSTRUCTthat is used by default.- Parameters:
recoveryStrategy- specifies the reaction which should be applied in case of previously saved state of bucket has been lost.- Returns:
this
-
withOptimization
RemoteAsyncBucketBuilder<K> withOptimization(Optimization optimization)
Configures the optimization strategy that will be applied for buckets that are built by this builder.It is worth mentioning that optimization will take effect only if you reuse the bucket, so you need to store a reference to the bucket anywhere in order to reuse it later. In other words, if any request optimization strategy has been applied to the bucket proxy then proxy can not be treated as a cheap object.
The full list of built-in optimizations can be found there
Optimizations- Parameters:
optimization- optimization strategy- Returns:
this
-
build
AsyncBucketProxy build(K key, BucketConfiguration configuration)
Builds theAsyncBucketProxy. Proxy is being created in lazy mode, its state is not persisted in external storage until first interaction, so if you want to save bucket state immediately then just callAsyncBucketProxy.getAvailableTokens().If you had not used
withOptimization(Optimization)during construction then created proxy can be treated as cheap object, feel free just build, use and forget as many proxies under the same key as you need, do not cache the built instances.- Parameters:
key- the key that used in external storage to distinguish one bucket from another.configuration- limits configuration- Returns:
- new instance of
AsyncBucketProxycreated in lazy mode.
-
build
AsyncBucketProxy build(K key, Supplier<CompletableFuture<BucketConfiguration>> configurationSupplier)
Has the same semantic withbuild(Object, BucketConfiguration), but additionally provides ability to provide configuration lazily, that can be helpful when figuring-out the right configuration parameters is costly, for example because parameters for particularkeyare stored in external database,configurationSupplierwill be called if and only if bucket has not been persisted before.- Parameters:
key- the key that used in external storage to distinguish one bucket from another.configurationSupplier- provider for bucket configuration- Returns:
- new instance of
AsyncBucketProxycreated in lazy mode.
-
-