From c9e9a642e6356ca27a347c9846a50068dacd687f Mon Sep 17 00:00:00 2001 From: Asi Bross <11426802+asibross@users.noreply.github.com> Date: Thu, 30 May 2024 11:32:58 -0700 Subject: [PATCH] Expose a setter in EVCache.Builder to explicitly set the pool manager --- .../java/com/netflix/evcache/EVCache.java | 138 ++++++++++-------- 1 file changed, 74 insertions(+), 64 deletions(-) diff --git a/evcache-core/src/main/java/com/netflix/evcache/EVCache.java b/evcache-core/src/main/java/com/netflix/evcache/EVCache.java index 92ee930c..e203a252 100644 --- a/evcache-core/src/main/java/com/netflix/evcache/EVCache.java +++ b/evcache-core/src/main/java/com/netflix/evcache/EVCache.java @@ -1236,12 +1236,12 @@ public Builder() { } public Builder withConfigurationProperties( - final EVCacheClientPoolConfigurationProperties configurationProperties) { - return this - .setCachePrefix(configurationProperties.getKeyPrefix()) - .setDefaultTTL(configurationProperties.getTimeToLive()) - .setRetry(configurationProperties.getRetryEnabled()) - .setExceptionThrowing(configurationProperties.getExceptionThrowingEnabled()); + final EVCacheClientPoolConfigurationProperties configurationProperties) { + return this + .setCachePrefix(configurationProperties.getKeyPrefix()) + .setDefaultTTL(configurationProperties.getTimeToLive()) + .setRetry(configurationProperties.getRetryEnabled()) + .setExceptionThrowing(configurationProperties.getExceptionThrowingEnabled()); } /** @@ -1304,15 +1304,15 @@ public Builder setDefaultTTL(int ttl) { return this; } - /** - * The default Time To Live (TTL) for items in {@link EVCache} in - * seconds. You can override the value by passing the desired TTL with - * {@link EVCache#set(String, Object, int)} operations. - * - * @param ttl. Default is 900 seconds. - * @return this {@code Builder} object - */ - public Builder setDefaultTTL(@Nullable final Duration ttl) { + /** + * The default Time To Live (TTL) for items in {@link EVCache} in + * seconds. You can override the value by passing the desired TTL with + * {@link EVCache#set(String, Object, int)} operations. + * + * @param ttl. Default is 900 seconds. + * @return this {@code Builder} object + */ + public Builder setDefaultTTL(@Nullable final Duration ttl) { if (ttl == null) { return this; } @@ -1322,7 +1322,7 @@ public Builder setDefaultTTL(@Nullable final Duration ttl) { @VisibleForTesting Transcoder getTranscoder() { - return this._transcoder; + return this._transcoder; } /** @@ -1349,18 +1349,18 @@ public Builder enableZoneFallback() { return this; } - /** - * Will enable or disable retry across Server Group for cache misses and exceptions - * if there are multiple Server Groups for the given EVCache App and - * data is replicated across them. This ensures the Hit Rate continues - * to be unaffected whenever a server group loses instances. - * - * By Default retry is enabled. - * - * @param enableRetry whether retries are to be enabled - * @return this {@code Builder} object - */ - public Builder setRetry(boolean enableRetry) { + /** + * Will enable or disable retry across Server Group for cache misses and exceptions + * if there are multiple Server Groups for the given EVCache App and + * data is replicated across them. This ensures the Hit Rate continues + * to be unaffected whenever a server group loses instances. + * + * By Default retry is enabled. + * + * @param enableRetry whether retries are to be enabled + * @return this {@code Builder} object + */ + public Builder setRetry(boolean enableRetry) { this._serverGroupRetry = enableRetry; return this; @@ -1404,15 +1404,15 @@ public Builder disableZoneFallback() { return this; } - /** - * By Default exceptions are not propagated and null values are - * returned. By enabling exception propagation we return the - * {@link EVCacheException} whenever the operations experience them. - * - * @param enableExceptionThrowing whether exception throwing is to be enabled - * @return this {@code Builder} object - */ - public Builder setExceptionThrowing(boolean enableExceptionThrowing) { + /** + * By Default exceptions are not propagated and null values are + * returned. By enabling exception propagation we return the + * {@link EVCacheException} whenever the operations experience them. + * + * @param enableExceptionThrowing whether exception throwing is to be enabled + * @return this {@code Builder} object + */ + public Builder setExceptionThrowing(boolean enableExceptionThrowing) { this._enableExceptionThrowing = enableExceptionThrowing; return this; @@ -1430,12 +1430,12 @@ public Builder enableExceptionPropagation() { return this; } - /** - * Adds customizers to be applied by {@code customize}. - * - * @param customizers List of {@code Customizer}s - * @return this {@code Builder} object - */ + /** + * Adds customizers to be applied by {@code customize}. + * + * @param customizers List of {@code Customizer}s + * @return this {@code Builder} object + */ public Builder addCustomizers(@Nullable final List customizers) { this._customizers.addAll(customizers); @@ -1443,33 +1443,43 @@ public Builder addCustomizers(@Nullable final List customizers) { } - /** - * Applies {@code Customizer}s added through {@code addCustomizers} to {@this}. - * - * @return this {@code Builder} object - */ - public Builder customize() { - _customizers.forEach(customizer -> { - customizeWith(customizer); - }); - - return this; - } - - /** - * Customizes {@this} with the {@code customizer}. - * - * @param customizer {@code Customizer} or {@code Consumer} to be applied to {@code this}. - * @return this {@code Builder} object - */ - public Builder customizeWith(final Customizer customizer) { + /** + * Applies {@code Customizer}s added through {@code addCustomizers} to {@this}. + * + * @return this {@code Builder} object + */ + public Builder customize() { + _customizers.forEach(customizer -> { + customizeWith(customizer); + }); + + return this; + } + + /** + * Customizes {@this} with the {@code customizer}. + * + * @param customizer {@code Customizer} or {@code Consumer} to be applied to {@code this}. + * @return this {@code Builder} object + */ + public Builder customizeWith(final Customizer customizer) { customizer.customize(this._appName, this); return this; } + /** + * The EVCache pool manager that will be used by this {@code EVCache}. + * @param poolManager + * @return this {@code Builder} object + */ + public Builder setPoolManager(EVCacheClientPoolManager poolManager) { + _poolManager = poolManager; + return this; + } + protected EVCache newImpl(String appName, String cachePrefix, int ttl, Transcoder transcoder, boolean serverGroupRetry, boolean enableExceptionThrowing, EVCacheClientPoolManager poolManager) { - return new EVCacheImpl(appName, cachePrefix, ttl, transcoder, serverGroupRetry, enableExceptionThrowing, poolManager); + return new EVCacheImpl(appName, cachePrefix, ttl, transcoder, serverGroupRetry, enableExceptionThrowing, poolManager); } /**