Class ConfigurationContext


  • public final class ConfigurationContext
    extends java.lang.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:
    for details of tracked info, for acessing collected info at runtime
    • Constructor Detail

      • ConfigurationContext

        public ConfigurationContext()
    • Method Detail

      • setDuplicatesDetector

        public void setDuplicatesDetector​(DuplicateConfigDetector detector)
        Change default duplicates detector.
        Parameters:
        detector - new policy
      • 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​(java.util.List<java.lang.Class<io.dropwizard.cli.Command>> commands)
        Register commands resolved with classpath scan.
        Parameters:
        commands - installed commands
        See Also:
        GuiceBundle.Builder.searchCommands()
      • registerLookupBundles

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

        public java.util.List<GuiceyBundle> getEnabledBundles()
        Returns:
        all configured bundles (without duplicates)
      • getDisabledBundles

        public java.util.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
      • disableDropwizardBundle

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

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

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

        public io.dropwizard.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​(java.lang.Class<? extends com.google.inject.Module>[] modules)
        Guice module manual disable registration from GuiceBundle.Builder.disableModules(Class[]).
        Parameters:
        modules - modules to disable
      • getEnabledModules

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

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

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

        public java.util.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 java.util.List<java.lang.Class<java.lang.Object>> getDisabledModuleTypes()
        Returns:
        all disabled module types, including never registered
      • registerInstallersFromScan

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

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

        public java.util.List<java.lang.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​(java.util.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
      • getOrRegisterExtension

        public ExtensionItemInfoImpl getOrRegisterExtension​(java.lang.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​(java.lang.Class<?> extension,
                                                                   java.lang.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
      • isExtensionEnabled

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

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

        public java.util.List<java.lang.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 java.lang.Enum & Option> void setOption​(T option,
                                                                  java.lang.Object value)
        Type Parameters:
        T - helper type to define option
        Parameters:
        option - option enum
        value - option value (not null)
      • option

        public <V,​T extends java.lang.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
      • registerDisablePredicates

        public void registerDisablePredicates​(java.util.function.Predicate<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.setup.Bootstrap bootstrap)
        Parameters:
        bootstrap - dropwizard bootstrap instance
      • runPhaseStarted

        public void runPhaseStarted​(io.dropwizard.Configuration configuration,
                                    io.dropwizard.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> java.util.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> java.util.List<T> getItems​(ConfigItem type,
                                              java.util.function.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> java.util.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​(java.lang.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.setup.Bootstrap getBootstrap()
        Returns:
        dropwizard bootstrap object
      • getConfiguration

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

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

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