Class StaticOptimizations

java.lang.Object
io.micronaut.core.optim.StaticOptimizations

@Internal public abstract class StaticOptimizations extends 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 
    Interface for an optimization which will be injected via service loading.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Enables environment caching.
    static <T> @NonNull Optional<T>
    get(@NonNull Class<T> optimizationClass)
    Returns, if available, the optimization data of the requested type.
    static boolean
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StaticOptimizations

      public StaticOptimizations()
  • Method Details

    • 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> @NonNull Optional<T> get(@NonNull @NonNull 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