Class DefaultComponentFactory
- java.lang.Object
-
- io.streamthoughts.azkarra.runtime.components.DefaultComponentFactory
-
- All Implemented Interfaces:
ComponentDescriptorRegistry
,ComponentFactory
,ComponentRegistry
,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 whether a components is already registered for the specified class.<T> boolean
containsComponent(Class<T> type, Qualifier<T> qualifier)
Checks whether a components is already registered for the specified type and scope.boolean
containsComponent(String alias)
Checks whether the specified components class or alias is already registered.<T> boolean
containsComponent(String type, Qualifier<T> qualifier)
Checks whether a components is already registered for the specified type and scope.<T> Collection<ComponentDescriptor<T>>
findAllDescriptorsByAlias(String alias)
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, 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, 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, Qualifier<T> qualifier)
Finds aComponentDescriptor
for the specified type and options.<T> Collection<GettableComponent<T>>
getAllComponents(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> GettableComponent<T>
getComponent(Class<T> type, Qualifier<T> qualifier)
Gets an instance, 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> 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 whether the specified components class or alias is already registered.- 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 whether a components is already registered for the specified type and scope.- 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 whether a components is already registered for the specified class.- 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 whether a components is already registered for the specified type and scope.- 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
.
-
getComponent
public <T> GettableComponent<T> getComponent(Class<T> type, 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.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.- 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.- 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.- 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.- 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
.
-
getAllComponents
public <T> Collection<GettableComponent<T>> getAllComponents(Class<T> type, Qualifier<T> qualifier)
Gets all instances, which may be shared or independent, for the specified type.- Specified by:
getAllComponents
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
.
-
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.- 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.- 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
-
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
.
-
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
.
-
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.
-
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)
-
-