Class ThreadSafeComponentManager<T>

  • Type Parameters:
    T - The type of handled extensions
    All Implemented Interfaces:
    LogEnabled, Disposable, Initializable, Contextualizable, Serviceable
    Direct Known Subclasses:
    PluginsComponentManager

    public class ThreadSafeComponentManager<T>
    extends AbstractLogEnabled
    implements Contextualizable, Initializable, Disposable, Serviceable
    Special ServiceManager able to handle extensions.
    It does not actually implements the Avalon ServiceManager interface, to be able to use the Java 5 generic parameter.
    This class is also intended to be used "locally" : its lookup(role) method does NOT propagate to the parent manager if the component does not exist.
    To use the real ServiceManager, use the PluginsServiceManager subclass instead.

    It handles the "PluginAware" interface, implemented by extensions.
    It handles the following Avalon interfaces :
    • LogEnabled
    • Contextualizable
    • Serviceable
    • Configurable
    • Parameterizable
    • Initializable
    • Startable
    • Disposable
    All handled components are considered ThreadSafe, ie only one instance is created at initialization time and returned at each lookup()
    • Constructor Detail

      • ThreadSafeComponentManager

        public ThreadSafeComponentManager​(boolean allowCircularDependencies)
        Constructor.
        Parameters:
        allowCircularDependencies - if this manager should allow circular dependencies during initialization
    • Method Detail

      • lookup

        public T lookup​(String role)
                 throws ComponentException
        Return an instance of a component based on a Role. The Role is usually the Interface Fully Qualified Name(FQN).
        Parameters:
        role - The key name of the Component to retrieve.
        Returns:
        the desired component or null if no component exist for the given role
        Throws:
        ComponentException - if an error occurs
      • hasRole

        public boolean hasRole​(String role)
        Tests for existence of a component for a given role.
        Parameters:
        role - a string identifying the key to check.
        Returns:
        true if there is a component for the given role, false if not.
      • hasComponent

        public boolean hasComponent​(T component)
        Tests for existence of a component.
        Parameters:
        component - to component to check
        Returns:
        true if the component exists, false if it does not.
      • dispose

        public void dispose()
        Properly dispose of the Child handlers.
        Specified by:
        dispose in interface Disposable
      • addComponent

        public void addComponent​(String pluginName,
                                 String featureName,
                                 String role,
                                 Class<? extends T> component,
                                 Configuration configuration)
        Add a new component to the manager.
        Parameters:
        pluginName - the plugin containing the component
        featureName - the feature containing the component
        role - the role name for the new component.
        component - the class of this component.
        configuration - the configuration for this component.