Class AbstractProxyManagerBuilder<K,P extends ProxyManager<K>,B extends AbstractProxyManagerBuilder<K,P,B>>
- java.lang.Object
-
- io.github.bucket4j.distributed.proxy.AbstractProxyManagerBuilder<K,P,B>
-
- Type Parameters:
K- type of keyP- type of proxy manager that is being buildB- the type of builder extending AbstractProxyManagerBuilder
- Direct Known Subclasses:
AbstractJdbcProxyManagerBuilder
public abstract class AbstractProxyManagerBuilder<K,P extends ProxyManager<K>,B extends AbstractProxyManagerBuilder<K,P,B>> extends Object
Base class for all proxy-manager builders.
-
-
Constructor Summary
Constructors Constructor Description AbstractProxyManagerBuilder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description BbackwardCompatibleWith(Version backwardCompatibilityVersion)ConfiguresbackwardCompatibilityVersion.abstract Pbuild()Builds new instance ofAbstractProxyManagerBuilderBclientClock(TimeMeter clientClock)ConfiguresclientClock.BdefaultListener(BucketListener defaultListener)Configures listener at proxy-manager level, this listener will be used for buckets in case of listener will not be specified during bucket build time.BdefaultRecoveryStrategy(RecoveryStrategy recoveryStrategy)Configures custom recovery strategy at proxy-manager level, this strategy will be used for buckets in case of it will not be specified during bucket build time.BexecutionStrategy(ExecutionStrategy executionStrategy)ConfiguresexecutionStrategy.BexpirationAfterWrite(ExpirationAfterWriteStrategy expirationStrategy)Configures strategy for choosing time to live for buckets.VersiongetBackwardCompatibilityVersion()Returns the Bucket4j protocol version is used to be backward compatible with other nodes in the cluster.Optional<TimeMeter>getClientSideClock()Returns clock that will be used for time measurement.ClientSideConfiggetClientSideConfig()ExecutionStrategygetExecutionStrategy()Returns the strategy for request executionOptional<ExpirationAfterWriteStrategy>getExpirationAfterWrite()Returns the strategy for choosing time to live for buckets.Optional<Long>getRequestTimeoutNanos()Returns timeout for remote operationsbooleanisExpireAfterWriteSupported()Describes whetherAbstractProxyManagerBuildersupports expire-after-write feature.BrequestTimeout(Duration requestTimeout)Configures timeout for remote operations.
-
-
-
Method Detail
-
backwardCompatibleWith
public B backwardCompatibleWith(Version backwardCompatibilityVersion)
ConfiguresbackwardCompatibilityVersion.Use this method in case of rolling upgrades, when you want from already new nodes to continue communication using the legacy protocol version which is compatible with
backwardCompatibilityVersion.By default backward compatibility version is
Versions.getLatest(). This means that compatibility with legacy versions is switched off.- Parameters:
backwardCompatibilityVersion- the Bucket4j protocol version to be backward compatible with other nodes in the cluster.- Returns:
- this builder with configured
backwardCompatibilityVersion.
-
clientClock
public B clientClock(TimeMeter clientClock)
ConfiguresclientClock.Use this method when you want to measure current time by yourself. In normal scenarios you should not use this functionality, but sometimes it can be useful, especially for testing and modeling.
By default, client-clock is null. This means that server-side clock is always used.
- Parameters:
clientClock- the clock that will be used for time measuring instead of server-side clock.- Returns:
- this builder with configured
clientClock.
-
executionStrategy
public B executionStrategy(ExecutionStrategy executionStrategy)
ConfiguresexecutionStrategy.The default executionStrategy is
ExecutionStrategy.SAME_TREAD.- Parameters:
executionStrategy- the strategy for request execution.- Returns:
- this builder with configured
clientClock.
-
requestTimeout
public B requestTimeout(Duration requestTimeout)
Configures timeout for remote operations.The way in which timeout is applied depends on concrete implementation of
ProxyManager. It can be three possible cases:- If underlying technology supports per request timeouts(like timeouts on prepared JDBC statements) then this feature is used by ProxyManager to satisfy requested timeout
- If timeouts is not supported by underlying technology, but it is possible to deal with timeout on Bucket4j library level(like specifying timeouts on CompletableFuture), then this way is applied.
- If nothing from above can be applied, then specified
requestTimeoutis totally ignored byProxyManager
- Parameters:
requestTimeout- timeout for remote operations.- Returns:
- this builder with configured
requestTimeout.
-
expirationAfterWrite
public B expirationAfterWrite(ExpirationAfterWriteStrategy expirationStrategy)
Configures strategy for choosing time to live for buckets.If particular
AbstractProxyManagerBuilderdoes not supportExpirationAfterWriteStrategythen this method throws exception.- Parameters:
expirationStrategy- the strategy for choosing time to live for buckets.- Returns:
- this builder with configured
expirationStrategy.
-
defaultListener
public B defaultListener(BucketListener defaultListener)
Configures listener at proxy-manager level, this listener will be used for buckets in case of listener will not be specified during bucket build time.- Parameters:
defaultListener- listener of bucket events- Returns:
- this builder instance
-
defaultRecoveryStrategy
public B defaultRecoveryStrategy(RecoveryStrategy recoveryStrategy)
Configures custom recovery strategy at proxy-manager level, this strategy will be used for buckets in case of it will not be specified during bucket build time.- 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
-
getExpirationAfterWrite
public Optional<ExpirationAfterWriteStrategy> getExpirationAfterWrite()
Returns the strategy for choosing time to live for buckets.- Returns:
- the strategy for choosing time to live for buckets
-
getClientSideClock
public Optional<TimeMeter> getClientSideClock()
Returns clock that will be used for time measurement.- Returns:
- clock that will be used for time measurement.
-
getRequestTimeoutNanos
public Optional<Long> getRequestTimeoutNanos()
Returns timeout for remote operations- Returns:
- timeout for remote operations
-
getBackwardCompatibilityVersion
public Version getBackwardCompatibilityVersion()
Returns the Bucket4j protocol version is used to be backward compatible with other nodes in the cluster.- Returns:
- the Bucket4j protocol version is used to be backward compatible with other nodes in the cluster.
- See Also:
backwardCompatibleWith(Version)
-
getExecutionStrategy
public ExecutionStrategy getExecutionStrategy()
Returns the strategy for request execution- Returns:
- the strategy for request execution
-
build
public abstract P build()
Builds new instance ofAbstractProxyManagerBuilder- Returns:
- new instance of
AbstractProxyManagerBuilder
-
isExpireAfterWriteSupported
public boolean isExpireAfterWriteSupported()
Describes whetherAbstractProxyManagerBuildersupports expire-after-write feature.- Returns:
trueAbstractProxyManagerBuildersupports expire-after-write feature.
-
getClientSideConfig
public ClientSideConfig getClientSideConfig()
-
-