Interface ServiceRegistry

    • Method Detail

      • add

        <S extends Service> void add​(Class<S> type,
                                     S service)
        Add a service
        Type Parameters:
        S - the service type to add
        Parameters:
        type - the service type to add
        service - the service implementation
        See Also:
        Service
      • addIfAbsent

        <S extends Service> S addIfAbsent​(Class<S> type,
                                          S service)
        Add a service if no implementation of the given service is registered with the registry yet. Returns null if the given service was added. Otherwise, the previous service implementation is returned.
        Type Parameters:
        S - the service type to add
        Parameters:
        type - the service type to add
        service - the service implementation
        Returns:
        null if no service implementation was previously associated with the given service. Otherwise, the previous service implementation is returned.
      • get

        <S extends Service> S get​(Class<S> type)
        Retrieve a service implementation
        Type Parameters:
        S - the service type
        Parameters:
        type - the service type
        Returns:
        the service implementation, or null if none is registered
      • getOptional

        <S extends ServiceOptional<S> getOptional​(Class<S> type)
        Retrieve a service implementation wrapped in Optional.
        Type Parameters:
        S - the service type
        Parameters:
        type - the service type
        Returns:
        the service implementation wrapped within Optional
      • getRequired

        <S extends Service> S getRequired​(Class<S> type)
        Retrieve a required service implementation. Throws an exception if the service is not available
        Type Parameters:
        S - the service type
        Parameters:
        type - the service type
        Returns:
        the service implementation
        Throws:
        IllegalStateException - if the service is not available
      • contains

        <S extends Service> boolean contains​(Class<S> type)
        Check if a service is registered
        Type Parameters:
        S - the service type
        Parameters:
        type - the service type
        Returns:
        true if a service is registered, otherwise false
      • cleanup

        void cleanup()
        Clear up the services registered, by calling Service.cleanup() on each registered service