Skip to content
Snippets Groups Projects

Various code smell fixes from sonar

Merged Martin Lowe requested to merge malowe/main/1.1.2-smell-fixes into main
29 files
+ 204
151
Compare changes
  • Side-by-side
  • Inline
Files
29
@@ -21,10 +21,6 @@ import java.util.concurrent.TimeUnit;
@@ -21,10 +21,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
import java.util.stream.Collectors;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.eclipse.microprofile.context.ManagedExecutor;
import org.eclipse.microprofile.context.ManagedExecutor;
import org.eclipsefoundation.caching.config.LoadingCacheConfig;
import org.eclipsefoundation.caching.config.LoadingCacheConfig;
import org.eclipsefoundation.caching.config.LoadingCacheConfig.LoaderDefinition;
import org.eclipsefoundation.caching.config.LoadingCacheConfig.LoaderDefinition;
@@ -38,10 +34,12 @@ import io.quarkus.arc.All;
@@ -38,10 +34,12 @@ import io.quarkus.arc.All;
import io.quarkus.arc.InstanceHandle;
import io.quarkus.arc.InstanceHandle;
import io.quarkus.runtime.Startup;
import io.quarkus.runtime.Startup;
import io.quarkus.scheduler.Scheduled;
import io.quarkus.scheduler.Scheduled;
 
import jakarta.annotation.PostConstruct;
 
import jakarta.enterprise.context.ApplicationScoped;
/**
/**
* Service layer for defined loading caches. This centralizes the loading caches to reduce potential for inconsistent or
* Service layer for defined loading caches. This centralizes the loading caches to reduce potential for inconsistent or incorrect
* incorrect implementations of loading caches in downstream applications.
* implementations of loading caches in downstream applications.
*
*
* @author Martin Lowe
* @author Martin Lowe
*
*
@@ -50,18 +48,27 @@ import io.quarkus.scheduler.Scheduled;
@@ -50,18 +48,27 @@ import io.quarkus.scheduler.Scheduled;
@ApplicationScoped
@ApplicationScoped
public class DefaultLoadingCacheManager implements LoadingCacheManager {
public class DefaultLoadingCacheManager implements LoadingCacheManager {
@Inject
private final LoadingCacheConfig config;
LoadingCacheConfig config;
private final List<InstanceHandle<LoadingCacheProvider<?>>> providers;
private final ManagedExecutor executor;
@Inject
@All
List<InstanceHandle<LoadingCacheProvider<?>>> providers;
@Inject
ManagedExecutor executor;
// internal list of managed loading caches
// internal list of managed loading caches
private List<LoadingCacheWrapper<?>> caches;
private List<LoadingCacheWrapper<?>> caches;
 
/**
 
* Default constructor for LCM, includes required configs, providers, and the executor for processing.
 
*
 
* @param config loading cache configuration mapping for runtime
 
* @param providers list of all available loaders for the cache
 
* @param executor context-aware executor for loading cache async
 
*/
 
public DefaultLoadingCacheManager(LoadingCacheConfig config, @All List<InstanceHandle<LoadingCacheProvider<?>>> providers,
 
ManagedExecutor executor) {
 
this.config = config;
 
this.providers = providers;
 
this.executor = executor;
 
}
 
