Package ej.service

Interface ServiceRegistry

    • Method Detail

      • register

        <T> void register​(Class<T> service,
                          T instance)
        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.

        Type Parameters:
        T - the service type.
        Parameters:
        service - the implemented service.
        instance - the service instance.
        Throws:
        SecurityException - if a security manager exists and does not allow the caller to register the given service instance.
      • unregister

        <T> void unregister​(Class<T> service,
                            T instance)
        Unregisters a service instance.

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

        Type Parameters:
        T - the service type.
        Parameters:
        service - the implemented service.
        instance - the service instance.
        Throws:
        SecurityException - if a security manager exists and does not allow the caller to unregister the given service instance.