Class ComponentManagerImpl

    • Field Detail

      • blacklist

        protected volatile Set<String> blacklist
      • started

        protected volatile List<RegistrationInfo> started
        The list of started components (sorted according to the start order). This list is null if the components were not yet started or were stopped
        Since:
        9.2
      • standby

        protected volatile List<RegistrationInfo> standby
        The list of standby components (sorted according to the start order) This list is null if component were not yet started or not yet put in standby When putting components in standby all started components are stopped and the started list is assigned to standby list then the started field is nullified. When resuming standby components the started list is restored from the standby list and the standby field is nullified
        Since:
        9.2
      • stash

        protected volatile ComponentManagerImpl.Stash stash
        A list of registrations that were deployed while the manager was started.
        Since:
        9.2
      • isFlushingStash

        protected volatile boolean isFlushingStash
        Since:
        9.2
      • changed

        protected volatile boolean changed
        Since:
        9.2
    • Constructor Detail

      • ComponentManagerImpl

        public ComponentManagerImpl​(RuntimeService runtime)
    • Method Detail

      • getNeededRegistrations

        public Set<ComponentName> getNeededRegistrations()
        Get the needed component names. The returned set is not a copy
      • getPendingExtensions

        public Set<Extension> getPendingExtensions​(ComponentName name)
        Get the pending extensions. The returned set is not a copy
      • isRegistered

        public boolean isRegistered​(ComponentName name)
        Description copied from interface: ComponentManager
        Checks whether or not a component with the given name was registered.
        Specified by:
        isRegistered in interface ComponentManager
        Parameters:
        name - the object name
        Returns:
        true if an object with the given name was registered, false otherwise
      • size

        public int size()
        Description copied from interface: ComponentManager
        Gets the number of registered objects in this registry.
        Specified by:
        size in interface ComponentManager
        Returns:
        the number of registered objects
      • shutdown

        public void shutdown()
        Description copied from interface: ComponentManager
        Shuts down the component registry.

        This unregisters all objects registered in this registry.

        Specified by:
        shutdown in interface ComponentManager
      • register

        public void register​(RegistrationInfo ri)
        Description copied from interface: ComponentManager
        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.

        Specified by:
        register in interface ComponentManager
        Parameters:
        ri - the registration info
      • unregister

        public void unregister​(RegistrationInfo regInfo)
        Description copied from interface: ComponentManager
        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.

        Specified by:
        unregister in interface ComponentManager
        Parameters:
        regInfo - the registration info
      • unregisterByLocation

        public boolean unregisterByLocation​(String sourceId)
        Description copied from interface: ComponentManager
        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
        Specified by:
        unregisterByLocation in interface ComponentManager
        Parameters:
        sourceId - the location from where the component was deployed
        Returns:
        false if no component was registered from that location, true otherwise
        See Also:
        for more on this
      • hasComponentFromLocation

        public boolean hasComponentFromLocation​(String sourceId)
        Description copied from interface: ComponentManager
        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
        Specified by:
        hasComponentFromLocation in interface ComponentManager
      • addComponentListener

        public void addComponentListener​(ComponentListener listener)
        Description copied from interface: ComponentManager
        Adds a component listener.

        Does nothing if the given listener is already registered.

        Specified by:
        addComponentListener in interface ComponentManager
        Parameters:
        listener - the component listener to add
      • getService

        public <T> T getService​(Class<T> serviceClass)
        Description copied from interface: ComponentManager
        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.

        Specified by:
        getService in interface ComponentManager
        Type Parameters:
        T - the service type
        Parameters:
        serviceClass - the service class
        Returns:
        the service object
      • registerExtension

        public void registerExtension​(Extension extension)
      • unregisterExtension

        public void unregisterExtension​(Extension extension)
      • getServices

        public String[] getServices()
        Description copied from interface: ComponentManager
        Get the list of all registered service names An empty array is returned if no registered services are found.
        Specified by:
        getServices in interface ComponentManager
        Returns:
        an array of registered service.
      • handleError

        protected static void handleError​(String message,
                                          String componentName,
                                          Exception e)
      • activateComponents

        protected List<RegistrationInfo> activateComponents()
        Activate all the resolved components and return the list of activated components in the activation order
        Returns:
        the list of the activated components in the activation order
        Since:
        9.2
      • instantiateComponent

        protected boolean instantiateComponent​(RegistrationInfo ri)
        Instantiates the given RegistrationInfo. This step will instantiate the component.

        Allows registering listeners on ComponentManager at component instantiation, before all components activation.

        Should be called before activateComponent(RegistrationInfo).

        Returns:
        false in case of error during instantiation, true otherwise.
        Since:
        11.3.
      • activateComponent

        protected void activateComponent​(RegistrationInfo ri)
        Activates the given RegistrationInfo. This step will activate the component, register extensions and then register services.
        Since:
        9.3
      • deactivateComponents

        protected void deactivateComponents​(boolean isShutdown)
        Deactivate all active components in the reverse resolve order
        Since:
        9.2
      • deactivateComponent

        protected void deactivateComponent​(RegistrationInfo ri,
                                           boolean isShutdown)
        Deactivates the given RegistrationInfo. This step will unregister the services, unregister the extensions and then deactivate the component.
        Since:
        9.3
      • startComponents

        protected void startComponents​(List<RegistrationInfo> ris,
                                       boolean isResume)
        Start all given components
        Since:
        9.2
      • stopComponents

        protected void stopComponents​(boolean isStandby)
        Stop all started components. Stopping components is done in reverse start order.
        Since:
        9.2
      • start

        public boolean start()
        Description copied from interface: ComponentManager
        Activate and start all resolved components. If components were already started do nothing.
        Specified by:
        start in interface ComponentManager
        Returns:
        false if components were already started, true otherwise
      • stop

        public boolean stop()
        Description copied from interface: ComponentManager
        Stop and deactivate all resolved components. If components were not yet started do nothing
        Specified by:
        stop in interface ComponentManager
        Returns:
        false if components were not yet started, true otherwise
      • standby

        public void standby()
        Description copied from interface: ComponentManager
        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

        Specified by:
        standby in interface ComponentManager
      • resume

        public void resume()
        Description copied from interface: ComponentManager
        Start standby components. If components are not in standby mode the it does nothing.
        Specified by:
        resume in interface ComponentManager
      • isStarted

        public boolean isStarted()
        Description copied from interface: ComponentManager
        Tests whether the components were already started.
        Specified by:
        isStarted in interface ComponentManager
        Returns:
        true if components are started, false
      • isStandby

        public boolean isStandby()
        Description copied from interface: ComponentManager
        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.

        Specified by:
        isStandby in interface ComponentManager
      • isRunning

        public boolean isRunning()
        Description copied from interface: ComponentManager
        Tests whether the components are running. That means they are either started either in standby mode.
        Specified by:
        isRunning in interface ComponentManager
      • hasSnapshot

        public boolean hasSnapshot()
        Description copied from interface: ComponentManager
        Check if a snapshot was done
        Specified by:
        hasSnapshot in interface ComponentManager
        Returns:
        true if a snapshot already exists, false otherwise
      • hasChanged

        public boolean hasChanged()
        Description copied from interface: ComponentManager
        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.
        Specified by:
        hasChanged in interface ComponentManager
      • snapshot

        public void snapshot()
        Description copied from interface: ComponentManager
        Make a snapshot of the component registry. When calling restart
        Specified by:
        snapshot in interface ComponentManager
      • restart

        public void restart​(boolean reset)
        Description copied from interface: ComponentManager
        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.

        Specified by:
        restart in interface ComponentManager
        Parameters:
        reset - whether or not to revert to the last snapshot
      • reset

        public boolean reset()
        Description copied from interface: ComponentManager
        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 ComponentManager.start() to start again the components
        Specified by:
        reset in interface ComponentManager
        Returns:
        true if the components were stopped, false otherwise
      • refresh

        public boolean refresh​(boolean reset)
        Description copied from interface: ComponentManager
        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)
        Specified by:
        refresh in interface ComponentManager
        Parameters:
        reset - whether or not to revert to the last snapshot
        Returns:
        false if stash is empty and nothing was done, true otherwise
      • restoreSnapshot

        protected void restoreSnapshot()
      • shouldStash

        protected boolean shouldStash()
        Tests whether new registrations should be stashed at registration time. If the component manager was started then new components should be stashed otherwise they can be registered.

        TODO: current implementation is stashing after the start completion. Should we also stashing while start is in progress?

      • unstash

        public void unstash()
        Description copied from interface: ComponentManager
        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 ComponentManager.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 ComponentManager.refresh() which is similar to stop(); [restoreSnapshot();] unstash(); start();

        Specified by:
        unstash in interface ComponentManager
      • writeDevMetrics

        protected void writeDevMetrics​(Watch watch,
                                       String type)