Package com.yahoo.component.provider
Class ComponentRegistry<COMPONENT>
java.lang.Object
com.yahoo.component.provider.ComponentRegistry<COMPONENT>
A generic superclass for component registries. Supports registration and lookup
of components by id. The registry resolves id requests to the newest matching
component version registered.
This registry supports the freeze pattern - changes can be made
to this registry until freeze()
is called. Subsequent change attempts will cause an
exception. Freezing a registry after building makes it possible to avoid locking and memory
synchronization on lookups.
- Author:
- bratseth
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns an unmodifiable snapshot of all components present in this registry.Returns an unmodifiable snapshot of all components present in this registry, by id.protected static Version
findBestMatch
(VersionSpecification versionSpec, Set<Version> versions) Finds the best (highest) matching version among a set.void
freeze()
Freezes this registry to prevent further changes.Returns a component.getComponent
(String componentSpecification) See getComponent(ComponentSpecification)int
Returns the number of components in thisfinal boolean
isFrozen()
returns whether this is currently frozenvoid
register
(ComponentId id, COMPONENT component) Registers a component unless this registry is frozen.static <COMPONENT>
ComponentRegistry<COMPONENT>singleton
(ComponentId id, COMPONENT component) Returns a frozen registry with a single component, for convenienceUnregisters a component unless this registry is frozen.
-
Constructor Details
-
ComponentRegistry
public ComponentRegistry()
-
-
Method Details
-
freeze
public void freeze()Freezes this registry to prevent further changes. Override this to freeze internal data structures and dependent objects. Overrides must call super. Calling freeze on an already frozen registry must have no effect. -
isFrozen
public final boolean isFrozen()returns whether this is currently frozen -
register
Registers a component unless this registry is frozen. This will succeed even if this component name and version is already registered.- Throws:
IllegalStateException
- if this chain is frozen
-
unregister
Unregisters a component unless this registry is frozen. Note that the component is not deconstructed or otherwise modified in any way, this is the responsiblity of the caller.- Parameters:
id
- the id of the component to be unregistered- Returns:
- the component that was unregistered, or null if no such component was already registered
-
getComponent
See getComponent(ComponentSpecification)- Parameters:
componentSpecification
- a component specification string, seeVersion
- Returns:
- the component or null if no component of this name (and version, if specified) is registered here
-
getComponent
-
getComponent
Returns a component. If the id does not specify an (exact) version, the newest (matching) version is returned. For example, if version 3.1 is specified and we have 3.1.0, 3.1.1 and 3.1.3 registered, 3.1.3 is returned.- Parameters:
id
- the id of the component to return. May not include a version, or include an underspecified version, in which case the highest (matching) version which does not contain a qualifier is returned- Returns:
- the search chain or null if no component of this name (and matching version, if specified) is registered
-
findBestMatch
Finds the best (highest) matching version among a set.- Returns:
- the matching version, or null if there are no matches
-
allComponents
Returns an unmodifiable snapshot of all components present in this registry. -
allComponentsById
Returns an unmodifiable snapshot of all components present in this registry, by id. -
getComponentCount
public int getComponentCount()Returns the number of components in this -
singleton
public static <COMPONENT> ComponentRegistry<COMPONENT> singleton(ComponentId id, COMPONENT component) Returns a frozen registry with a single component, for convenience
-