Class ResourceInstaller
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.module.installer.option.InstallerOptionsSupport
-
- ru.vyarus.dropwizard.guice.module.installer.feature.jersey.AbstractJerseyInstaller<java.lang.Object>
-
- ru.vyarus.dropwizard.guice.module.installer.feature.jersey.ResourceInstaller
-
- All Implemented Interfaces:
FeatureInstaller
,BindingInstaller
,JerseyInstaller<java.lang.Object>
,TypeInstaller<java.lang.Object>
,WithOptions
public class ResourceInstaller extends AbstractJerseyInstaller<java.lang.Object> implements BindingInstaller, TypeInstaller<java.lang.Object>
Jersey resource installer. Search classes annotated withPath
or implementing interfaces annotated withPath
(only directly implemented). Directly register instance in jersey context to force singleton. If we register it by type, then we could use prototype beans (resource instance created on each request), which will lead to performance overhead. To ovoid misuse, singleton resources are forced, but not for beans having explicit scope annotation. SeeInstallersOptions.ForceSingletonForJerseyExtensions
.Prototype
annotation may be used to force prototype scope on guice beans (prevent forced singleton). This may be useful to avoid providers usage and directly inject request, response and other request specific beans. Note that jersey managed resources may use direct injections even in singletons (as jersey will use proxies instead of direct dependencies - implicit providers).- Since:
- 01.09.2014
-
-
Field Summary
-
Fields inherited from class ru.vyarus.dropwizard.guice.module.installer.feature.jersey.AbstractJerseyInstaller
logger
-
-
Constructor Summary
Constructors Constructor Description ResourceInstaller()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bind(com.google.inject.Binder binder, java.lang.Class<?> type, boolean lazyMarker)
Called to apply custom binding for installed feature.java.util.List<java.lang.String>
getRecognizableSigns()
Method used by extensions help report (GuiceBundle.Builder.printExtensionsHelp()
) to show what signs this exact installer recognize so user could better understand extensions support specifics.void
install(io.dropwizard.core.setup.Environment environment, java.lang.Class<java.lang.Object> type)
FullInjector
could be obtained withInjectorLookup.getInjector(Environment)
.void
install(org.glassfish.jersey.internal.inject.AbstractBinder binder, com.google.inject.Injector injector, java.lang.Class<java.lang.Object> type)
Called on jersey start to inject extensions into HK context.<T> void
manualBinding(com.google.inject.Binder binder, java.lang.Class<T> type, com.google.inject.Binding<T> binding)
Called for extensions, resolved from guice bindings (in user modules).boolean
matches(java.lang.Class<?> type)
NOTE: consider usingru.vyarus.dropwizard.guice.module.installer.util.FeatureUtils
to simplify checks (for example, types most likely must be checks to be not abstract).void
report()
Called to log registered endpoints in dropwizard log fashion.-
Methods inherited from class ru.vyarus.dropwizard.guice.module.installer.feature.jersey.AbstractJerseyInstaller
bindInGuice, isForceSingleton, isJerseyExtension, isLazy
-
Methods inherited from class ru.vyarus.dropwizard.guice.module.installer.option.InstallerOptionsSupport
option, setOptions
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ru.vyarus.dropwizard.guice.module.installer.install.binding.BindingInstaller
extensionBound
-
-
-
-
Method Detail
-
matches
public boolean matches(java.lang.Class<?> type)
Description copied from interface:FeatureInstaller
NOTE: consider usingru.vyarus.dropwizard.guice.module.installer.util.FeatureUtils
to simplify checks (for example, types most likely must be checks to be not abstract).When type accepted by any extension it's registered in guice module.
- Specified by:
matches
in interfaceFeatureInstaller
- Parameters:
type
- type to check- Returns:
- true if extension recognized, false otherwise
-
bind
public void bind(com.google.inject.Binder binder, java.lang.Class<?> type, boolean lazyMarker)
Description copied from interface:BindingInstaller
Called to apply custom binding for installed feature. By default, all found extensions are installed asbinder.bind(type)
. This method will be called instead of default registration.Called only for non binding extensions (extensions that are not already bound in guice module.
WARNING: may be called multiple times due to enabled bindings reporting! Be sure to produce correct logs.
- Specified by:
bind
in interfaceBindingInstaller
- Parameters:
binder
- guice bindertype
- extension classlazyMarker
- true if extension is annotated withLazyBinding
-
manualBinding
public <T> void manualBinding(com.google.inject.Binder binder, java.lang.Class<T> type, com.google.inject.Binding<T> binding)
Description copied from interface:BindingInstaller
Called for extensions, resolved from guice bindings (in user modules). May be used to validate binding or do some additional bindings with existing binding. Binding is detected primarily by main keyBinding.getKey()
, but linked bindings (LinkedKeyBinding
) are also checked for target key (LinkedKeyBinding.getLinkedKey()
).LazyBinding
flag is not used here because guicey will automatically throw an error if existing binding is annotated as lazy binding (which don't makes any sense).WARNING: may be called multiple times due to enabled bindings reporting! Be sure to produce correct logs.
- Specified by:
manualBinding
in interfaceBindingInstaller
- Type Parameters:
T
- extension type, used to connect extension class with binding- Parameters:
binder
- guice bindertype
- extension classbinding
- binding declaration from guice module- See Also:
for errors reporting
-
install
public void install(io.dropwizard.core.setup.Environment environment, java.lang.Class<java.lang.Object> type)
Description copied from interface:TypeInstaller
FullInjector
could be obtained withInjectorLookup.getInjector(Environment)
.Shared state could be obtained with
SharedConfigurationState.get(Environment)
- Specified by:
install
in interfaceTypeInstaller<java.lang.Object>
- Parameters:
environment
- environment objecttype
- extension type
-
install
public void install(org.glassfish.jersey.internal.inject.AbstractBinder binder, com.google.inject.Injector injector, java.lang.Class<java.lang.Object> type)
Description copied from interface:JerseyInstaller
Called on jersey start to inject extensions into HK context. UseJerseyBinding
utility for proper types binding: it provide utilities for various jersey extensions and use special "bridges" for registration to respect guice scopes (most of the time we not register ready instance, but factory which delegates creation to guice).- Specified by:
install
in interfaceJerseyInstaller<java.lang.Object>
- Parameters:
binder
- hk binderinjector
- guice injectortype
- extension type to register- See Also:
JerseyBinding
,JerseyManaged
-
report
public void report()
Description copied from interface:FeatureInstaller
Called to log registered endpoints in dropwizard log fashion. It's important to naturally show all dynamically resolved classes to easily catch errors. UseReporter
to simplify reporting.Method may do nothing if reporting not required
- Specified by:
report
in interfaceFeatureInstaller
-
getRecognizableSigns
public java.util.List<java.lang.String> getRecognizableSigns()
Description copied from interface:FeatureInstaller
Method used by extensions help report (GuiceBundle.Builder.printExtensionsHelp()
) to show what signs this exact installer recognize so user could better understand extensions support specifics.- Specified by:
getRecognizableSigns
in interfaceFeatureInstaller
- Returns:
- list of extension signs installer recognize
-
-