/**
/**
* Using the loading cache providers, generate active loading caches for the application.
* Using the loading cache providers, generate active loading caches for the application.
*/
*/
@@ -104,8 +111,8 @@ public class DefaultLoadingCacheManager implements LoadingCacheManager {
@@ -104,8 +111,8 @@ public class DefaultLoadingCacheManager implements LoadingCacheManager {
}
}
/**
/**
* Using the key and the discovered cache, do a lookup of the key, using the configured timeout and rethrowing any
* Using the key and the discovered cache, do a lookup of the key, using the configured timeout and rethrowing any exceptions in
* exceptions in execution upstream.
* execution upstream.
*
*
* @param <T> the type of data returned by the cache
* @param <T> the type of data returned by the cache
* @param k the cache key to pass to the loading cache for value retrieval
* @param k the cache key to pass to the loading cache for value retrieval
@@ -133,13 +140,12 @@ public class DefaultLoadingCacheManager implements LoadingCacheManager {
@@ -133,13 +140,12 @@ public class DefaultLoadingCacheManager implements LoadingCacheManager {
}
}
/**
/**
* Checks if a cache should be refreshed by checking the last refresh time, and if so iterating all active keys and
* Checks if a cache should be refreshed by checking the last refresh time, and if so iterating all active keys and attempt a refresh.
* attempt a refresh. This is used for cases where we need to force the cache to refresh before it is called by
* This is used for cases where we need to force the cache to refresh before it is called by downstream methods to have the most
* downstream methods to have the most accurate data possible.
* accurate data possible.
*/
*/
@Scheduled(every = "5m")
@Scheduled(every = "5m")
void refreshKeys() {
void refreshKeys() {
// TODO we'll want to maintain a map of last refresh times to reduce unnecessary operations
caches
caches
.stream()
.stream()
.filter(wrapper -> wrapper.config.forceRefresh())
.filter(wrapper -> wrapper.config.forceRefresh())
@@ -166,8 +172,8 @@ public class DefaultLoadingCacheManager implements LoadingCacheManager {
@@ -166,8 +172,8 @@ public class DefaultLoadingCacheManager implements LoadingCacheManager {
}
}
/**
/**
* Typed generic wrapper for loading caches. This will help match on internal types of expected output and increase type
* Typed generic wrapper for loading caches. This will help match on internal types of expected output and increase type safety around
* safety around lookups, as well as provide best matching configuration values for the given cache.
* lookups, as well as provide best matching configuration values for the given cache.
*
*
* @author Martin Lowe
* @author Martin Lowe
*
*
@@ -179,8 +185,8 @@ public class DefaultLoadingCacheManager implements LoadingCacheManager {
@@ -179,8 +185,8 @@ public class DefaultLoadingCacheManager implements LoadingCacheManager {
private final LoaderDefinition config;
private final LoaderDefinition config;
/**
/**
* Builds the wrapper with assembled cache, the configurations that apply to the cache to reduce need for reflection,
* Builds the wrapper with assembled cache, the configurations that apply to the cache to reduce need for reflection, and the
* and the internal type for easier matching on incoming requests.
* internal type for easier matching on incoming requests.
*
*
* @param cache the wrapped asynchronous cache
* @param cache the wrapped asynchronous cache
* @param innerType the return type of the loading cache
* @param innerType the return type of the loading cache
@@ -202,8 +208,8 @@ public class DefaultLoadingCacheManager implements LoadingCacheManager {
@@ -202,8 +208,8 @@ public class DefaultLoadingCacheManager implements LoadingCacheManager {
}
}
/**
/**
* Retrieves a view of the cache keys for the current cache. Will only show keys that have realized values and not
* Retrieves a view of the cache keys for the current cache. Will only show keys that have realized values and not values that are
* values that are in the process of being fetched.
* in the process of being fetched.
*
*
* @return list of cache keys for finished cache results.
* @return list of cache keys for finished cache results.
*/
*/
@@ -221,8 +227,8 @@ public class DefaultLoadingCacheManager implements LoadingCacheManager {
@@ -221,8 +227,8 @@ public class DefaultLoadingCacheManager implements LoadingCacheManager {
}
}
/**
/**
* Gets the pre-loading cache configuration that defines refresh periods, whether to enforce forced refreshes, and the
* Gets the pre-loading cache configuration that defines refresh periods, whether to enforce forced refreshes, and the timeout
* timeout periods to reduce risk of stalled operations.
* periods to reduce risk of stalled operations.
*
*
* @return the preloading configuration for the wrapped cache.
* @return the preloading configuration for the wrapped cache.
*/
*/
Loading