Class AbstractComponentRegistry

java.lang.Object
org.infinispan.factories.AbstractComponentRegistry
All Implemented Interfaces:
Lifecycle
Direct Known Subclasses:
ComponentRegistry, GlobalComponentRegistry

@Deprecated(forRemoval=true) public abstract class AbstractComponentRegistry extends Object implements Lifecycle
Deprecated, for removal: This API element is subject to removal in a future version.
Since 9.4, please use BasicComponentRegistry instead.
A registry where components which have been created are stored. Components are stored as singletons, registered under a specific name.

Components can be retrieved from the registry using getComponent(Class).

Components can be registered using registerComponent(Object, Class), which will cause any dependencies to be wired in as well. Components that need to be created as a result of wiring will be done using getOrCreateComponent(Class), which will look up the default factory for the component type (factories annotated with the appropriate DefaultFactoryFor annotation.

Default factories are treated as components too and will need to be wired before being used.

The registry can exist in one of several states, as defined by the ComponentStatus enumeration. In terms of the cache, state changes in the following manner:

  • INSTANTIATED - when first constructed
  • CONSTRUCTED - when created using the DefaultCacheFactory
  • STARTED - when Lifecycle.start() is called
  • STOPPED - when Cache.stop() is called

Cache configuration can only be changed and will only be re-injected if the cache is not in the ComponentStatus.RUNNING state. Thread Safety: instances of GlobalComponentRegistry can be concurrently updated so all the write operations are serialized through class intrinsic lock.

Since:
4.0
Author:
Manik Surtani, Galder ZamarreƱo
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected ComponentStatus
    Deprecated, for removal: This API element is subject to removal in a future version.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected abstract CompletionStage<Void>
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected abstract ClassLoader
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    <T> T
    Deprecated, for removal: This API element is subject to removal in a future version.
    Retrieves a component of a specified type from the registry, or null if it cannot be found.
    <T> T
    getComponent(Class<T> componentClass, String name)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    <T> T
    getComponent(String componentClassName)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    <T> T
    getComponent(String componentClassName, String name)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    <T> T
    getComponent(String componentClassName, String name, boolean nameIsFQCN)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected abstract org.infinispan.util.logging.Log
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected abstract String
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    <T> Optional<T>
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected <T> T
    getOrCreateComponent(Class<T> componentClass)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Retrieves a component if one exists, and if not, attempts to find a factory capable of constructing the component (factories annotated with the DefaultFactoryFor annotation that is capable of creating the component class).
    protected <T> T
    getOrCreateComponent(Class<T> componentClass, String name)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected <T> T
    getOrCreateComponent(Class<T> componentClass, String name, boolean nameIsFQCN)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    Deprecated, for removal: This API element is subject to removal in a future version.
    Retrieves the state of the registry
    abstract TimeService
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected abstract void
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected abstract void
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected abstract void
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected abstract void
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    final void
    registerComponent(Object component, Class<?> type)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Registers a component in the registry under the given type, and injects any dependencies needed.
    final void
    registerComponent(Object component, String name)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    final void
    registerComponent(Object component, String name, boolean nameIsFQCN)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected void
    registerComponentInternal(Object component, String name, boolean nameIsFQCN)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected ClassLoader
    Deprecated.
    Since 9.4, not used
    protected final void
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected void
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Rewires components.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    This starts the components in the registry, connecting to channels, starting service threads, etc.
    final void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Stops the component and sets its status to ComponentStatus.TERMINATED once it is done.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Wires an object instance with dependencies annotated with the Inject annotation, creating more components as needed based on the Configuration passed in if these additional components don't exist in the ComponentRegistry.
    void
    wireDependencies(Object target, boolean startDependencies)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Wires an object instance with dependencies annotated with the Inject annotation, creating more components as needed based on the Configuration passed in if these additional components don't exist in the ComponentRegistry.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • state

      protected volatile ComponentStatus state
      Deprecated, for removal: This API element is subject to removal in a future version.
  • Method Details

    • getStatus

      public ComponentStatus getStatus()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Retrieves the state of the registry
      Returns:
      state of the registry
    • getClassLoader

      protected abstract ClassLoader getClassLoader()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getLog

      protected abstract org.infinispan.util.logging.Log getLog()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • wireDependencies

      public void wireDependencies(Object target) throws CacheConfigurationException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Wires an object instance with dependencies annotated with the Inject annotation, creating more components as needed based on the Configuration passed in if these additional components don't exist in the ComponentRegistry. Strictly for components that don't otherwise live in the registry and have a lifecycle, such as Commands.
      Parameters:
      target - object to wire
      Throws:
      CacheConfigurationException - if there is a problem wiring the instance
    • wireDependencies

      public void wireDependencies(Object target, boolean startDependencies) throws CacheConfigurationException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Wires an object instance with dependencies annotated with the Inject annotation, creating more components as needed based on the Configuration passed in if these additional components don't exist in the ComponentRegistry. Strictly for components that don't otherwise live in the registry and have a lifecycle, such as Commands.
      Parameters:
      target - object to wire
      startDependencies - whether to start injected components (if not already started)
      Throws:
      CacheConfigurationException - if there is a problem wiring the instance
    • registerComponent

      public final void registerComponent(Object component, Class<?> type)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Registers a component in the registry under the given type, and injects any dependencies needed. Note: Until 9.4, if a component of this type already existed, it was overwritten.
      Parameters:
      component - component to register
      type - type of component
      Throws:
      CacheConfigurationException - If a component is already registered with that name, or if a dependency cannot be resolved
    • registerComponent

      public final void registerComponent(Object component, String name)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • registerComponent

      public final void registerComponent(Object component, String name, boolean nameIsFQCN)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • registerNonVolatileComponent

      protected final void registerNonVolatileComponent(Object component, String name)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • registerComponentInternal

      protected void registerComponentInternal(Object component, String name, boolean nameIsFQCN)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getOrCreateComponent

      protected <T> T getOrCreateComponent(Class<T> componentClass)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Retrieves a component if one exists, and if not, attempts to find a factory capable of constructing the component (factories annotated with the DefaultFactoryFor annotation that is capable of creating the component class).

      If an instance needs to be constructed, dependencies are then automatically wired into the instance, based on methods on the component type annotated with Inject.

      Summing it up, component retrieval happens in the following order:
      1. Look for a component that has already been created and registered. 2. Look for an appropriate component that exists in the Configuration that may be injected from an external system. 3. Look for a class definition passed in to the Configuration - such as an EvictionPolicy implementation 4. Attempt to create it by looking for an appropriate factory (annotated with DefaultFactoryFor)

      Parameters:
      componentClass - type of component to be retrieved. Should not be null.
      Returns:
      a fully wired component instance, or null if one cannot be found or constructed.
      Throws:
      CacheConfigurationException - if there is a problem with constructing or wiring the instance.
    • getOrCreateComponent

      protected <T> T getOrCreateComponent(Class<T> componentClass, String name)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getOrCreateComponent

      protected <T> T getOrCreateComponent(Class<T> componentClass, String name, boolean nameIsFQCN)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getComponent

      public <T> T getComponent(Class<T> type)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Retrieves a component of a specified type from the registry, or null if it cannot be found.
      Parameters:
      type - type to find
      Returns:
      component, or null
    • getComponent

      public <T> T getComponent(String componentClassName)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getComponent

      public <T> T getComponent(String componentClassName, String name)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getComponent

      public <T> T getComponent(Class<T> componentClass, String name)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getComponent

      public <T> T getComponent(String componentClassName, String name, boolean nameIsFQCN)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getOptionalComponent

      public <T> Optional<T> getOptionalComponent(Class<T> type)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • registerDefaultClassLoader

      protected ClassLoader registerDefaultClassLoader(ClassLoader loader)
      Deprecated.
      Since 9.4, not used
    • rewire

      public void rewire()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Rewires components. Used to rewire components in the CR if a cache has been stopped (moved to state TERMINATED), which would (almost) empty the registry of components. Rewiring will re-inject all dependencies so that the cache can be started again.

    • start

      public void start()
      Deprecated, for removal: This API element is subject to removal in a future version.
      This starts the components in the registry, connecting to channels, starting service threads, etc. If the component is not in the ComponentStatus.INITIALIZING state, it will be initialized first.
      Specified by:
      start in interface Lifecycle
    • getName

      protected abstract String getName()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • preStart

      protected abstract void preStart()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • postStart

      protected abstract void postStart()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • delayStart

      protected abstract CompletionStage<Void> delayStart()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • stop

      public final void stop()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Stops the component and sets its status to ComponentStatus.TERMINATED once it is done. If the component is not in the ComponentStatus.RUNNING state, this is a no-op.
      Specified by:
      stop in interface Lifecycle
    • postStop

      protected abstract void postStop()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • preStop

      protected abstract void preStop()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • addShutdownHook

      protected void addShutdownHook()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • removeShutdownHook

      protected void removeShutdownHook()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getTimeService

      public abstract TimeService getTimeService()
      Deprecated, for removal: This API element is subject to removal in a future version.