Interface ComponentManager

  • All Known Implementing Classes:
    ComponentManagerImpl

    public interface ComponentManager
    Author:
    Bogdan Stefanescu, Florent Guillaume
    • Method Detail

      • addComponentListener

        void addComponentListener​(ComponentListener listener)
        Adds a component listener.

        Does nothing if the given listener is already registered.

        Parameters:
        listener - the component listener to add
      • removeComponentListener

        void removeComponentListener​(ComponentListener listener)
        Removes a component listener.

        Does nothing if the given listener is not registered.

        Parameters:
        listener - the component listener to remove
      • register

        void register​(RegistrationInfo ri)
        Handles the registration of the given registration info.

        This is called by the main registry when all dependencies of this registration info were solved and the object can be registered.

        If true is returned, the object will be added to the main registry under the name given in RegistrationInfo.

        Parameters:
        ri - the registration info
      • unregister

        void unregister​(RegistrationInfo ri)
        Handles the unregistration of the given registration info.

        This is called by the main registry when the object is unregistered.

        If true is returned, the object will be removed from the main registry.

        Parameters:
        ri - the registration info
      • unregister

        void unregister​(ComponentName name)
        Unregisters a component given its name.
        Parameters:
        name - the component name
      • unregisterByLocation

        @Deprecated
        boolean unregisterByLocation​(String sourceId)
        Deprecated.
        since 9.2
        This method was added only to support unregistering by location which is used by some tests. Removing by location should be managed at a higher level (it is useful only for tests) and this method should be removed
        Parameters:
        sourceId - the location from where the component was deployed
        Returns:
        false if no component was registered from that location, true otherwise
        Since:
        9.2
        See Also:
        for more on this
      • hasComponentFromLocation

        @Deprecated
        boolean hasComponentFromLocation​(String sourceId)
        Deprecated.
        since 9.2
        Given a source location tests if a component was deployed from that location
        This method was added to support undeploying by location needed by tests. Should be removed and a test specific helper implemented to support locations
      • getRegistrationInfo

        RegistrationInfo getRegistrationInfo​(ComponentName name)
        Gets the component if there is one having the given name.
        Parameters:
        name - the component name
        Returns:
        the component if any was registered with that name, null otherwise
      • getComponent

        ComponentInstance getComponent​(ComponentName name)
        Gets object instance managed by the named component.
        Parameters:
        name - the object name
        Returns:
        the object instance if any. may be null
      • isRegistered

        boolean isRegistered​(ComponentName name)
        Checks whether or not a component with the given name was registered.
        Parameters:
        name - the object name
        Returns:
        true if an object with the given name was registered, false otherwise
      • getRegistrations

        Collection<RegistrationInfo> getRegistrations()
        Gets the registered components.
        Returns:
        a read-only collection of components
      • getPendingRegistrations

        Map<ComponentName,​Set<ComponentName>> getPendingRegistrations()
        Gets the pending registrations and their dependencies.
        Returns:
        the pending registrations
      • getMissingRegistrations

        Map<ComponentName,​Set<Extension>> getMissingRegistrations()
        Returns the missing registrations, linked to missing target extension points.
        Since:
        8.10
      • getActivatingRegistrations

        Collection<ComponentName> getActivatingRegistrations()
        Gets the pending extensions by component.
        Returns:
        the pending extensions
      • getResolvedRegistrations

        Collection<ComponentName> getResolvedRegistrations()
        Gets the resolved component names in the order they were resolved
        Since:
        9.2
      • getStartFailureRegistrations

        Collection<ComponentName> getStartFailureRegistrations()
        Gets the components that fail on applicationStarted notification
        Since:
        7.4
      • size

        int size()
        Gets the number of registered objects in this registry.
        Returns:
        the number of registered objects
      • shutdown

        void shutdown()
        Shuts down the component registry.

        This unregisters all objects registered in this registry.

      • getService

        <T> T getService​(Class<T> serviceClass)
        Gets the service of type serviceClass if such a service was declared by a resolved runtime component.

        If the component is not yet activated it will be prior to return the service.

        Type Parameters:
        T - the service type
        Parameters:
        serviceClass - the service class
        Returns:
        the service object
      • getServices

        String[] getServices()
        Get the list of all registered service names An empty array is returned if no registered services are found.
        Returns:
        an array of registered service.
      • getComponentProvidingService

        ComponentInstance getComponentProvidingService​(Class<?> serviceClass)
        Gets the component that provides the given service.
        Parameters:
        serviceClass - the service class
        Returns:
        the component or null if none
      • setBlacklist

        void setBlacklist​(Set<String> blacklist)
      • start

        boolean start()
        Activate and start all resolved components. If components were already started do nothing.
        Returns:
        false if components were already started, true otherwise
        Since:
        9.2
      • stop

        boolean stop()
        Stop and deactivate all resolved components. If components were not yet started do nothing
        Returns:
        false if components were not yet started, true otherwise
        Since:
        9.2
      • stop

        void stop​(int timeout)
        Same as stop() but log a warning if the timeout is reached while stopping components
        Since:
        9.2
      • standby

        void standby()
        Stop all started components but don't deactivate them. After calling this method you can safely contribute new extensions (i.e. modify extension registries).

        If any components were previously started do nothing

        Since:
        9.2
      • standby

        void standby​(int timeout)
        Same as standby() but log a warning if the timeout is reached while stopping components
        Since:
        9.2
      • resume

        void resume()
        Start standby components. If components are not in standby mode the it does nothing.
        Since:
        9.2
      • snapshot

        void snapshot()
        Make a snapshot of the component registry. When calling restart
        Since:
        9.2
      • restart

        void restart​(boolean reset)
        Optionally reset the registry to the last snapshot and restart the components.

        When restarting components all components will be stopped, deactivated and re-instantiated. It means that all references to components before a restart will become invalid after the restart.

        If no snapshot was created then the components will be restarted without changing the registry.

        If the reset argument is true then the registry will be reverted to the last snapshot before starting the components.

        Parameters:
        reset - whether or not to revert to the last snapshot
        Since:
        9.2
      • reset

        boolean reset()
        Reset the registry to the last snapshot if any and stop the components (if they are currently started). After a reset all the components are stopped so we can contribute new components if needed. You must call start() to start again the components
        Returns:
        true if the components were stopped, false otherwise
        Since:
        9.2
      • refresh

        boolean refresh​(boolean reset)
        Refresh the registry using stashed registrations if any. If the reset argument is true then the registry will be reverted to the last snapshot before applying the stash.

        If the stash is empty it does nothing and return true, otherwise it will:

        1. stop the components (if they are started)
        2. revert to the last snapshot (if reset flag is true)
        3. apply the stash (the stash will remain empty after this operation)
        4. start the components (if they was started)
        Parameters:
        reset - whether or not to revert to the last snapshot
        Returns:
        false if stash is empty and nothing was done, true otherwise
        Since:
        9.2
      • refresh

        default boolean refresh()
        Shortcut for refresh(false).
        Since:
        9.2
        See Also:
        refresh(boolean)
      • isStarted

        boolean isStarted()
        Tests whether the components were already started.
        Returns:
        true if components are started, false
        Since:
        9.2
      • isStandby

        boolean isStandby()
        Tests whether the components are in standby mode. That means they were started and then stopped - waiting to be started again.

        When putting components in standby they are stopped but not deactivated. You start back the standby components by calling #resume

        While in standby mode the component manager remains in running state.

        Since:
        9.2
      • isRunning

        boolean isRunning()
        Tests whether the components are running. That means they are either started either in standby mode.
        Since:
        9.2
      • hasChanged

        boolean hasChanged()
        Tests whether components were deployed over the initial snapshot (i.e. the actual registry differs from the snapshot) If no snapshot was done returns false.
        Since:
        9.2
      • hasSnapshot

        boolean hasSnapshot()
        Check if a snapshot was done
        Returns:
        true if a snapshot already exists, false otherwise
        Since:
        9.2
      • isStashEmpty

        boolean isStashEmpty()
        Tests if the stash is empty
        Since:
        9.2
      • unstash

        void unstash()
        Apply the stash if not empty. This is a low level operation and may not be safe to call when the component manager is running isRunning().

        For compatibility reasons (to be able to emulate the old hot deploy mechanism or to speed up tests) this method will force a registry refresh in all 3 component manager states: stopped, standby, started.

        Usually you should apply the stash by calling refresh() which is similar to stop(); [restoreSnapshot();] unstash(); start();

        Since:
        9.2
      • addListener

        void addListener​(ComponentManager.Listener listener)
        Add a listener to be notified on manager actions like start / stop components.
        Since:
        9.2