- java.lang.Object
-
- io.github.bucket4j.distributed.proxy.ClientSideConfig
-
public class ClientSideConfig extends Object
Represents additional options forProxyManagersuch as:- Backward compatibility version, see
backwardCompatibleWith(Version)for more details. - Client-side clock, see
withClientClock(TimeMeter)for more details.
- Backward compatibility version, see
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedClientSideConfig(Version backwardCompatibilityVersion, Optional<TimeMeter> clientSideClock, ExecutionStrategy executionStrategy, Optional<Long> requestTimeoutNanos)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ClientSideConfigbackwardCompatibleWith(Version backwardCompatibilityVersion)Returns new instance ofClientSideConfigwith configuredbackwardCompatibilityVersion.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.static ClientSideConfiggetDefault()Returns default client-side configuration for proxy-manager that configured with following parameters: Client-clock: is null.ExecutionStrategygetExecutionStrategy()Returns the strategy for request executionOptional<Long>getRequestTimeoutNanos()Returns timeout for remote operationsClientSideConfigwithClientClock(TimeMeter clientClock)Returns new instance ofClientSideConfigwith configuredclientClock.ClientSideConfigwithExecutionStrategy(ExecutionStrategy executionStrategy)Returns new instance ofClientSideConfigwith configuredexecutionStrategy.ClientSideConfigwithRequestTimeout(Duration requestTimeout)Returns new instance ofClientSideConfigwith configured timeout for remote operations.
-
-
-
Method Detail
-
getDefault
public static ClientSideConfig getDefault()
Returns default client-side configuration for proxy-manager that configured with following parameters:- Client-clock: is null. This means that server-side clock is always used.
- Backward compatibility version: is
Versions.getLatest(). This means that compatibility with legacy versions is switched off.
- Returns:
- default client-side configuration for proxy-manager
-
backwardCompatibleWith
public ClientSideConfig backwardCompatibleWith(Version backwardCompatibilityVersion)
Returns new instance ofClientSideConfigwith configuredbackwardCompatibilityVersion.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:
- new instance of
ClientSideConfigwith configuredbackwardCompatibilityVersion.
-
withClientClock
public ClientSideConfig withClientClock(TimeMeter clientClock)
Returns new instance ofClientSideConfigwith configuredclientClock.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:
- new instance of
ClientSideConfigwith configuredclientClock.
-
withExecutionStrategy
public ClientSideConfig withExecutionStrategy(ExecutionStrategy executionStrategy)
Returns new instance ofClientSideConfigwith configuredexecutionStrategy.The default executionStrategy is
ExecutionStrategy.SAME_TREAD.- Parameters:
executionStrategy- the strategy for request execution.- Returns:
- new instance of
ClientSideConfigwith configuredclientClock.
-
withRequestTimeout
public ClientSideConfig withRequestTimeout(Duration requestTimeout)
Returns new instance ofClientSideConfigwith configured 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:
- new instance of
ClientSideConfigwith configuredrequestTimeout.
-
getClientSideClock
public Optional<TimeMeter> getClientSideClock()
Returns clock that will be used for time measurement.- Returns:
- clock that will be used for time measurement.
- See Also:
withClientClock(TimeMeter)
-
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
-
-