Class SharedServiceRegistryKF

  • All Implemented Interfaces:
    SharedServiceRegistry, FeatureStateListener, ServiceLoader, ServiceRegistry

    public class SharedServiceRegistryKF
    extends SimpleServiceRegistry
    implements SharedServiceRegistry, FeatureStateListener
    Implementation of the shared service registry over Kernel and Features.

    This service registry is able to handle the following kind of services:

    • Services owned by the kernel, available to the kernel and the features (provided that the type is part of the API)
    • Services owned by a feature using shared interfaces mechanism, available to other features through Proxy instances
    • Services owned by a feature using an interface owned by the kernel, only available to the kernel (kernel extensions)
    • Services owned by a feature using a type owned by the feature, only available to the feature
    • Constructor Detail

      • SharedServiceRegistryKF

        public SharedServiceRegistryKF()
        Creates a shared service registry.
    • Method Detail

      • register

        public <T> void register​(Class<T> serviceClass,
                                 T implementation)
        Description copied from interface: ServiceRegistry
        Registers a service instance.

        The given instance is returned each time the service is requested by ServiceLoader.getService(Class).

        If the service already has a registered instance, the previous one is replaced.

        Specified by:
        register in interface ServiceRegistry
        Overrides:
        register in class SimpleServiceRegistry
        Type Parameters:
        T - the service type.
        Parameters:
        serviceClass - the implemented service.
        implementation - the service instance.
      • unregister

        public <T> void unregister​(Class<T> serviceClass,
                                   T implementation)
        Description copied from interface: ServiceRegistry
        Unregisters a service instance.

        If the given instance is not the one currently registered for the given service, nothing is done.

        Specified by:
        unregister in interface ServiceRegistry
        Overrides:
        unregister in class SimpleServiceRegistry
        Type Parameters:
        T - the service type.
        Parameters:
        serviceClass - the implemented service.
        implementation - the service instance.
      • getService

        @Nullable
        public <T> T getService​(Class<T> serviceClass)
        Gets the registered implementation for the given service. This implementation depends on who request it. if it is a feature we search the service with the following order:
        • We search it in the shared services provided by the current feature.
        • We search it in the shared services provided by the kernel.
        • We search it in the shared services provided by the trusted features.
        • We search it in the shared services provided by the non trusted features.
        if it is the kernel, we search the service with the following order:
        • We search it in the shared services provided by the kernel.
        • We search it in the shared services provided by the trusted features.
        • We search it in the shared services provided by the non trusted features.
        Specified by:
        getService in interface ServiceLoader
        Overrides:
        getService in class SimpleServiceLoader
        Type Parameters:
        T - the service type.
        Parameters:
        serviceClass - the service to found.
        Returns:
        an instance of the given service or null if no implementation is available.