Package io.micronaut.core.optim
Class StaticOptimizations
- java.lang.Object
-
- io.micronaut.core.optim.StaticOptimizations
-
@Internal public abstract class StaticOptimizations extends java.lang.Object
This class is a generic container for pre-computed data which can be injected at initialization time. Every class which needs static optimizations should go through this class to get its static state.- Since:
- 3.2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
StaticOptimizations.Loader<T>
Interface for an optimization which will be injected via service loading.
-
Constructor Summary
Constructors Constructor Description StaticOptimizations()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
cacheEnvironment()
Enables environment caching.static <T> java.util.Optional<T>
get(java.lang.Class<T> optimizationClass)
Returns, if available, the optimization data of the requested type.static boolean
isEnvironmentCached()
Returns true if the environment should be cached, that is to say if the environment variables and system properties are deemed immutable during the whole application run time.static <T> void
set(T value)
Injects an optimization.
-
-
-
Method Detail
-
cacheEnvironment
public static void cacheEnvironment()
Enables environment caching. If enabled, both the environment variables and system properties will be deemed immutable.
-
get
@NonNull public static <T> java.util.Optional<T> get(@NonNull java.lang.Class<T> optimizationClass)
Returns, if available, the optimization data of the requested type. Those optimizations are singletons, which is why they are accessed by type.- Type Parameters:
T
- the optimization type- Parameters:
optimizationClass
- the type of the optimization class- Returns:
- the optimization if set, otherwise empty
-
set
public static <T> void set(@NonNull T value)
Injects an optimization. Optimizations must be immutable final data classes: there's a one-to-one mapping between an optimization class and its associated data.- Type Parameters:
T
- the type of the optimization- Parameters:
value
- the optimization to store
-
isEnvironmentCached
public static boolean isEnvironmentCached()
Returns true if the environment should be cached, that is to say if the environment variables and system properties are deemed immutable during the whole application run time.- Returns:
- true if the environment is cached
-
-