Package com.mastfrog.giulius
Class DependenciesBuilder
java.lang.Object
com.mastfrog.giulius.DependenciesBuilder
Builder for Dependencies. Allows for adding Settings for various
namespaces programmatically.
- Author:
- Tim Boudreau
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(com.google.inject.Module... modules) Add modules to be used when creating the InjectorAdd a Settings tied to the default namespace.Add a Settings tied to a specific namespace.addDefaultLocation(File loc) Add a folder on disk to look in for configuration filesAdd the default settings (see SettingsBuilder.createDefault()), and default settings for any namespaces found in /com/mastfrog/namespaces.list files anywhere on the classpath (these are generated from the @Defaults annotation).addNamespace(String name) Add a namespace, causing all of the default locations to be used.build()Build a dependencies object.disableBindings(SettingsBindings... bindings) Disable binding of settings to some types if you know they will not be used, to save (minimal) memory.enableOnlyBindingsFor(SettingsBindings... bindings) Explicitly set the list of types that are bound to settings to save (minimal) memory.getSettings(String ns) Even if multiple namespaces are present, merge settings from all namespaces (with the default namespace as the lowest) layer.Get the list of namespaces this DependenciesBuilder will bind settings for.toString()If called, bind a MutableSettings (has setters) rather than the default (mutable settings are bound, but are created on the fly and any changes are not shared with other code).Set the minimum length of time that shutdown hooks (which are automatically bound and can be used to perform resource cleanup and orderly, graceful shutdown behavior, or restart-without-jvm-exit) should wait for all ExecutorServices where were added to the shutdown hooks to terminate before proceeding further with shutdown.Set the length of time that shutdown hooks (which are automatically bound and can be used to perform resource cleanup and orderly, graceful shutdown behavior, or restart-without-jvm-exit) should wait for all ExecutorServices where were added to the shutdown hooks to terminate before proceeding further with shutdown.
-
Constructor Details
-
DependenciesBuilder
public DependenciesBuilder()
-
-
Method Details
-
namespaces
Get the list of namespaces this DependenciesBuilder will bind settings for. If you have calledaddDefaultSettings()this will include any namespaces generated from annotations, which are defined as the concatenation of all files namedcom/mastfrog/namespaces.liston the classpath.- Returns:
- A set of namespaces
-
withShutdownHookExecutorAwaitDuration
Set the length of time that shutdown hooks (which are automatically bound and can be used to perform resource cleanup and orderly, graceful shutdown behavior, or restart-without-jvm-exit) should wait for all ExecutorServices where were added to the shutdown hooks to terminate before proceeding further with shutdown.- Parameters:
dur- A duration- Returns:
- this
-
withMinimumShutdownHookExecutorAwaitDuration
Set the minimum length of time that shutdown hooks (which are automatically bound and can be used to perform resource cleanup and orderly, graceful shutdown behavior, or restart-without-jvm-exit) should wait for all ExecutorServices where were added to the shutdown hooks to terminate before proceeding further with shutdown. If this method was already called, the resulting value is the maximum of the original value and the new one.- Parameters:
dur- A duration- Returns:
- this
-
add
Add modules to be used when creating the Injector- Parameters:
modules- Some modules- Returns:
- this
-
addDefaultLocation
Add a folder on disk to look in for configuration files- Parameters:
loc- A folder on disk- Returns:
-
disableBindings
Disable binding of settings to some types if you know they will not be used, to save (minimal) memory. This is only significant if you are running in < 20Mb heap.- Parameters:
bindings- The bindings to remove- Returns:
- this
-
enableOnlyBindingsFor
Explicitly set the list of types that are bound to settings to save (minimal) memory.- Parameters:
bindings- The types of bindings to set up- Returns:
- this
-
addNamespace
Add a namespace, causing all of the default locations to be used. The namespace's settings will contain environment variables, system properties and the contents of any generated-$NAMESPACE.properties and $NAMESPACE.properties files in the default location on the classpath.- Parameters:
name- The name of the namespace.- Returns:
- this
- Throws:
IOException
-
addDefaultSettings
Add the default settings (see SettingsBuilder.createDefault()), and default settings for any namespaces found in /com/mastfrog/namespaces.list files anywhere on the classpath (these are generated from the @Defaults annotation).- Returns:
- this
- Throws:
IOException- If loading settings fails
-
getSettings
-
add
Add a Settings tied to the default namespace. Note that if you have calledaddDefaultSettings(), this will merge these settings with any settings files for that namespace which are on the classpath.- Parameters:
settings- The settingsnamespace- The namespace, referenced by @Namespace annotations on the related classes- Returns:
- this
-
add
Add a Settings tied to a specific namespace. Note that if you have calledaddDefaultSettings(), this will merge these settings with any settings files for that namespace which are on the classpath.- Parameters:
settings- The settingsnamespace- The namespace, referenced by @Namespace annotations on the related classes- Returns:
- this
-
useMutableSettings
If called, bind a MutableSettings (has setters) rather than the default (mutable settings are bound, but are created on the fly and any changes are not shared with other code).- Returns:
- this
-
mergeNamespaces
Even if multiple namespaces are present, merge settings from all namespaces (with the default namespace as the lowest) layer. This can be useful when you only have one actual namespace, which is not the default namespace (so the file name is different, but you don't actually care about different objects being injected into classes in different namespaces or packages), as it eliminates the overhead of binding individual providers for each namespace.- Returns:
- this
-
build
Build a dependencies object.- Returns:
- Throws:
IOException
-
toString
-