Class AppConstants

All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>

public final class AppConstants extends PropertyLoader
Configuration Constants for this application.

When an instance is created, it tries to load the properties file specified by the propertiesFileName field

.

If a property exits with the name ADDITIONAL.PROPERTIES.FILE that file is loaded also

There is a global instance that can be retrieved with getInstance(), and an instance per configuration that can be retrieved with getInstance(ClassLoader) using the configuration classloader. Each method will the instance if it does not yet exist.

To change a value across all instances, use setGlobalProperty(String, String). Changing a value for only a single instance with setProperty(String, String) is in general recommended only for tests.

Version:
2.1
Author:
Niels Meijer
See Also:
  • Field Details

    • APPLICATION_SERVER_TYPE_PROPERTY

      public static final String APPLICATION_SERVER_TYPE_PROPERTY
      See Also:
    • APPLICATION_SERVER_CUSTOMIZATION_PROPERTY

      public static final String APPLICATION_SERVER_CUSTOMIZATION_PROPERTY
      See Also:
    • ADDITIONAL_PROPERTIES_FILE_SUFFIX_KEY

      public static final String ADDITIONAL_PROPERTIES_FILE_SUFFIX_KEY
      See Also:
  • Method Details

    • getInstance

      public static AppConstants getInstance()
      Return the AppConstants root instance
      Returns:
      AppConstants instance
    • getInstance

      public static AppConstants getInstance(ClassLoader classLoader)
      Retrieve an instance based on a ClassLoader. This should be used by classes which are part of the Ibis configuration (like pipes and senders) because the configuration might be loaded from outside the webapp classpath. Hence, the Thread.currentThread().getContextClassLoader() at the time the class was instantiated should be used.
      Parameters:
      classLoader - ClassLoader to retrieve AppConstants from
      Returns:
      AppConstants instance
    • removeInstance

      public static void removeInstance()
    • removeInstance

      public static void removeInstance(ClassLoader cl)
    • getAppConstants

      public Properties getAppConstants(String keyBase)
      Returns a list of AppConstants which names begin with the keyBase
    • getAppConstants

      public Properties getAppConstants(String keyBase, boolean useSystemProperties, boolean useEnvironmentVariables)
      Returns a list of AppConstants which names begin with the keyBase
    • setProperty

      public Object setProperty(String key, String value)
      Use this method for testing only, when only local properties need to be set that do not affect other tests.
      Overrides:
      setProperty in class Properties
      Parameters:
      key - the key to be placed into this property list.
      value - the value corresponding to key.
      Returns:
      Previous value, or null
    • setProperty

      public Object setProperty(String key, boolean value)
      Set key as boolean. Use this method for testing only, when local properties need to be set that do not affect other tests.
      Parameters:
      key - the key to be placed into this property list.
      value - the value corresponding to key.
      Returns:
      Previous value, or null
    • setGlobalProperty

      @Nullable public static Boolean setGlobalProperty(@Nonnull String key, boolean value)
      Set boolean value in all instances of AppConstants, current and future. Use this in production-code to make sure a settings-change is propagated to all configurations.
      Parameters:
      key - the key to be placed into this property list.
      value - the value corresponding to key.
      Returns:
      Previous value, or null
    • setGlobalProperty

      @Nullable public static String setGlobalProperty(@Nonnull String key, @Nonnull String value)
      Set value in all instances of AppConstants, current and future. Use this in production-code to make sure a settings-change is propagated to all configurations.
      Parameters:
      key - the key to be placed into this property list.
      value - the value corresponding to key.
      Returns:
      Previous value, or null
    • clearGlobalProperty

      @Nullable public static String clearGlobalProperty(@Nonnull String key)
      Clear a property in all instances of AppConstants.
      Parameters:
      key - the key to be removed
      Returns:
      The value associated with the key, or null
    • load

      protected void load(ClassLoader classLoader, String filename)
      Description copied from class: PropertyLoader
      Load the contents of a properties file.

      Optionally, this may be a comma-separated list of files to load, e.g. log4j2.properties,DeploymentSpecifics.properties which will cause both files to be loaded in the listed order.

      Overrides:
      load in class PropertyLoader