From 5518045e1c9468534226371edd4deb32db0a8a9a Mon Sep 17 00:00:00 2001 From: Petr Aubrecht Date: Thu, 1 Jun 2023 17:16:00 +0200 Subject: [PATCH] FISH-7426 variable naming clarification -- milliseconds FISH-7426 another variable naming clarification -- milliseconds FISH-7426 fixing config provider resolver to return seconds from config cache The value cacheDurationSeconds returned milliseconds by mistake (misleading method name). FISH-7426 update copyright years --- .../spi/ConfigProviderResolverImpl.java | 4 +-- .../microprofile/config/spi/PayaraConfig.java | 30 +++++++++---------- .../config/spi/PayaraConfigTest.java | 4 +-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/spi/ConfigProviderResolverImpl.java b/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/spi/ConfigProviderResolverImpl.java index 6ec60148664..77cf9a1c8fa 100644 --- a/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/spi/ConfigProviderResolverImpl.java +++ b/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/spi/ConfigProviderResolverImpl.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2017-2021] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2017-2023] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -203,7 +203,7 @@ public MicroprofileConfigConfiguration getMPConfig() { long getCacheDurationSeconds() { if (serverLevelConfig != null) { - return serverLevelConfig.getCacheDurationSeconds(); + return serverLevelConfig.getCacheDurationMilliSeconds() / 1_000; } return Integer.parseInt(getMPConfig().getCacheDurationSeconds()); } diff --git a/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/spi/PayaraConfig.java b/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/spi/PayaraConfig.java index 8b5ea5525c2..21f8cd26872 100644 --- a/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/spi/PayaraConfig.java +++ b/nucleus/payara-modules/nucleus-microprofile/config-service/src/main/java/fish/payara/nucleus/microprofile/config/spi/PayaraConfig.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2017-2022 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2017-2023 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -98,49 +98,49 @@ private static final class CacheEntry { private final Map cachedValuesByProperty = new ConcurrentHashMap<>(); - private volatile long configuredCacheDurationSeconds; - private volatile long configuredCacheDurationSecondsExpires = 0; // force value reload at start + private volatile long configuredCacheDurationMilliSeconds; + private volatile long configuredCacheDurationMilliSecondsExpires = 0; // force value reload at start private final Object configuredCacheValueLock = new Object(); private final String profile; - public PayaraConfig(List sources, Map, Converter> converters, long defaultCacheDurationSeconds) { + public PayaraConfig(List sources, Map, Converter> converters, long defaultCacheDurationMilliSeconds) { this.sources = sources; this.converters = new ConcurrentHashMap<>(converters); - this.defaultCacheDurationMilliSeconds = defaultCacheDurationSeconds; + this.defaultCacheDurationMilliSeconds = defaultCacheDurationMilliSeconds; Collections.sort(sources, new ConfigSourceComparator()); profile = getConfigValue(MP_CONFIG_PROFILE_NAME_STRING).getValue(); } @SuppressWarnings("unchecked") - public long getCacheDurationSeconds() { + public long getCacheDurationMilliSeconds() { final Optional> converter = Optional.ofNullable((Converter) converters.get(Long.class)); if (converter.isPresent()) { long currentTimeMillis = currentTimeMillis(); // If the value has been found and it hasn't expired - if (currentTimeMillis < configuredCacheDurationSecondsExpires) { - return configuredCacheDurationSeconds; + if (currentTimeMillis < configuredCacheDurationMilliSecondsExpires) { + return configuredCacheDurationMilliSeconds; } else { // Atomic block to modify the cached value synchronized (configuredCacheValueLock) { // double check if situation didn't change - if (currentTimeMillis < configuredCacheDurationSecondsExpires) { - return configuredCacheDurationSeconds; + if (currentTimeMillis < configuredCacheDurationMilliSecondsExpires) { + return configuredCacheDurationMilliSeconds; } // Fetch the value from config final ConfigValue value = searchConfigSources(MP_CONFIG_CACHE_DURATION, null); if (value.getValue() != null) { // If it's found, cache it - configuredCacheDurationSeconds = convertValue(value, null, converter); + configuredCacheDurationMilliSeconds = convertValue(value, null, converter); } else { // Cache the default value (usually that's from the server config) - configuredCacheDurationSeconds = defaultCacheDurationMilliSeconds; + configuredCacheDurationMilliSeconds = defaultCacheDurationMilliSeconds; } - configuredCacheDurationSecondsExpires = currentTimeMillis + configuredCacheDurationSeconds; + configuredCacheDurationMilliSecondsExpires = currentTimeMillis + configuredCacheDurationMilliSeconds; long endTimeMillis = currentTimeMillis(); log.log(Level.FINER, () -> "getCacheDurationSeconds took about " + (endTimeMillis - currentTimeMillis) + " ms"); - return configuredCacheDurationSeconds; + return configuredCacheDurationMilliSeconds; } } } @@ -230,7 +230,7 @@ protected ConfigValueImpl getConfigValue(String propertyName, String cacheKey, L } protected ConfigValueImpl getConfigValue(String propertyName, String cacheKey, Long ttl, String defaultValue, ConfigValueType type) { - long entryTTL = ttl != null ? ttl : getCacheDurationSeconds(); + long entryTTL = ttl != null ? ttl : getCacheDurationMilliSeconds(); if (entryTTL <= 0) { return searchConfigSources(propertyName, defaultValue); diff --git a/nucleus/payara-modules/nucleus-microprofile/config-service/src/test/java/fish/payara/nucleus/microprofile/config/spi/PayaraConfigTest.java b/nucleus/payara-modules/nucleus-microprofile/config-service/src/test/java/fish/payara/nucleus/microprofile/config/spi/PayaraConfigTest.java index 74c4c1b80fd..3d2d7f6202f 100644 --- a/nucleus/payara-modules/nucleus-microprofile/config-service/src/test/java/fish/payara/nucleus/microprofile/config/spi/PayaraConfigTest.java +++ b/nucleus/payara-modules/nucleus-microprofile/config-service/src/test/java/fish/payara/nucleus/microprofile/config/spi/PayaraConfigTest.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2020 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2020-2023 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -272,7 +272,7 @@ public void illegalArrayElementFailsOverallArrayConversion() { @Test public void ttlParameterIsRespected() { final long ttl = 60 * 1000L; - assertEquals(ttl, new PayaraConfig(emptyList(), emptyMap(), ttl).getCacheDurationSeconds()); + assertEquals(ttl, new PayaraConfig(emptyList(), emptyMap(), ttl).getCacheDurationMilliSeconds()); } private void assertCachedValue(ConfigSource source, String key, Class propertyType, T expectedValue1,