java.lang.Object
org.meeuw.configuration.ConfigurationService
A set of static methods to maintain a thread local
Configuration. Every configuration has a set of ConfigurationAspect and values.
These values are initially loaded via java service loading. This initial default values can be changed, and also the values per thread.
So configuration is:
- Type safe. Every aspect has its own implementation with their own 'withers'
- JVM global defaults can be set.
- This default configuration object is the initial value of every thread local configuration
- Since:
- 0.7
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ThreadLocal<Configuration>static ConfigurationService.Reset -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddefaultConfiguration(Consumer<Configuration.Builder> consumer) Configures the default configuration object.static Configurationstatic <E extends ConfigurationAspect>
EgetConfigurationAspect(Class<E> clazz) static voidResets all settings (viadefaultConfiguration(Consumer).static voidUnsets the configuration thread local, effectively resetting it the default settings.static ConfigurationService.ResetsetConfiguration(Consumer<Configuration.Builder> consumer) static voidsetConfiguration(Configuration configuration) Sets the given configuration object as a thread localstatic voidsetConfiguration(Configuration.Builder configuration) static ConfigurationService.ResetsetConfiguration(Configuration configuration, Consumer<Configuration.Builder> consumer) static voidPersists settings viaConfigurationPreferences(a wrapper aroundPreferences).static booleansync()static <E extends ConfigurationAspect>
voidwithAspect(E configurationAspect, Runnable r) static <E extends ConfigurationAspect,R>
RwithAspect(E configurationAspect, Supplier<R> r) static <E extends ConfigurationAspect>
voidwithAspect(Class<E> configurationAspectClass, UnaryOperator<E> aspectConfigurer, Runnable r) AswithAspect(Class, UnaryOperator, Supplier), but with aRunnableargumentstatic <E extends ConfigurationAspect,R>
RwithAspect(Class<E> configurationAspectClass, UnaryOperator<E> aspectConfigurer, Supplier<R> r) Runs a piece of code, but before that configure one configuration aspectstatic voidwithConfiguration(Consumer<Configuration.Builder> configuration, Runnable runnable) static voidwithConfiguration(Configuration configuration, Runnable r) Runs a piece of code with a certainConfigurationThis is justwithConfiguration(Configuration, Supplier), but accepting aRunnablestatic <R> RwithConfiguration(Configuration configuration, Supplier<R> supplier) Executes code with a certain configuration.
-
Field Details
-
RESET_TO_DEFAULTS
-
CONFIGURATION
-
-
Method Details
-
setupUserPreferences
public static void setupUserPreferences()Persists settings viaConfigurationPreferences(a wrapper aroundPreferences). This may result in a config file in$HOME/.java/.userPrefs(UNIXes), in$HOME/Library/Preferences/org.meeuw.configuration.plist(OS X) or registry entries (Windows) -
defaultConfiguration
Configures the default configuration object.- Parameters:
consumer- the code to configure the new default configuration. it will receive aConfiguration.Builderwith the existing configuration.- See Also:
-
getConfiguration
- Returns:
- the current (thread local) configuration object
-
setConfiguration
Sets the given configuration object as a thread local- Parameters:
configuration- the new configuration
-
setConfiguration
public static ConfigurationService.Reset setConfiguration(Configuration configuration, Consumer<Configuration.Builder> consumer) - Since:
- 0.10
-
setConfiguration
- Since:
- 0.10
-
setConfiguration
- Since:
- 0.10
-
resetToDefaults
public static void resetToDefaults()Unsets the configuration thread local, effectively resetting it the default settings. -
resetToDefaultDefaults
public static void resetToDefaultDefaults()Resets all settings (viadefaultConfiguration(Consumer).- See Also:
-
sync
public static boolean sync() -
getConfigurationAspect
- Type Parameters:
E- The type of the aspect to obtain- Parameters:
clazz- the class of the aspect to obtain- Returns:
- an aspect of the current configuration object
-
withConfiguration
Executes code with a certain configuration. Will set given configuration, and restore the existing one after calling the supplier- Parameters:
configuration- The configuration to run insupplier- The code to execute
-
withConfiguration
Runs a piece of code with a certainConfigurationThis is justwithConfiguration(Configuration, Supplier), but accepting aRunnable -
withAspect
public static <E extends ConfigurationAspect,R> R withAspect(Class<E> configurationAspectClass, UnaryOperator<E> aspectConfigurer, Supplier<R> r) Runs a piece of code, but before that configure one configuration aspect- Parameters:
configurationAspectClass- the class of the configuration aspect to configureaspectConfigurer- unary operator on aConfigurationAspect, returns a new value for that aspect
-
withAspect
public static <E extends ConfigurationAspect> void withAspect(Class<E> configurationAspectClass, UnaryOperator<E> aspectConfigurer, Runnable r) AswithAspect(Class, UnaryOperator, Supplier), but with aRunnableargument -
withAspect
-
withAspect
-
withConfiguration
public static void withConfiguration(Consumer<Configuration.Builder> configuration, Runnable runnable)
-