Class RemoteAsyncBucketBuilderView<K,KeyOld>
- java.lang.Object
-
- io.github.bucket4j.distributed.proxy.RemoteAsyncBucketBuilderView<K,KeyOld>
-
- All Implemented Interfaces:
RemoteAsyncBucketBuilder<K>
public class RemoteAsyncBucketBuilderView<K,KeyOld> extends Object implements RemoteAsyncBucketBuilder<K>
-
-
Constructor Summary
Constructors Constructor Description RemoteAsyncBucketBuilderView(RemoteAsyncBucketBuilder<KeyOld> target, Function<K,KeyOld> mapper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AsyncBucketProxybuild(K key, BucketConfiguration configuration)Builds theAsyncBucketProxy.AsyncBucketProxybuild(K key, Supplier<CompletableFuture<BucketConfiguration>> configurationSupplier)Has the same semantic withRemoteAsyncBucketBuilder.build(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>withImplicitConfigurationReplacement(long desiredConfigurationVersion, TokensInheritanceStrategy tokensInheritanceStrategy)Activates implicit configuration replacement.RemoteAsyncBucketBuilder<K>withListener(BucketListener listener)Specifieslistenerfor buckets that will be created by this builder.<K2> RemoteAsyncBucketBuilder<K2>withMapper(Function<? super K2,? extends K> innerMapper)Returns a proxy object that wraps this RemoteAsyncBucketBuilder such that keys are first mapped using the specified mapping function before being sent to the remote store.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.
-
-
-
Constructor Detail
-
RemoteAsyncBucketBuilderView
public RemoteAsyncBucketBuilderView(RemoteAsyncBucketBuilder<KeyOld> target, Function<K,KeyOld> mapper)
-
-
Method Detail
-
withRecoveryStrategy
public RemoteAsyncBucketBuilder<K> withRecoveryStrategy(RecoveryStrategy recoveryStrategy)
Description copied from interface:RemoteAsyncBucketBuilderConfigures custom recovery strategy instead ofRecoveryStrategy.RECONSTRUCTthat is used by default.- Specified by:
withRecoveryStrategyin interfaceRemoteAsyncBucketBuilder<K>- Parameters:
recoveryStrategy- specifies the reaction which should be applied in case of previously saved state of bucket has been lost, explicitly removed or expired.- Returns:
this
-
withOptimization
public RemoteAsyncBucketBuilder<K> withOptimization(Optimization optimization)
Description copied from interface:RemoteAsyncBucketBuilderConfigures 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- Specified by:
withOptimizationin interfaceRemoteAsyncBucketBuilder<K>- Parameters:
optimization- optimization strategy- Returns:
this
-
withImplicitConfigurationReplacement
public RemoteAsyncBucketBuilder<K> withImplicitConfigurationReplacement(long desiredConfigurationVersion, TokensInheritanceStrategy tokensInheritanceStrategy)
Description copied from interface:RemoteAsyncBucketBuilderActivates implicit configuration replacement.By default distributed bucket operates with configuration that was provided at the time of its first creation. Providing the new configuration via
RemoteBucketBuildertakes no effect if bucket is already persisted in the storage, because configuration is stored together with state of bucket. Without implicit configuration replacement, there is only one way to replace configuration of bucket - is explicit calling ofAsyncBucketProxy.replaceConfiguration(BucketConfiguration, TokensInheritanceStrategy).When implicit configuration replacement is activated, bucket will automatically replace persisted configuration using provided
tokensInheritanceStrategyin case of persisted version of configuration in the storage < than provideddesiredConfigurationVersion.- Specified by:
withImplicitConfigurationReplacementin interfaceRemoteAsyncBucketBuilder<K>- Parameters:
desiredConfigurationVersion- specifies desired configuration versiontokensInheritanceStrategy- the strategy that will be used for token migration ifdesiredConfigurationVersion of persisted bucketis less that provided desiredConfigurationVersion- Returns:
this
-
withListener
public RemoteAsyncBucketBuilder<K> withListener(BucketListener listener)
Description copied from interface:RemoteAsyncBucketBuilderSpecifieslistenerfor buckets that will be created by this builder.- Specified by:
withListenerin interfaceRemoteAsyncBucketBuilder<K>- Parameters:
listener- the listener of bucket events.- Returns:
- this builder instance
-
build
public AsyncBucketProxy build(K key, BucketConfiguration configuration)
Description copied from interface:RemoteAsyncBucketBuilderBuilds 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
RemoteAsyncBucketBuilder.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.- Specified by:
buildin interfaceRemoteAsyncBucketBuilder<K>- 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
public AsyncBucketProxy build(K key, Supplier<CompletableFuture<BucketConfiguration>> configurationSupplier)
Description copied from interface:RemoteAsyncBucketBuilderHas the same semantic withRemoteAsyncBucketBuilder.build(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.- Specified by:
buildin interfaceRemoteAsyncBucketBuilder<K>- 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.
-
withMapper
public <K2> RemoteAsyncBucketBuilder<K2> withMapper(Function<? super K2,? extends K> innerMapper)
Description copied from interface:RemoteAsyncBucketBuilderReturns a proxy object that wraps this RemoteAsyncBucketBuilder such that keys are first mapped using the specified mapping function before being sent to the remote store. The returned RemoteAsyncBucketBuilder shares the same underlying store as the original, and keys that map to the same value will share the same remote state.- Specified by:
withMapperin interfaceRemoteAsyncBucketBuilder<K>- Type Parameters:
K2- the type of key accepted by returned RemoteAsyncBucketBuilder- Parameters:
innerMapper- the mapper function to apply to keys- Returns:
- a proxy object that wraps this RemoteAsyncBucketBuilder
-
-