Class DefaultComponentFactory
- java.lang.Object
-
- io.streamthoughts.azkarra.runtime.components.DefaultComponentFactory
-
- All Implemented Interfaces:
ComponentDescriptorRegistry
,ComponentFactory
,ComponentRegistry
,ConditionalDescriptorRegistry
,Closeable
,AutoCloseable
public class DefaultComponentFactory extends Object implements ComponentFactory
The defaultComponentRegistry
implementation.
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Logger
LOG
-
Constructor Summary
Constructors Constructor Description DefaultComponentFactory(ComponentDescriptorFactory descriptorFactory)
Creates a newDefaultComponentFactory
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
<T> boolean
containsComponent(Class<T> type)
Checks if at least one component is registered for the given type.<T> boolean
containsComponent(Class<T> type, Qualifier<T> qualifier)
Checks if at least one component is registered for the given type and qualifier.boolean
containsComponent(String alias)
Checks if at least one component is registered for the given type.<T> boolean
containsComponent(String type, Qualifier<T> qualifier)
Checks if at least one component is registered for the given type and qualifier.<T> Collection<ComponentDescriptor<T>>
findAllDescriptorsByAlias(String alias)
Finds allComponentDescriptor
registered for the specified alias.<T> Collection<ComponentDescriptor<T>>
findAllDescriptorsByAlias(String alias, ComponentConditionalContext context)
Finds allComponentDescriptor
registered for the specified alias.<T> Collection<ComponentDescriptor<T>>
findAllDescriptorsByAlias(String alias, ComponentConditionalContext context, Qualifier<T> qualifier)
Finds allComponentDescriptor
registered for the specified alias.<T> Collection<ComponentDescriptor<T>>
findAllDescriptorsByAlias(String alias, Qualifier<T> qualifier)
Finds allComponentDescriptor
registered for the specified alias.<T> Collection<ComponentDescriptor<T>>
findAllDescriptorsByClass(Class<T> type)
Finds allComponentDescriptor
registered for the specified type.<T> Collection<ComponentDescriptor<T>>
findAllDescriptorsByClass(Class<T> type, ComponentConditionalContext context)
Finds allComponentDescriptor
registered for the specified type.<T> Collection<ComponentDescriptor<T>>
findAllDescriptorsByClass(Class<T> type, ComponentConditionalContext context, Qualifier<T> qualifier)
Finds allComponentDescriptor
registered for the specified type.<T> Collection<ComponentDescriptor<T>>
findAllDescriptorsByClass(Class<T> type, Qualifier<T> qualifier)
Finds allComponentDescriptor
registered for the specified type.<T> Optional<ComponentDescriptor<T>>
findDescriptorByAlias(String alias)
Finds aComponentDescriptor
for the specified type.<T> Optional<ComponentDescriptor<T>>
findDescriptorByAlias(String alias, ComponentConditionalContext context)
Finds aComponentDescriptor
for the specified type.<T> Optional<ComponentDescriptor<T>>
findDescriptorByAlias(String alias, ComponentConditionalContext context, Qualifier<T> qualifier)
Finds aComponentDescriptor
for the specified type and options.<T> Optional<ComponentDescriptor<T>>
findDescriptorByAlias(String alias, Qualifier<T> qualifier)
Finds aComponentDescriptor
for the specified type and options.<T> Optional<ComponentDescriptor<T>>
findDescriptorByClass(Class<T> type)
Finds aComponentDescriptor
for the specified type.<T> Optional<ComponentDescriptor<T>>
findDescriptorByClass(Class<T> type, ComponentConditionalContext context)
Finds aComponentDescriptor
for the specified type.<T> Optional<ComponentDescriptor<T>>
findDescriptorByClass(Class<T> type, ComponentConditionalContext context, Qualifier<T> qualifier)
Finds aComponentDescriptor
for the specified type and options.<T> Optional<ComponentDescriptor<T>>
findDescriptorByClass(Class<T> type, Qualifier<T> qualifier)
Finds aComponentDescriptor
for the specified type and options.<T> Collection<GettableComponent<T>>
getAllComponentProviders(Class<T> type, Qualifier<T> qualifier)
Gets all instances, which may be shared or independent, for the specified type.<T> Collection<T>
getAllComponents(Class<T> type, Conf conf)
Gets all instances, which may be shared or independent, for the specified type.<T> Collection<T>
getAllComponents(Class<T> type, Conf conf, Qualifier<T> qualifier)
Gets all instances, which may be shared or independent, for the specified type.<T> Collection<T>
getAllComponents(String alias, Conf conf)
Gets all instances, which may be shared or independent, for the specified type.<T> Collection<T>
getAllComponents(String alias, Conf conf, Qualifier<T> qualifier)
Gets all instances, which may be shared or independent, for the specified type.<T> T
getComponent(Class<T> type, Conf conf)
Gets an instance, which may be shared or independent, for the specified type.<T> T
getComponent(Class<T> type, Conf conf, Qualifier<T> qualifier)
Gets an instance, which may be shared or independent, for the specified type.<T> T
getComponent(String alias, Conf conf)
Gets an instance, which may be shared or independent, for the specified type.<T> T
getComponent(String alias, Conf conf, Qualifier<T> qualifier)
Gets an instance, which may be shared or independent, for the specified type.<T> GettableComponent<T>
getComponentProvider(Class<T> type, Qualifier<T> qualifier)
Gets an instance, which may be shared or independent, for the specified type.void
init(Conf conf)
Initialize the component factory for the given configuration.<T> void
registerComponent(String componentName, Class<T> componentClass, ComponentDescriptorModifier... modifiers)
Registers the component supplier for the specified type and name.<T> void
registerComponent(String componentName, Class<T> componentClass, Supplier<T> supplier, ComponentDescriptorModifier... modifiers)
Registers the component supplier for the specified type and name.<T> void
registerDescriptor(ComponentDescriptor<T> descriptor)
Registers the specifiedComponentDescriptor
to thisComponentRegistry
.<T> void
registerSingleton(String componentName, Class<T> componentClass, ComponentDescriptorModifier... modifiers)
Registers a singleton no-arg constructor component supplier for the specified type.<T> void
registerSingleton(String componentName, Class<T> componentClass, Supplier<T> singleton, ComponentDescriptorModifier... modifiers)
Registers the component supplier for the specified type and name.<T> void
registerSingleton(T singleton)
Register the specified shared instance.DefaultComponentFactory
setComponentAliasesGenerator(ComponentAliasesGenerator aliasesGenerator)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.streamthoughts.azkarra.api.components.ComponentRegistry
registerComponent, registerComponent, registerSingleton, registerSingleton
-
-
-
-
Constructor Detail
-
DefaultComponentFactory
public DefaultComponentFactory(ComponentDescriptorFactory descriptorFactory)
Creates a newDefaultComponentFactory
instance.
-
-
Method Detail
-
containsComponent
public boolean containsComponent(String alias)
Checks if at least one component is registered for the given type.- Specified by:
containsComponent
in interfaceComponentFactory
- Parameters:
alias
- the fully qualified class name or an alias of the component.- Returns:
true
if a provider exist,false
otherwise.
-
containsComponent
public <T> boolean containsComponent(String type, Qualifier<T> qualifier)
Checks if at least one component is registered for the given type and qualifier.- Specified by:
containsComponent
in interfaceComponentFactory
- Parameters:
type
- the component type.qualifier
- the options to qualified the component.- Returns:
true
if a provider exist,false
otherwise.
-
containsComponent
public <T> boolean containsComponent(Class<T> type)
Checks if at least one component is registered for the given type.- Specified by:
containsComponent
in interfaceComponentFactory
- Parameters:
type
- the component type.- Returns:
true
if a provider exist,false
otherwise.
-
containsComponent
public <T> boolean containsComponent(Class<T> type, Qualifier<T> qualifier)
Checks if at least one component is registered for the given type and qualifier.- Specified by:
containsComponent
in interfaceComponentFactory
- Parameters:
type
- the component type.qualifier
- the options to qualified the component.- Returns:
true
if a provider exist,false
otherwise.
-
getComponent
public <T> T getComponent(Class<T> type, Conf conf)
Gets an instance, which may be shared or independent, for the specified type.- Specified by:
getComponent
in interfaceComponentFactory
- Type Parameters:
T
- the component-type.- Parameters:
type
- the component class.conf
- the configuration used if the component implementConfigurable
.- Returns:
- the instance of type
ComponentFactory
.
-
getComponent
public <T> T getComponent(Class<T> type, Conf conf, Qualifier<T> qualifier)
Gets an instance, which may be shared or independent, for the specified type.- Specified by:
getComponent
in interfaceComponentFactory
- Type Parameters:
T
- the component-type.- Parameters:
type
- the component class.conf
- the configuration used if the component implementConfigurable
.qualifier
- the options used to qualify the component.- Returns:
- the instance of type
ComponentFactory
.
-
findAllDescriptorsByClass
public <T> Collection<ComponentDescriptor<T>> findAllDescriptorsByClass(Class<T> type)
Finds allComponentDescriptor
registered for the specified type.- Specified by:
findAllDescriptorsByClass
in interfaceComponentDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
type
- the component class.- Returns:
- the collection of
ComponentDescriptor
.
-
findAllDescriptorsByClass
public <T> Collection<ComponentDescriptor<T>> findAllDescriptorsByClass(Class<T> type, Qualifier<T> qualifier)
Finds allComponentDescriptor
registered for the specified type.- Specified by:
findAllDescriptorsByClass
in interfaceComponentDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
type
- the component class.- Returns:
- the collection of
ComponentDescriptor
.
-
getComponentProvider
public <T> GettableComponent<T> getComponentProvider(Class<T> type, Qualifier<T> qualifier)
Gets an instance, which may be shared or independent, for the specified type.- Specified by:
getComponentProvider
in interfaceComponentFactory
- Type Parameters:
T
- the component-type.- Parameters:
type
- the component class.qualifier
- the options used to qualified the component.- Returns:
- the instance of type
ComponentFactory
.
-
getComponent
public <T> T getComponent(String alias, Conf conf)
Gets an instance, which may be shared or independent, for the specified type. If the object, returned from that method, implements theConfigurable
interface, then the factory will invoke the methodConfigurable.configure(Conf)
with the givenConf
. For a shared object, the method will be invoked only the first time it is returned.- Specified by:
getComponent
in interfaceComponentFactory
- Type Parameters:
T
- the component-type.- Parameters:
alias
- the fully qualified class name or an alias of the component.conf
- the configuration used if the component implementConfigurable
.- Returns:
- the instance of type
ComponentFactory
.
-
getComponent
public <T> T getComponent(String alias, Conf conf, Qualifier<T> qualifier)
Gets an instance, which may be shared or independent, for the specified type. If the object, returned from that method, implements theConfigurable
interface, then the factory will invoke the methodConfigurable.configure(Conf)
with the givenConf
. For a shared object, the method will be invoked only the first time it is returned.- Specified by:
getComponent
in interfaceComponentFactory
- Type Parameters:
T
- the component-type.- Parameters:
alias
- the fully qualified class name or an alias of the component.conf
- the configuration used if the component implementConfigurable
.qualifier
- the options used to qualify the component.- Returns:
- the instance of type
ComponentFactory
.
-
getAllComponents
public <T> Collection<T> getAllComponents(String alias, Conf conf)
Gets all instances, which may be shared or independent, for the specified type. If one of the objects, returned from that method, implements theConfigurable
interface, then the factory will invoke the methodConfigurable.configure(Conf)
with the givenConf
. For a shared object, the method will be invoked only the first time it is returned.- Specified by:
getAllComponents
in interfaceComponentFactory
- Type Parameters:
T
- the component-type.- Parameters:
alias
- the fully qualified class name or an alias of the component.conf
- the configuration used if the component implementConfigurable
.- Returns:
- all instances of type
ComponentFactory
.
-
getAllComponents
public <T> Collection<T> getAllComponents(Class<T> type, Conf conf, Qualifier<T> qualifier)
Gets all instances, which may be shared or independent, for the specified type. If one of the objects, returned from that method, implements theConfigurable
interface, then the factory will invoke the methodConfigurable.configure(Conf)
with the givenConf
. For a shared object, the method will be invoked only the first time it is returned.- Specified by:
getAllComponents
in interfaceComponentFactory
- Type Parameters:
T
- the component-type.- Parameters:
type
- the component class.conf
- the configuration used if the component implementConfigurable
.qualifier
- the options used to qualify the component.- Returns:
- all instances of type
ComponentFactory
.
-
getAllComponentProviders
public <T> Collection<GettableComponent<T>> getAllComponentProviders(Class<T> type, Qualifier<T> qualifier)
Gets all instances, which may be shared or independent, for the specified type.- Specified by:
getAllComponentProviders
in interfaceComponentFactory
- Type Parameters:
T
- the component-type.- Parameters:
type
- the component class.qualifier
- the options used to qualify the component.- Returns:
- all instances of type
ComponentFactory
.
-
init
public void init(Conf conf)
Initialize the component factory for the given configuration.- Specified by:
init
in interfaceComponentFactory
- Parameters:
conf
- the configuration.
-
getAllComponents
public <T> Collection<T> getAllComponents(String alias, Conf conf, Qualifier<T> qualifier)
Gets all instances, which may be shared or independent, for the specified type. If one of the objects, returned from that method, implements theConfigurable
interface, then the factory will invoke the methodConfigurable.configure(Conf)
with the givenConf
. For a shared object, the method will be invoked only the first time it is returned.- Specified by:
getAllComponents
in interfaceComponentFactory
- Type Parameters:
T
- the component-type.- Parameters:
alias
- the fully qualified class name or an alias of the component.conf
- the configuration used if the component implementConfigurable
.qualifier
- the options used to qualify the component.- Returns:
- all instances of type
ComponentFactory
.
-
getAllComponents
public <T> Collection<T> getAllComponents(Class<T> type, Conf conf)
Gets all instances, which may be shared or independent, for the specified type. If one of the objects, returned from that method, implements theConfigurable
interface, then the factory will invoke the methodConfigurable.configure(Conf)
with the givenConf
. For a shared object, the method will be invoked only the first time it is returned.- Specified by:
getAllComponents
in interfaceComponentFactory
- Type Parameters:
T
- the component-type.- Parameters:
type
- the component class.conf
- the configuration used if the component implementConfigurable
.- Returns:
- all instances of type
ComponentFactory
.
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceComponentFactory
-
findAllDescriptorsByAlias
public <T> Collection<ComponentDescriptor<T>> findAllDescriptorsByAlias(String alias)
Finds allComponentDescriptor
registered for the specified alias.- Specified by:
findAllDescriptorsByAlias
in interfaceComponentDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
alias
- the fully qualified class name or an alias of the component.- Returns:
- the collection of
ComponentDescriptor
.
-
findDescriptorByAlias
public <T> Optional<ComponentDescriptor<T>> findDescriptorByAlias(String alias)
Finds aComponentDescriptor
for the specified type.- Specified by:
findDescriptorByAlias
in interfaceComponentDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
alias
- the fully qualified class name or an alias of the component.- Returns:
- the optional
ComponentDescriptor
instance.
-
findDescriptorByAlias
public <T> Optional<ComponentDescriptor<T>> findDescriptorByAlias(String alias, Qualifier<T> qualifier)
Finds aComponentDescriptor
for the specified type and options.- Specified by:
findDescriptorByAlias
in interfaceComponentDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
alias
- the fully qualified class name or an alias of the component.qualifier
- the options used to qualified the component.- Returns:
- the optional
ComponentDescriptor
instance.
-
findAllDescriptorsByAlias
public <T> Collection<ComponentDescriptor<T>> findAllDescriptorsByAlias(String alias, Qualifier<T> qualifier)
Finds allComponentDescriptor
registered for the specified alias.- Specified by:
findAllDescriptorsByAlias
in interfaceComponentDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
alias
- the fully qualified class name or an alias of the component.- Returns:
- the collection of
ComponentDescriptor
.
-
findDescriptorByClass
public <T> Optional<ComponentDescriptor<T>> findDescriptorByClass(Class<T> type)
Finds aComponentDescriptor
for the specified type.- Specified by:
findDescriptorByClass
in interfaceComponentDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
type
- the component class.- Returns:
- the optional
ComponentDescriptor
instance.
-
findDescriptorByClass
public <T> Optional<ComponentDescriptor<T>> findDescriptorByClass(Class<T> type, Qualifier<T> qualifier)
Finds aComponentDescriptor
for the specified type and options.- Specified by:
findDescriptorByClass
in interfaceComponentDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
type
- the fully qualified class name or an alias of the component.qualifier
- the options used to qualified the component.- Returns:
- the optional
ComponentDescriptor
instance.
-
registerComponent
public <T> void registerComponent(String componentName, Class<T> componentClass, Supplier<T> supplier, ComponentDescriptorModifier... modifiers)
Registers the component supplier for the specified type and name.- Specified by:
registerComponent
in interfaceComponentRegistry
- Type Parameters:
T
- the component-type.- Parameters:
componentName
- the name of the component.componentClass
- the class-type of the component.supplier
- the supplier of the component.modifiers
- the component descriptor modifiers.
-
registerComponent
public <T> void registerComponent(String componentName, Class<T> componentClass, ComponentDescriptorModifier... modifiers)
Registers the component supplier for the specified type and name.- Specified by:
registerComponent
in interfaceComponentRegistry
- Type Parameters:
T
- the component-type.- Parameters:
componentName
- the name of the component.componentClass
- the class-type of the component.
-
registerSingleton
public <T> void registerSingleton(String componentName, Class<T> componentClass, Supplier<T> singleton, ComponentDescriptorModifier... modifiers)
Registers the component supplier for the specified type and name. The given supplier will be used for creating a shared instance of typeComponentRegistry
.- Specified by:
registerSingleton
in interfaceComponentRegistry
- Type Parameters:
T
- the component-type.- Parameters:
componentName
- the name of the component.componentClass
- the class-type of the component.singleton
- the supplier of the component.
-
registerSingleton
public <T> void registerSingleton(String componentName, Class<T> componentClass, ComponentDescriptorModifier... modifiers)
Registers a singleton no-arg constructor component supplier for the specified type.- Specified by:
registerSingleton
in interfaceComponentRegistry
- Type Parameters:
T
- the component-type.- Parameters:
componentName
- the name of the component.componentClass
- the class-type of the component.
-
registerSingleton
public <T> void registerSingleton(T singleton)
Register the specified shared instance.- Specified by:
registerSingleton
in interfaceComponentRegistry
- Type Parameters:
T
- the component-type.- Parameters:
singleton
- the singleton component instance.
-
registerDescriptor
public <T> void registerDescriptor(ComponentDescriptor<T> descriptor)
Registers the specifiedComponentDescriptor
to thisComponentRegistry
.- Specified by:
registerDescriptor
in interfaceComponentDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
descriptor
- theComponentDescriptor
instance to be registered.
-
setComponentAliasesGenerator
public DefaultComponentFactory setComponentAliasesGenerator(ComponentAliasesGenerator aliasesGenerator)
-
findAllDescriptorsByClass
public <T> Collection<ComponentDescriptor<T>> findAllDescriptorsByClass(Class<T> type, ComponentConditionalContext context)
Finds allComponentDescriptor
registered for the specified type.- Specified by:
findAllDescriptorsByClass
in interfaceConditionalDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
type
- the component class.- Returns:
- the collection of
ComponentDescriptor
.
-
findAllDescriptorsByClass
public <T> Collection<ComponentDescriptor<T>> findAllDescriptorsByClass(Class<T> type, ComponentConditionalContext context, Qualifier<T> qualifier)
Finds allComponentDescriptor
registered for the specified type.- Specified by:
findAllDescriptorsByClass
in interfaceConditionalDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
type
- the component class.- Returns:
- the collection of
ComponentDescriptor
.
-
findAllDescriptorsByAlias
public <T> Collection<ComponentDescriptor<T>> findAllDescriptorsByAlias(String alias, ComponentConditionalContext context)
Finds allComponentDescriptor
registered for the specified alias.- Specified by:
findAllDescriptorsByAlias
in interfaceConditionalDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
alias
- the fully qualified class name or an alias of the component.- Returns:
- the collection of
ComponentDescriptor
.
-
findAllDescriptorsByAlias
public <T> Collection<ComponentDescriptor<T>> findAllDescriptorsByAlias(String alias, ComponentConditionalContext context, Qualifier<T> qualifier)
Finds allComponentDescriptor
registered for the specified alias.- Specified by:
findAllDescriptorsByAlias
in interfaceConditionalDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
alias
- the fully qualified class name or an alias of the component.- Returns:
- the collection of
ComponentDescriptor
.
-
findDescriptorByAlias
public <T> Optional<ComponentDescriptor<T>> findDescriptorByAlias(String alias, ComponentConditionalContext context)
Finds aComponentDescriptor
for the specified type.- Specified by:
findDescriptorByAlias
in interfaceConditionalDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
alias
- the fully qualified class name or an alias of the component.- Returns:
- the optional
ComponentDescriptor
instance.
-
findDescriptorByAlias
public <T> Optional<ComponentDescriptor<T>> findDescriptorByAlias(String alias, ComponentConditionalContext context, Qualifier<T> qualifier)
Finds aComponentDescriptor
for the specified type and options.- Specified by:
findDescriptorByAlias
in interfaceConditionalDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
alias
- the fully qualified class name or an alias of the component.qualifier
- the options used to qualified the component.- Returns:
- the optional
ComponentDescriptor
instance.
-
findDescriptorByClass
public <T> Optional<ComponentDescriptor<T>> findDescriptorByClass(Class<T> type, ComponentConditionalContext context)
Finds aComponentDescriptor
for the specified type.- Specified by:
findDescriptorByClass
in interfaceConditionalDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
type
- the component class.- Returns:
- the optional
ComponentDescriptor
instance.
-
findDescriptorByClass
public <T> Optional<ComponentDescriptor<T>> findDescriptorByClass(Class<T> type, ComponentConditionalContext context, Qualifier<T> qualifier)
Finds aComponentDescriptor
for the specified type and options.- Specified by:
findDescriptorByClass
in interfaceConditionalDescriptorRegistry
- Type Parameters:
T
- the component type.- Parameters:
type
- the fully qualified class name or an alias of the component.qualifier
- the options used to qualified the component.- Returns:
- the optional
ComponentDescriptor
instance.
-
-