public class GuiceyBootstrap
extends java.lang.Object
GuiceBundle.Builder. Also, contains dropwizard bootstrap objects.
May register pure dropwizard bundles.
In contrast to main builder, guicey bundle can't:
GuiceyConfigurationHook
(because it's too late - all hooks were processed)| Constructor and Description |
|---|
GuiceyBootstrap(ConfigurationContext context,
java.util.List<GuiceyBundle> iterationBundles) |
| Modifier and Type | Method and Description |
|---|---|
io.dropwizard.Application |
application()
Application instance may be useful for complex (half manual) integrations where access for
injector is required.
|
<T extends io.dropwizard.Configuration> |
bootstrap()
Note: application is already in run phase, so it's too late to configure dropwizard bootstrap object.
|
GuiceyBootstrap |
bundles(GuiceyBundle... bundles)
Register other guicey bundles for installation.
|
GuiceyBootstrap |
disableExtensions(java.lang.Class<?>... extensions) |
GuiceyBootstrap |
disableInstallers(java.lang.Class<? extends FeatureInstaller>... installers) |
GuiceyBootstrap |
disableModules(java.lang.Class<? extends com.google.inject.Module>... modules)
Disable both usual and overriding guice modules.
|
GuiceyBootstrap |
dropwizardBundles(io.dropwizard.ConfiguredBundle... bundles)
Shortcut for dropwizard bundles registration (instead of
bootstrap().addBundle()), but with
duplicates detection and tracking in diagnostic reporting. |
GuiceyBootstrap |
extensions(java.lang.Class<?>... extensionClasses)
Bundle should not rely on auto-scan mechanism and so must declare all extensions manually
(this better declares bundle content and speed ups startup).
|
GuiceyBootstrap |
extensionsOptional(java.lang.Class<?>... extensionClasses)
The same as
extensions(Class[]), but, in case if no installer recognize extension, will be
automatically disabled instead of throwing error. |
GuiceyBootstrap |
installers(java.lang.Class<? extends FeatureInstaller>... installers)
If bundle provides new installers then they must be declared here.
|
GuiceyBootstrap |
listen(GuiceyLifecycleListener... listeners)
Guicey broadcast a lot of events in order to indicate lifecycle phases
(GuiceyLifecycle).
|
GuiceyBootstrap |
modules(com.google.inject.Module... modules)
Register guice modules.
|
GuiceyBootstrap |
modulesOverride(com.google.inject.Module... modules)
Override modules (using guice
Modules.override(Module...)). |
<V,T extends java.lang.Enum & Option> |
option(T option)
Read option value.
|
<T> T |
sharedState(java.lang.Class<?> key,
java.util.function.Supplier<T> defaultValue)
Alternative shared value initialization for cases when first accessed bundle should init state value
and all other just use it.
|
<T> T |
sharedStateOrFail(java.lang.Class<?> key,
java.lang.String message,
java.lang.Object... args)
Use to access shared state value and immediately fail if value not yet set (most likely due to incorrect
configuration order).
|
GuiceyBootstrap |
shareState(java.lang.Class<?> key,
java.lang.Object value)
Share global state to be used in other bundles (during configuration).
|
public GuiceyBootstrap(ConfigurationContext context, java.util.List<GuiceyBundle> iterationBundles)
public <T extends io.dropwizard.Configuration> io.dropwizard.setup.Bootstrap<T> bootstrap()
T - configuration typepublic io.dropwizard.Application application()
Managed may access injector in it's start method by calling
InjectorLookup.getInjector(Application).
NOTE: it will work in this example, because injector access will be after injector creation. Directly inside bundle initialization method injector could not be obtained as it's not exists yet.
public <V,T extends java.lang.Enum & Option> V option(T option)
GuiceBundle.Builder.option(Enum, Object).
If value wasn't set there then default value will be returned. Null may return only if it was default value
and no new value were assigned.
Option access is tracked as option usage (all tracked data is available through
OptionsInfo).
V - option value typeT - helper type to define optionoption - option enummore options info,
options example,
options definitionpublic GuiceyBootstrap modules(com.google.inject.Module... modules)
Note that this registration appear under initialization phase and so neither configuration nor environment
objects are not available yet. If you need them for module, then you can wrap it with
DropwizardAwareModule or register modules in run phase
(inside GuiceyBundle.run(GuiceyEnvironment)).
modules - one or more guice modulesGuiceBundle.Builder.modules(com.google.inject.Module...),
DropwizardAwareModulepublic GuiceyBootstrap modulesOverride(com.google.inject.Module... modules)
Modules.override(Module...)).modules - overriding modulesGuiceBundle.Builder.modulesOverride(Module...)@SafeVarargs public final GuiceyBootstrap installers(java.lang.Class<? extends FeatureInstaller>... installers)
installers - feature installer classes to registerGuiceBundle.Builder.installers(Class[])public GuiceyBootstrap extensions(java.lang.Class<?>... extensionClasses)
NOTE: startup will fail if bean not recognized by installers. Use extensionsOptional(Class[]) to
register optional extension.
Alternatively, you can manually bind extensions in guice module and they would be recognized
(GuiceyOptions.AnalyzeGuiceModules).
extensionClasses - extension bean classes to registerGuiceBundle.Builder.extensions(Class[])public GuiceyBootstrap extensionsOptional(java.lang.Class<?>... extensionClasses)
extensions(Class[]), but, in case if no installer recognize extension, will be
automatically disabled instead of throwing error. Useful for optional extensions declaration in 3rd party
bundles (where it is impossible to be sure what other bundles will be used and so what installers will
be available).
Alternatively, you can manually bind extensions in guice module and they would be recognized
(GuiceyOptions.AnalyzeGuiceModules). Extensions with no available target
installer will simply wouldn't be detected (because installers used for recognition) and so there is no need
to mark them as optional in this case.
extensionClasses - extension bean classes to registerpublic GuiceyBootstrap bundles(GuiceyBundle... bundles)
Equal instances of the same type will be considered as duplicate.
bundles - guicey bundlesGuiceBundle.Builder.bundles(GuiceyBundle...)public GuiceyBootstrap dropwizardBundles(io.dropwizard.ConfiguredBundle... bundles)
bootstrap().addBundle()), but with
duplicates detection and tracking in diagnostic reporting. Dropwizard bundle is immediately initialized.bundles - dropwizard bundles to registerGuiceBundle.Builder.dropwizardBundles(ConfiguredBundle...)@SafeVarargs public final GuiceyBootstrap disableInstallers(java.lang.Class<? extends FeatureInstaller>... installers)
installers - feature installer types to disableGuiceBundle.Builder.disableInstallers(Class[])public final GuiceyBootstrap disableExtensions(java.lang.Class<?>... extensions)
extensions - extensions to disable (manually added, registered by bundles or with classpath scan)GuiceBundle.Builder.disableExtensions(Class[])@SafeVarargs public final GuiceyBootstrap disableModules(java.lang.Class<? extends com.google.inject.Module>... modules)
If bindings analysis is not disabled, could also disable inner (transitive) modules, but only inside normal modules.
modules - guice module types to disableGuiceBundle.Builder.disableModules(Class[])public GuiceyBootstrap listen(GuiceyLifecycleListener... listeners)
GuiceyLifecycle.BundlesInitialized.
Listener is not registered if equal listener was already registered (Set used as
listeners storage), so if you need to be sure that only one instance of some listener will be used
implement Object.equals(Object).
listeners - guicey lifecycle listenersGuiceBundle.Builder.listen(GuiceyLifecycleListener...)public GuiceyBootstrap shareState(java.lang.Class<?> key, java.lang.Object value)
Internally, state is linked to application instance so it would be safe to use with concurrent tests.
Value could be accessed statically with application instance:
SharedConfigurationState.lookup(Application, Class).
Use bundle class as key. Value could be set only once (to prevent hard to track situations).
If initialization point could vary (first access should initialize it) use sharedState(Class, Supplier)
instead.
key - shared object keyvalue - shared objectSharedConfigurationStatepublic <T> T sharedState(java.lang.Class<?> key,
java.util.function.Supplier<T> defaultValue)
T - shared object typekey - shared object keydefaultValue - default object providerSharedConfigurationStatepublic <T> T sharedStateOrFail(java.lang.Class<?> key,
java.lang.String message,
java.lang.Object... args)
T - shared object typekey - shared object keymessage - exception message (could use String.format(String, Object...) placeholders)args - placeholder arguments for error messagejava.lang.IllegalStateException - if no value availableSharedConfigurationState