Class ConfigurationContext
java.lang.Object
ru.vyarus.dropwizard.guice.module.context.ConfigurationContext
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAutoScanFilter(Predicate<Class<?>> filter) Add extra filter for scanned classes (classpath scan and bindings recognition).voidAdd delayed configuration from the main builder (or hook) to run under run phase (when configuration would be available).voidCalled after complete guice bundle startup (other dropwizard bundle's run phase (for bundles registered after guice bundle) may not yet be called).voidClears current scope.voiddisableBundle(Class<? extends GuiceyBundle>[] bundles) Guicey bundle manual disable registration fromGuiceBundle.Builder.disableBundles(Class[]).voiddisableDropwizardBundle(Class<? extends io.dropwizard.core.ConfiguredBundle>[] bundles) Guicey bundle manual disable registration fromGuiceBundle.Builder.disableBundles(Class[]).voiddisableExtensions(Class<?>[] extensions) Extension manual disable registration fromGuiceBundle.Builder.disableExtensions(Class[]).voiddisableInstallers(Class<? extends FeatureInstaller>[] installers) Installer manual disable registration fromGuiceBundle.Builder.disableInstallers(Class[])orGuiceyBootstrap.disableInstallers(Class[]).voiddisableModules(Class<? extends com.google.inject.Module>[] modules) Guice module manual disable registration fromGuiceBundle.Builder.disableModules(Class[]).voidCalled when context configuration is finished (but extensions installation is not finished yet).io.dropwizard.core.setup.Bootstrapio.dropwizard.core.setup.BootstrapProxy object created on first access because of ~200ms creation overhead.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.ConfigurationNote: before configuration finalization this returns all actually disabled bundles and after finalization all disables (including never registered bundles).List<io.dropwizard.core.ConfiguredBundle>Note: before configuration finalization this returns all actually disabled extensions and after finalization all disables (including never registered extensions).List<Class<? extends FeatureInstaller>>Note: before configuration finalization this returns all actually disabled installers and after finalization all disables (including never registered installers).List<com.google.inject.Module>Note: before configuration finalization this returns all actually disabled modules and after finalization all disables (including never registered modules).List<io.dropwizard.core.ConfiguredBundle>List<Class<? extends FeatureInstaller>>List<com.google.inject.Module>NOTE: both normal and overriding modules.io.dropwizard.core.setup.EnvironmentList<Class<? extends GuiceyConfigurationHook>><T> List<T>getIgnoredItems(ConfigItem type) <T extends ItemInfoImpl>
T<T> List<T>getItems(ConfigItem type) <T> List<T>getItems(ConfigItem type, Predicate<T> filter) List<com.google.inject.Module>getOrRegisterBindingExtension(Class<?> extension, Class<? extends com.google.inject.Module> topScope) Registration of extension detected from guice binding.getOrRegisterExtension(Class<?> extension, boolean fromScan) Extensions classpath scan requires testing with all installers to recognize actual extensions.List<com.google.inject.Module>voidinitPhaseStarted(io.dropwizard.core.setup.Bootstrap bootstrap) voidinstallersResolved(List<FeatureInstaller> installers) Called with prepared list of installers to use for extensions recognition and installation.booleanisAcceptableAutoScanClass(Class<?> clazz) booleanBundle 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(Class<?> extension) voidnotifyExtensionRecognized(ExtensionItemInfoImpl extension) Extension recognized by installer, which means it is now completely initialized and disable predicates could be applied now.voidCurrent configuration context (application, bundle or classpath scan).option(T option) options()voidprocessDelayedConfigurations(GuiceyEnvironment environment) Process delayed builder (or hooks) configurations.registerBundles(GuiceyBundle... bundles) Usual bundle registration fromGuiceBundle.Builder.bundles(GuiceyBundle...)orGuiceyBootstrap.bundles(GuiceyBundle...).voidregisterCommands(List<Class<io.dropwizard.core.cli.Command>> commands) Register commands resolved with classpath scan.voidregisterDisablePredicates(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(Class<?>... extensions) Usual extension registration fromGuiceBundle.Builder.extensions(Class[])orGuiceyBootstrap.extensions(Class[]).voidregisterExtensionsOptional(Class<?>... extensions) Optional extension registration fromGuiceBundle.Builder.extensionsOptional(Class[])orGuiceyBootstrap.extensionsOptional(Class[]).voidregisterInstallers(Class<? extends FeatureInstaller>[] installers) Usual installer registration fromGuiceBundle.Builder.installers(Class[])orGuiceyBootstrap.installers(Class[]).voidregisterInstallersFromScan(List<Class<? extends FeatureInstaller>> installers) Register installers from classpath scan.voidregisterLookupBundles(List<GuiceyBundle> bundles) Register bundles resolved by lookup mechanism.voidregisterModules(com.google.inject.Module... modules) voidregisterModulesOverride(com.google.inject.Module... modules) replaceContextScope(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.stat()voidstoreBundlesInitOrder(List<GuiceyBundle> orderedBundles) Store initialization order of bundles.
-
Constructor Details
-
ConfigurationContext
public ConfigurationContext()Create a context.
-
-
Method Details
-
addAutoScanFilter
Add extra filter for scanned classes (classpath scan and bindings recognition).- Parameters:
filter- filter instance
-
isAcceptableAutoScanClass
- Parameters:
clazz- class to test- Returns:
- true if extension class could be used, false otherwise (auto scan filter)
-
setDuplicatesDetector
Change default duplicates detector.- Parameters:
detector- new policy
-
addDelayedConfiguration
Add delayed configuration from the main builder (or hook) to run under run phase (when configuration would be available).- Parameters:
config- delayed configuration
-
processDelayedConfigurations
Process delayed builder (or hooks) configurations.- Parameters:
environment- guicey environment
-
openScope
Current configuration context (application, bundle or classpath scan).- Parameters:
scope- scope key
-
replaceContextScope
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
Register commands resolved with classpath scan.- Parameters:
commands- installed commands- See Also:
-
registerLookupBundles
Register bundles resolved by lookup mechanism.GuiceyBundleLookupused as context.- Parameters:
bundles- bundles resolved by lookup mechanism- See Also:
-
registerBundles
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
Guicey bundle manual disable registration fromGuiceBundle.Builder.disableBundles(Class[]).- Parameters:
bundles- modules to disable
-
getEnabledBundles
- Returns:
- all configured bundles (without duplicates)
-
storeBundlesInitOrder
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
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
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
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
Guicey bundle manual disable registration fromGuiceBundle.Builder.disableBundles(Class[]).- Parameters:
bundles- modules to disable
-
getEnabledDropwizardBundles
- Returns:
- all configured dropwizard bundles (without duplicates)
-
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
Guice module manual disable registration fromGuiceBundle.Builder.disableModules(Class[]).- Parameters:
modules- modules to disable
-
getEnabledModules
NOTE: both normal and overriding modules.- Returns:
- all configured and enabled guice modules (without duplicates)
-
getNormalModules
- Returns:
- list of all enabled normal guice modules or empty list
-
getOverridingModules
- Returns:
- list of all enabled overriding modules or empty list
-
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
- Returns:
- all disabled module types, including never registered
-
registerInstallers
Usual installer registration fromGuiceBundle.Builder.installers(Class[])orGuiceyBootstrap.installers(Class[]).- Parameters:
installers- installers to register
-
registerInstallersFromScan
Register installers from classpath scan. UseClasspathScanneras context class.- Parameters:
installers- installers found by classpath scan
-
disableInstallers
Installer manual disable registration fromGuiceBundle.Builder.disableInstallers(Class[])orGuiceyBootstrap.disableInstallers(Class[]).- Parameters:
installers- installers to disable
-
getEnabledInstallers
- Returns:
- all configured and enabled installers (including resolved by scan)
-
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
Called with prepared list of installers to use for extensions recognition and installation.- Parameters:
installers- installers to use in correct order
-
getExtensionsHolder
- Returns:
- extensions holder object
-
registerExtensions
Usual extension registration fromGuiceBundle.Builder.extensions(Class[])orGuiceyBootstrap.extensions(Class[]).- Parameters:
extensions- extensions to register
-
registerExtensionsOptional
Optional extension registration fromGuiceBundle.Builder.extensionsOptional(Class[])orGuiceyBootstrap.extensionsOptional(Class[]).- Parameters:
extensions- optional extensions to register
-
getOrRegisterExtension
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(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 classtopScope- top module in registration modules hierarchy- Returns:
- extension info container
-
notifyExtensionRecognized
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
Extension manual disable registration fromGuiceBundle.Builder.disableExtensions(Class[]).- Parameters:
extensions- extensions to disable
-
isExtensionEnabled
- Parameters:
extension- extension type- Returns:
- true if extension is enabled, false if disabled
-
getEnabledExtensions
- Returns:
- all configured extensions (including resolved by scan)
-
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
- Type Parameters:
T- helper type to define option- Parameters:
option- option enumvalue- option value (not null)
-
option
- Type Parameters:
V- value typeT- helper type to define option- Parameters:
option- option enum- Returns:
- option value (set or default)
-
options
- Returns:
- options support object
-
optionsReadOnly
- Returns:
- read-only options
-
registerDisablePredicates
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
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
- Type Parameters:
T- expected items type- Parameters:
type- config type- Returns:
- list of all registered items of type or empty list
-
getItems
- Type Parameters:
T- expected items type- Parameters:
type- config typefilter- items filter- Returns:
- list of all items matching filter or empty list
-
getIgnoredItems
- Type Parameters:
T- expected items type- Parameters:
type- config type- Returns:
- list of all detected duplicates of this configuration type
-
getInfo
- Type Parameters:
T- expected container type- Parameters:
item- item to get info- Returns:
- item registration info container or null if item not registered
-
stat
- Returns:
- startup statistics tracker instance
-
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
- Returns:
- introspected configuration object
-
getEnvironment
public io.dropwizard.core.setup.Environment getEnvironment()- Returns:
- dropwizard environment object
-
getExecutedHookTypes
- Returns:
- types of executed hooks
-