Class DefaultComponentRegistry
- java.lang.Object
-
- io.streamthoughts.azkarra.runtime.components.DefaultComponentRegistry
-
- All Implemented Interfaces:
ComponentRegistry
,Closeable
,AutoCloseable
public class DefaultComponentRegistry extends Object implements ComponentRegistry
The defaultComponentRegistry
implementation.
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Logger
LOG
-
Constructor Summary
Constructors Constructor Description DefaultComponentRegistry()
Creates a newDefaultComponentRegistry
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
<T> Collection<ComponentDescriptor<T>>
findAllDescriptorByAlias(String alias)
Finds aComponentDescriptor
for the specified class or alias.<T> Collection<ComponentDescriptor<T>>
findAllDescriptorsByType(Class<T> type)
Finds all registered providers for the specified type.<T> Optional<ComponentDescriptor<T>>
findDescriptorByAlias(String alias)
Finds aComponentDescriptor
for the specified class or alias.<T> Optional<ComponentDescriptor<T>>
findLatestDescriptorByAlias(String alias)
Finds aComponentDescriptor
for the specified class or alias.<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(String alias, Conf conf)
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(String alias, Conf conf)
Gets an instance, which may be shared or independent, for the specified type.<T> T
getLatestComponent(Class<T> type, Conf conf)
Gets an instance, which may be shared or independent, for the specified type.<T> T
getLatestComponent(String classOrAlias, Conf conf)
Gets an instance, which may be shared or independent, for the specified type.<T> T
getVersionedComponent(String alias, String version, Conf conf)
Gets an instance, which may be shared or independent, for the specified type.boolean
isRegistered(String classOrAlias)
Checks whether the specified components class or alias is already registered.<T> void
registerComponent(ComponentDescriptor<T> descriptor)
Registers the specifiedComponentDescriptor
to thisComponentRegistry
.<T> void
registerComponent(ComponentDescriptor<T> descriptor, ComponentFactory<T> factory)
Registers the specifiedComponentDescriptor
to thisComponentRegistry
.DefaultComponentRegistry
setComponentAliasesGenerator(ComponentAliasesGenerator aliasesGenerator)
Sets theComponentAliasesGenerator
instance.
-
-
-
Constructor Detail
-
DefaultComponentRegistry
public DefaultComponentRegistry()
Creates a newDefaultComponentRegistry
instance.
-
-
Method Detail
-
isRegistered
public boolean isRegistered(String classOrAlias)
Checks whether the specified components class or alias is already registered.- Specified by:
isRegistered
in interfaceComponentRegistry
- Parameters:
classOrAlias
- the fully qualified class name or an alias of the component.- Returns:
true
if a provider exist, {code false} otherwise.
-
findDescriptorByAlias
public <T> Optional<ComponentDescriptor<T>> findDescriptorByAlias(String alias)
Finds aComponentDescriptor
for the specified class or alias.- Specified by:
findDescriptorByAlias
in interfaceComponentRegistry
- Type Parameters:
T
- the component type.- Parameters:
alias
- the fully qualified class name or an alias of the component.- Returns:
- the optional
ComponentDescriptor
instance.
-
findLatestDescriptorByAlias
public <T> Optional<ComponentDescriptor<T>> findLatestDescriptorByAlias(String alias)
Finds aComponentDescriptor
for the specified class or alias. If more than one component is registered for the given alias, the latest version is returned.- Specified by:
findLatestDescriptorByAlias
in interfaceComponentRegistry
- Type Parameters:
T
- the component type.- Parameters:
alias
- the fully qualified class name or an alias of the component.- Returns:
- the optional
ComponentDescriptor
instance.
-
findAllDescriptorByAlias
public <T> Collection<ComponentDescriptor<T>> findAllDescriptorByAlias(String alias)
Finds aComponentDescriptor
for the specified class or alias.- Specified by:
findAllDescriptorByAlias
in interfaceComponentRegistry
- Type Parameters:
T
- the component type.- Parameters:
alias
- the fully qualified class name or an alias of the component.- Returns:
- the optional
ComponentDescriptor
instance.
-
findAllDescriptorsByType
public <T> Collection<ComponentDescriptor<T>> findAllDescriptorsByType(Class<T> type)
Finds all registered providers for the specified type.- Specified by:
findAllDescriptorsByType
in interfaceComponentRegistry
- Type Parameters:
T
- the component type.- Parameters:
type
- the component class.- Returns:
- the collection of
ComponentDescriptor
.
-
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 interfaceComponentRegistry
- Type Parameters:
T
- the component-type.- Parameters:
type
- the component class.conf
- the configuration used if the component implementConfigurable
.- Returns:
- the instance of type
ComponentRegistry
.
-
getLatestComponent
public <T> T getLatestComponent(Class<T> type, Conf conf)
Gets an instance, which may be shared or independent, for the specified type. If more than one component is registered for the given type, the latest version is returned.- Specified by:
getLatestComponent
in interfaceComponentRegistry
- Type Parameters:
T
- the component-type.- Parameters:
type
- the component class.conf
- the configuration used if the component implementConfigurable
.- Returns:
- the instance of type
ComponentRegistry
.
-
getLatestComponent
public <T> T getLatestComponent(String classOrAlias, Conf conf)
Gets an instance, which may be shared or independent, for the specified type. If more than one component is registered for the given type, the latest version is returned.- Specified by:
getLatestComponent
in interfaceComponentRegistry
- Type Parameters:
T
- the component-type.- Parameters:
classOrAlias
- the fully qualified class name or an alias of the component.conf
- the configuration used if the component implementConfigurable
.- Returns:
- the instance of type
ComponentRegistry
.
-
getVersionedComponent
public <T> T getVersionedComponent(String alias, String version, Conf conf)
Gets an instance, which may be shared or independent, for the specified type. If more than one component is registered for the given type, the latest version is returned.- Specified by:
getVersionedComponent
in interfaceComponentRegistry
- 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
ComponentRegistry
.
-
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 interfaceComponentRegistry
- Type Parameters:
T
- the component-type.- Parameters:
type
- the component class.conf
- the configuration used if the component implementConfigurable
.- Returns:
- the instance of type
ComponentRegistry
.
-
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 interfaceComponentRegistry
- 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
ComponentRegistry
.
-
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 interfaceComponentRegistry
- 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
ComponentRegistry
.
-
registerComponent
public <T> void registerComponent(ComponentDescriptor<T> descriptor)
Registers the specifiedComponentDescriptor
to thisComponentRegistry
.- Specified by:
registerComponent
in interfaceComponentRegistry
- Type Parameters:
T
- the component type.- Parameters:
descriptor
- theComponentDescriptor
instance to be registered.
-
registerComponent
public <T> void registerComponent(ComponentDescriptor<T> descriptor, ComponentFactory<T> factory)
Registers the specifiedComponentDescriptor
to thisComponentRegistry
.- Specified by:
registerComponent
in interfaceComponentRegistry
- Type Parameters:
T
- the component type.- Parameters:
descriptor
- theComponentDescriptor
instance to be registered.factory
- theComponentFactory
instance.
-
setComponentAliasesGenerator
public DefaultComponentRegistry setComponentAliasesGenerator(ComponentAliasesGenerator aliasesGenerator)
Sets theComponentAliasesGenerator
instance.- Specified by:
setComponentAliasesGenerator
in interfaceComponentRegistry
- Parameters:
aliasesGenerator
- theComponentAliasesGenerator
used for generating provider aliases.
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-