Class ConfigurationContext

java.lang.Object
ru.vyarus.dropwizard.guice.module.context.ConfigurationContext

public final class ConfigurationContext extends Object
Configuration context used internally to track all registered configuration items. Items may be registered by type (installer, extension) or by instance (module, bundle).

Each item is registered only once, but all registrations are tracked. Uniqueness guaranteed by type.

Support generic disabling mechanism (for items marked with DisableSupport sign). If item is disabled, but never registered special empty item info will be created at the end of configuration.

Considered as internal api.

Since:
06.07.2016
See Also:
  • Constructor Details

    • ConfigurationContext

      public ConfigurationContext()
      Create a context.
  • Method Details

    • addAutoScanFilter

      public void addAutoScanFilter(Predicate<Class<?>> filter)
      Add extra filter for scanned classes (classpath scan and bindings recognition).
      Parameters:
      filter - filter instance
    • isAcceptableAutoScanClass

      public boolean isAcceptableAutoScanClass(Class<?> clazz)
      Parameters:
      clazz - class to test
      Returns:
      true if extension class could be used, false otherwise (auto scan filter)
    • setDuplicatesDetector

      public void setDuplicatesDetector(DuplicateConfigDetector detector)
      Change default duplicates detector.
      Parameters:
      detector - new policy
    • addDelayedConfiguration

      public void addDelayedConfiguration(Consumer<GuiceyEnvironment> config)
      Add delayed configuration from the main builder (or hook) to run under run phase (when configuration would be available).
      Parameters:
      config - delayed configuration
    • processDelayedConfigurations

      public void processDelayedConfigurations(GuiceyEnvironment environment)
      Process delayed builder (or hooks) configurations.
      Parameters:
      environment - guicey environment
    • openScope

      public void openScope(ItemId scope)
      Current configuration context (application, bundle or classpath scan).
      Parameters:
      scope - scope key
    • replaceContextScope

      public ItemId replaceContextScope(ItemId scope)
      Declares possibly sub-configuration context. For example, to track dropwizard bundles initialization scope.
      Parameters:
      scope - scope key
      Returns:
      previous scope or null (for application scope)
    • closeScope

      public void closeScope()
      Clears current scope.
    • registerCommands

      public void registerCommands(List<Class<io.dropwizard.core.cli.Command>> commands)
      Register commands resolved with classpath scan.
      Parameters:
      commands - installed commands
      See Also:
    • registerLookupBundles

      public void registerLookupBundles(List<GuiceyBundle> bundles)
      Register bundles resolved by lookup mechanism. GuiceyBundleLookup used as context.
      Parameters:
      bundles - bundles resolved by lookup mechanism
      See Also:
    • registerBundles

      public List<GuiceyBundle> registerBundles(GuiceyBundle... bundles)
      Usual bundle registration from GuiceBundle.Builder.bundles(GuiceyBundle...) or GuiceyBootstrap.bundles(GuiceyBundle...). Context class is set to currently processed bundle.
      Parameters:
      bundles - bundles to register
      Returns:
      list of actually registered bundles (without duplicates)
    • disableBundle

      public void disableBundle(Class<? extends GuiceyBundle>[] bundles)
      Guicey bundle manual disable registration from GuiceBundle.Builder.disableBundles(Class[]).
      Parameters:
      bundles - modules to disable
    • getEnabledBundles

      public List<GuiceyBundle> getEnabledBundles()
      Returns:
      all configured bundles (without duplicates)
    • storeBundlesInitOrder

      public void storeBundlesInitOrder(List<GuiceyBundle> orderedBundles)
      Store initialization order of bundles. Due to transitive bundles immediate installation, real initialization order could differ from registration order (because the root bundle would be registered before a transitive bundle, but its processing would be finished after it).
      Parameters:
      orderedBundles - bundles in initialization order
    • getBundlesOrdered

      public List<GuiceyBundle> getBundlesOrdered()
      It is important to call bundles run in the same order as bundles were initialized (it would differ from registration order due to transitive bundles).
      Returns:
      all bundles in the initialization order
    • getDisabledBundles

      public List<GuiceyBundle> getDisabledBundles()
      Note: before configuration finalization this returns all actually disabled bundles and after finalization all disables (including never registered bundles).
      Returns:
      all configured disabled bundles (without duplicates)
    • isBundleEnabled

      public boolean isBundleEnabled(ItemId id)
      Bundle must be disabled before it's processing, otherwise disabling will not have effect (because bundle will be already processed and register all related items).
      Parameters:
      id - bundle id
      Returns:
      true if bundle enabled, false otherwise
    • registerDropwizardBundles

      public void registerDropwizardBundles(io.dropwizard.core.ConfiguredBundle... bundles)
      Direct dropwizard bundle registration from GuiceBundle.Builder.dropwizardBundles(ConfiguredBundle...) or GuiceyBootstrap.dropwizardBundles(ConfiguredBundle[]). Context class is set to currently processed bundle.
      Parameters:
      bundles - dropwizard bundles
    • disableDropwizardBundle

      public void disableDropwizardBundle(Class<? extends io.dropwizard.core.ConfiguredBundle>[] bundles)
      Guicey bundle manual disable registration from GuiceBundle.Builder.disableBundles(Class[]).
      Parameters:
      bundles - modules to disable
    • getEnabledDropwizardBundles

      public List<io.dropwizard.core.ConfiguredBundle> getEnabledDropwizardBundles()
      Returns:
      all configured dropwizard bundles (without duplicates)
    • getDisabledDropwizardBundles

      public List<io.dropwizard.core.ConfiguredBundle> getDisabledDropwizardBundles()
      Returns:
      all disabled dropwizard bundles
    • getBootstrapProxy

      public io.dropwizard.core.setup.Bootstrap getBootstrapProxy()
      Proxy object created on first access because of ~200ms creation overhead.
      Returns:
      bootstrap proxy object
    • registerModules

      public void registerModules(com.google.inject.Module... modules)
      Parameters:
      modules - guice modules to register
    • registerModulesOverride

      public void registerModulesOverride(com.google.inject.Module... modules)
      Parameters:
      modules - overriding guice modules to register
    • disableModules

      public void disableModules(Class<? extends com.google.inject.Module>[] modules)
      Guice module manual disable registration from GuiceBundle.Builder.disableModules(Class[]).
      Parameters:
      modules - modules to disable
    • getEnabledModules

      public List<com.google.inject.Module> getEnabledModules()
      NOTE: both normal and overriding modules.
      Returns:
      all configured and enabled guice modules (without duplicates)
    • getNormalModules

      public List<com.google.inject.Module> getNormalModules()
      Returns:
      list of all enabled normal guice modules or empty list
    • getOverridingModules

      public List<com.google.inject.Module> getOverridingModules()
      Returns:
      list of all enabled overriding modules or empty list
    • getDisabledModules

      public List<com.google.inject.Module> getDisabledModules()
      Note: before configuration finalization this returns all actually disabled modules and after finalization all disables (including never registered modules).
      Returns:
      list of disabled modules or empty list
    • getDisabledModuleTypes

      public List<Class<Object>> getDisabledModuleTypes()
      Returns:
      all disabled module types, including never registered
    • registerInstallers

      public void registerInstallers(Class<? extends FeatureInstaller>[] installers)
      Parameters:
      installers - installers to register
    • registerInstallersFromScan

      public void registerInstallersFromScan(List<Class<? extends FeatureInstaller>> installers)
      Register installers from classpath scan. Use ClasspathScanner as context class.
      Parameters:
      installers - installers found by classpath scan
    • disableInstallers

      public void disableInstallers(Class<? extends FeatureInstaller>[] installers)
      Parameters:
      installers - installers to disable
    • getEnabledInstallers

      public List<Class<? extends FeatureInstaller>> getEnabledInstallers()
      Returns:
      all configured and enabled installers (including resolved by scan)
    • getDisabledInstallers

      public List<Class<? extends FeatureInstaller>> getDisabledInstallers()
      Note: before configuration finalization this returns all actually disabled installers and after finalization all disables (including never registered installers).
      Returns:
      list of disabled installers
    • installersResolved

      public void installersResolved(List<FeatureInstaller> installers)
      Called with prepared list of installers to use for extensions recognition and installation.
      Parameters:
      installers - installers to use in correct order
    • getExtensionsHolder

      public ExtensionsHolder getExtensionsHolder()
      Returns:
      extensions holder object
    • registerExtensions

      public void registerExtensions(Class<?>... extensions)
      Parameters:
      extensions - extensions to register
    • registerExtensionsOptional

      public void registerExtensionsOptional(Class<?>... extensions)
      Parameters:
      extensions - optional extensions to register
    • getOrRegisterExtension

      public ExtensionItemInfoImpl getOrRegisterExtension(Class<?> extension, boolean fromScan)
      Extensions classpath scan requires testing with all installers to recognize actual extensions. To avoid duplicate installers recognition, extensions resolved by classpath scan are registered immediately. It's required because of not obvious method used for both manually registered extensions (to obtain container) and to create container from extensions from classpath scan.
      Parameters:
      extension - found extension
      fromScan - true when called for extension found in classpath scan, false for manually registered extension
      Returns:
      extension info container
    • getOrRegisterBindingExtension

      public ExtensionItemInfoImpl getOrRegisterBindingExtension(Class<?> extension, Class<? extends com.google.inject.Module> topScope)
      Registration of extension detected from guice binding. Descriptor for extension may already exists.

      Top guice module must be used because it's the only module, known by guicey configuration model and so the only way to show it properly on configuration report. Guice report can show extensions in correct positions, if required.

      Parameters:
      extension - extension class
      topScope - top module in registration modules hierarchy
      Returns:
      extension info container
    • notifyExtensionRecognized

      public void notifyExtensionRecognized(ExtensionItemInfoImpl extension)
      Extension recognized by installer, which means it is now completely initialized and disable predicates could be applied now.
      Parameters:
      extension - extension after setting installer
    • disableExtensions

      public void disableExtensions(Class<?>[] extensions)
      Extension manual disable registration from GuiceBundle.Builder.disableExtensions(Class[]).
      Parameters:
      extensions - extensions to disable
    • isExtensionEnabled

      public boolean isExtensionEnabled(Class<?> extension)
      Parameters:
      extension - extension type
      Returns:
      true if extension is enabled, false if disabled
    • getEnabledExtensions

      public List<Class<?>> getEnabledExtensions()
      Returns:
      all configured extensions (including resolved by scan)
    • getDisabledExtensions

      public List<Class<?>> getDisabledExtensions()
      Note: before configuration finalization this returns all actually disabled extensions and after finalization all disables (including never registered extensions).
      Returns:
      list of disabled extensions
    • setOption

      public <T extends Enum & Option> void setOption(T option, Object value)
      Type Parameters:
      T - helper type to define option
      Parameters:
      option - option enum
      value - option value (not null)
    • option

      public <V, T extends Enum & Option> V option(T option)
      Type Parameters:
      V - value type
      T - helper type to define option
      Parameters:
      option - option enum
      Returns:
      option value (set or default)
    • options

      public OptionsSupport options()
      Returns:
      options support object
    • optionsReadOnly

      public Options optionsReadOnly()
      Returns:
      read-only options
    • registerDisablePredicates

      public void registerDisablePredicates(Predicate<? extends ItemInfo>[] predicates)
      Register disable predicates, used to disable all matched items.

      After registration predicates are applied to all currently registered items to avoid registration order influence.

      Parameters:
      predicates - disable predicates
    • runHooks

      public void runHooks(GuiceBundle.Builder builder)
      Runs all registered hooks (at the end of manual builder configuration) and fire success event.
      Parameters:
      builder - bundle builder
    • initPhaseStarted

      public void initPhaseStarted(io.dropwizard.core.setup.Bootstrap bootstrap)
      Parameters:
      bootstrap - dropwizard bootstrap instance
    • runPhaseStarted

      public void runPhaseStarted(io.dropwizard.core.Configuration configuration, io.dropwizard.core.setup.Environment environment)
      Parameters:
      configuration - dropwizard configuration instance
      environment - dropwizard environment instance
    • finalizeConfiguration

      public void finalizeConfiguration()
      Called when context configuration is finished (but extensions installation is not finished yet). Merges disabled items configuration with registered items or creates new items to hold disable info.
    • bundleStarted

      public void bundleStarted()
      Called after complete guice bundle startup (other dropwizard bundle's run phase (for bundles registered after guice bundle) may not yet be called).
    • getItems

      public <T> List<T> getItems(ConfigItem type)
      Type Parameters:
      T - expected items type
      Parameters:
      type - config type
      Returns:
      list of all registered items of type or empty list
    • getItems

      public <T> List<T> getItems(ConfigItem type, Predicate<T> filter)
      Type Parameters:
      T - expected items type
      Parameters:
      type - config type
      filter - items filter
      Returns:
      list of all items matching filter or empty list
    • getIgnoredItems

      public <T> List<T> getIgnoredItems(ConfigItem type)
      Type Parameters:
      T - expected items type
      Parameters:
      type - config type
      Returns:
      list of all detected duplicates of this configuration type
    • getInfo

      public <T extends ItemInfoImpl> T getInfo(Object item)
      Type Parameters:
      T - expected container type
      Parameters:
      item - item to get info
      Returns:
      item registration info container or null if item not registered
    • stat

      public StatsTracker stat()
      Returns:
      startup statistics tracker instance
    • lifecycle

      public LifecycleSupport lifecycle()
      Returns:
      lifecycle events broadcaster
    • getBootstrap

      public io.dropwizard.core.setup.Bootstrap getBootstrap()
      Returns:
      dropwizard bootstrap object
    • getConfiguration

      public io.dropwizard.core.Configuration getConfiguration()
      Returns:
      dropwizard configuration object
    • getConfigurationTree

      public ConfigurationTree getConfigurationTree()
      Returns:
      introspected configuration object
    • getEnvironment

      public io.dropwizard.core.setup.Environment getEnvironment()
      Returns:
      dropwizard environment object
    • getSharedState

      public SharedConfigurationState getSharedState()
      Returns:
      application-wide registry object
    • getExecutedHookTypes

      public List<Class<? extends GuiceyConfigurationHook>> getExecutedHookTypes()
      Returns:
      types of executed hooks