Class ConfigurationContext
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.module.context.ConfigurationContext
-
public final class ConfigurationContext extends java.lang.ObjectConfiguration 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
DisableSupportsign). 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 Summary
Constructors Constructor Description ConfigurationContext()Create a context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAutoScanFilter(java.util.function.Predicate<java.lang.Class<?>> filter)Add extra filter for scanned classes (classpath scan and bindings recognition).voidaddDelayedConfiguration(java.util.function.Consumer<GuiceyEnvironment> config)Add delayed configuration from the main builder (or hook) to run under run phase (when configuration would be available).voidbundleStarted()Called after complete guice bundle startup (other dropwizard bundle's run phase (for bundles registered after guice bundle) may not yet be called).voidcloseScope()Clears current scope.voiddisableBundle(java.lang.Class<? extends GuiceyBundle>[] bundles)Guicey bundle manual disable registration fromGuiceBundle.Builder.disableBundles(Class[]).voiddisableDropwizardBundle(java.lang.Class<? extends io.dropwizard.core.ConfiguredBundle>[] bundles)Guicey bundle manual disable registration fromGuiceBundle.Builder.disableBundles(Class[]).voiddisableExtensions(java.lang.Class<?>[] extensions)Extension manual disable registration fromGuiceBundle.Builder.disableExtensions(Class[]).voiddisableInstallers(java.lang.Class<? extends FeatureInstaller>[] installers)Installer manual disable registration fromGuiceBundle.Builder.disableInstallers(Class[])orGuiceyBootstrap.disableInstallers(Class[]).voiddisableModules(java.lang.Class<? extends com.google.inject.Module>[] modules)Guice module manual disable registration fromGuiceBundle.Builder.disableModules(Class[]).voidfinalizeConfiguration()Called when context configuration is finished (but extensions installation is not finished yet).io.dropwizard.core.setup.BootstrapgetBootstrap()io.dropwizard.core.setup.BootstrapgetBootstrapProxy()Proxy object created on first access because of ~200ms creation overhead.java.util.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).io.dropwizard.core.ConfigurationgetConfiguration()ConfigurationTreegetConfigurationTree()java.util.List<GuiceyBundle>getDisabledBundles()Note: before configuration finalization this returns all actually disabled bundles and after finalization all disables (including never registered bundles).java.util.List<io.dropwizard.core.ConfiguredBundle>getDisabledDropwizardBundles()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).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).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).java.util.List<java.lang.Class<java.lang.Object>>getDisabledModuleTypes()java.util.List<GuiceyBundle>getEnabledBundles()java.util.List<io.dropwizard.core.ConfiguredBundle>getEnabledDropwizardBundles()java.util.List<java.lang.Class<?>>getEnabledExtensions()java.util.List<java.lang.Class<? extends FeatureInstaller>>getEnabledInstallers()java.util.List<com.google.inject.Module>getEnabledModules()NOTE: both normal and overriding modules.io.dropwizard.core.setup.EnvironmentgetEnvironment()java.util.List<java.lang.Class<? extends GuiceyConfigurationHook>>getExecutedHookTypes()ExtensionsHoldergetExtensionsHolder()<T> java.util.List<T>getIgnoredItems(ConfigItem type)<T extends ItemInfoImpl>
TgetInfo(java.lang.Object item)<T> java.util.List<T>getItems(ConfigItem type)<T> java.util.List<T>getItems(ConfigItem type, java.util.function.Predicate<T> filter)java.util.List<com.google.inject.Module>getNormalModules()ExtensionItemInfoImplgetOrRegisterBindingExtension(java.lang.Class<?> extension, java.lang.Class<? extends com.google.inject.Module> topScope)Registration of extension detected from guice binding.ExtensionItemInfoImplgetOrRegisterExtension(java.lang.Class<?> extension, boolean fromScan)Extensions classpath scan requires testing with all installers to recognize actual extensions.java.util.List<com.google.inject.Module>getOverridingModules()SharedConfigurationStategetSharedState()voidinitPhaseStarted(io.dropwizard.core.setup.Bootstrap bootstrap)voidinstallersResolved(java.util.List<FeatureInstaller> installers)Called with prepared list of installers to use for extensions recognition and installation.booleanisAcceptableAutoScanClass(java.lang.Class<?> clazz)booleanisBundleEnabled(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).booleanisExtensionEnabled(java.lang.Class<?> extension)LifecycleSupportlifecycle()voidnotifyExtensionRecognized(ExtensionItemInfoImpl extension)Extension recognized by installer, which means it is now completely initialized and disable predicates could be applied now.voidopenScope(ItemId scope)Current configuration context (application, bundle or classpath scan).<V,T extends java.lang.Enum & Option>
Voption(T option)OptionsSupportoptions()OptionsoptionsReadOnly()voidprocessDelayedConfigurations(GuiceyEnvironment environment)Process delayed builder (or hooks) configurations.java.util.List<GuiceyBundle>registerBundles(GuiceyBundle... bundles)Usual bundle registration fromGuiceBundle.Builder.bundles(GuiceyBundle...)orGuiceyBootstrap.bundles(GuiceyBundle...).voidregisterCommands(java.util.List<java.lang.Class<io.dropwizard.core.cli.Command>> commands)Register commands resolved with classpath scan.voidregisterDisablePredicates(java.util.function.Predicate<? extends ItemInfo>[] predicates)Register disable predicates, used to disable all matched items.voidregisterDropwizardBundles(io.dropwizard.core.ConfiguredBundle... bundles)Direct dropwizard bundle registration fromGuiceBundle.Builder.dropwizardBundles(ConfiguredBundle...)orGuiceyBootstrap.dropwizardBundles( ConfiguredBundle[]).voidregisterExtensions(java.lang.Class<?>... extensions)Usual extension registration fromGuiceBundle.Builder.extensions(Class[])orGuiceyBootstrap.extensions(Class[]).voidregisterExtensionsOptional(java.lang.Class<?>... extensions)Optional extension registration fromGuiceBundle.Builder.extensionsOptional(Class[])orGuiceyBootstrap.extensionsOptional(Class[]).voidregisterInstallers(java.lang.Class<? extends FeatureInstaller>[] installers)Usual installer registration fromGuiceBundle.Builder.installers(Class[])orGuiceyBootstrap.installers(Class[]).voidregisterInstallersFromScan(java.util.List<java.lang.Class<? extends FeatureInstaller>> installers)Register installers from classpath scan.voidregisterLookupBundles(java.util.List<GuiceyBundle> bundles)Register bundles resolved by lookup mechanism.voidregisterModules(com.google.inject.Module... modules)voidregisterModulesOverride(com.google.inject.Module... modules)ItemIdreplaceContextScope(ItemId scope)Declares possibly sub-configuration context.voidrunHooks(GuiceBundle.Builder builder)Runs all registered hooks (at the end of manual builder configuration) and fire success event.voidrunPhaseStarted(io.dropwizard.core.Configuration configuration, io.dropwizard.core.setup.Environment environment)voidsetDuplicatesDetector(DuplicateConfigDetector detector)Change default duplicates detector.<T extends java.lang.Enum & Option>
voidsetOption(T option, java.lang.Object value)StatsTrackerstat()voidstoreBundlesInitOrder(java.util.List<GuiceyBundle> orderedBundles)Store initialization order of bundles.
-
-
-
Method Detail
-
addAutoScanFilter
public void addAutoScanFilter(java.util.function.Predicate<java.lang.Class<?>> filter)
Add extra filter for scanned classes (classpath scan and bindings recognition).- Parameters:
filter- filter instance
-
isAcceptableAutoScanClass
public boolean isAcceptableAutoScanClass(java.lang.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(java.util.function.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(java.util.List<java.lang.Class<io.dropwizard.core.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.GuiceyBundleLookupused as context.- Parameters:
bundles- bundles resolved by lookup mechanism- See Also:
GuiceyBundleLookup
-
registerBundles
public java.util.List<GuiceyBundle> registerBundles(GuiceyBundle... bundles)
Usual bundle registration fromGuiceBundle.Builder.bundles(GuiceyBundle...)orGuiceyBootstrap.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(java.lang.Class<? extends GuiceyBundle>[] bundles)
Guicey bundle manual disable registration fromGuiceBundle.Builder.disableBundles(Class[]).- Parameters:
bundles- modules to disable
-
getEnabledBundles
public java.util.List<GuiceyBundle> getEnabledBundles()
- Returns:
- all configured bundles (without duplicates)
-
storeBundlesInitOrder
public void storeBundlesInitOrder(java.util.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 java.util.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 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
-
registerDropwizardBundles
public void registerDropwizardBundles(io.dropwizard.core.ConfiguredBundle... bundles)
Direct dropwizard bundle registration fromGuiceBundle.Builder.dropwizardBundles(ConfiguredBundle...)orGuiceyBootstrap.dropwizardBundles( ConfiguredBundle[]). Context class is set to currently processed bundle.- Parameters:
bundles- dropwizard bundles
-
disableDropwizardBundle
public void disableDropwizardBundle(java.lang.Class<? extends io.dropwizard.core.ConfiguredBundle>[] bundles)
Guicey bundle manual disable registration fromGuiceBundle.Builder.disableBundles(Class[]).- Parameters:
bundles- modules to disable
-
getEnabledDropwizardBundles
public java.util.List<io.dropwizard.core.ConfiguredBundle> getEnabledDropwizardBundles()
- Returns:
- all configured dropwizard bundles (without duplicates)
-
getDisabledDropwizardBundles
public java.util.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(java.lang.Class<? extends com.google.inject.Module>[] modules)
Guice module manual disable registration fromGuiceBundle.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
-
registerInstallers
public void registerInstallers(java.lang.Class<? extends FeatureInstaller>[] installers)
Usual installer registration fromGuiceBundle.Builder.installers(Class[])orGuiceyBootstrap.installers(Class[]).- Parameters:
installers- installers to register
-
registerInstallersFromScan
public void registerInstallersFromScan(java.util.List<java.lang.Class<? extends FeatureInstaller>> installers)
Register installers from classpath scan. UseClasspathScanneras context class.- Parameters:
installers- installers found by classpath scan
-
disableInstallers
public void disableInstallers(java.lang.Class<? extends FeatureInstaller>[] installers)
Installer manual disable registration fromGuiceBundle.Builder.disableInstallers(Class[])orGuiceyBootstrap.disableInstallers(Class[]).- Parameters:
installers- installers to disable
-
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
-
registerExtensions
public void registerExtensions(java.lang.Class<?>... extensions)
Usual extension registration fromGuiceBundle.Builder.extensions(Class[])orGuiceyBootstrap.extensions(Class[]).- Parameters:
extensions- extensions to register
-
registerExtensionsOptional
public void registerExtensionsOptional(java.lang.Class<?>... extensions)
Optional extension registration fromGuiceBundle.Builder.extensionsOptional(Class[])orGuiceyBootstrap.extensionsOptional(Class[]).- Parameters:
extensions- optional extensions to register
-
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 extensionfromScan- 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 classtopScope- 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(java.lang.Class<?>[] extensions)
Extension manual disable registration fromGuiceBundle.Builder.disableExtensions(Class[]).- Parameters:
extensions- extensions to disable
-
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 enumvalue- option value (not null)
-
option
public <V,T extends java.lang.Enum & Option> V option(T option)
- Type Parameters:
V- value typeT- 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(java.util.function.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 instanceenvironment- 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 typefilter- 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.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 java.util.List<java.lang.Class<? extends GuiceyConfigurationHook>> getExecutedHookTypes()
- Returns:
- types of executed hooks
-
-