Class DependenciesBuilder

java.lang.Object
com.mastfrog.giulius.DependenciesBuilder

public final class DependenciesBuilder extends Object
Builder for Dependencies. Allows for adding Settings for various namespaces programmatically.
Author:
Tim Boudreau
  • Constructor Details

    • DependenciesBuilder

      public DependenciesBuilder()
  • Method Details

    • namespaces

      public Set<String> namespaces()
      Get the list of namespaces this DependenciesBuilder will bind settings for. If you have called addDefaultSettings() this will include any namespaces generated from annotations, which are defined as the concatenation of all files named com/mastfrog/namespaces.list on the classpath.
      Returns:
      A set of namespaces
    • withShutdownHookExecutorAwaitDuration

      public DependenciesBuilder withShutdownHookExecutorAwaitDuration(Duration dur)
      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

      public DependenciesBuilder withMinimumShutdownHookExecutorAwaitDuration(Duration dur)
      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

      public DependenciesBuilder add(com.google.inject.Module... modules)
      Add modules to be used when creating the Injector
      Parameters:
      modules - Some modules
      Returns:
      this
    • addDefaultLocation

      public DependenciesBuilder addDefaultLocation(File loc)
      Add a folder on disk to look in for configuration files
      Parameters:
      loc - A folder on disk
      Returns:
    • disableBindings

      public DependenciesBuilder disableBindings(SettingsBindings... bindings)
      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

      public DependenciesBuilder enableOnlyBindingsFor(SettingsBindings... bindings)
      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

      public DependenciesBuilder addNamespace(String name) throws IOException
      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

      public DependenciesBuilder addDefaultSettings() throws IOException
      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

      public List<SettingsBuilder> getSettings(String ns)
    • add

      public DependenciesBuilder add(Settings settings)
      Add a Settings tied to the default namespace. Note that if you have called addDefaultSettings(), this will merge these settings with any settings files for that namespace which are on the classpath.
      Parameters:
      settings - The settings
      namespace - The namespace, referenced by @Namespace annotations on the related classes
      Returns:
      this
    • add

      public DependenciesBuilder add(Settings settings, String namespace)
      Add a Settings tied to a specific namespace. Note that if you have called addDefaultSettings(), this will merge these settings with any settings files for that namespace which are on the classpath.
      Parameters:
      settings - The settings
      namespace - The namespace, referenced by @Namespace annotations on the related classes
      Returns:
      this
    • useMutableSettings

      public DependenciesBuilder 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

      public DependenciesBuilder 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

      public Dependencies build() throws IOException
      Build a dependencies object.
      Returns:
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object