Package com.io7m.idstore.services.api

# Class IdServiceDirectory

java.lang.Object
com.io7m.idstore.services.api.IdServiceDirectory

All Implemented Interfaces:
  `IdServiceDirectoryType`, `Closeable`, `AutoCloseable`

public final class IdServiceDirectory extends Object implements IdServiceDirectoryType
A service directory.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `IdServiceDirectory()`
  Construct a service directory.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  `<T extends IdServiceType>
  Optional<T>`
  `optionalService(Class<T> clazz)`
  Get an optional reference to the given service.
  `<T extends IdServiceType>
  List<? extends T>`
  `optionalServices(Class<T> clazz)`
  Get references to the given services.
  `<T extends IdServiceType>
  void`
  `register(Class<T> clazz, T service)`
  Register the given service.
  `<T extends IdServiceType>
  T`
  `requireService(Class<T> clazz)`
  Get a required reference to the given service.
  `List<IdServiceType>`
  `services()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### IdServiceDirectory

    public IdServiceDirectory()
    Construct a service directory.

- ## Method Details

  - ### register

    public <T extends IdServiceType> void register(Class<T> clazz, T service)
    Register the given service.
    Type Parameters:
      `T` - The type of service
    Parameters:
      `clazz` - The service interface
      `service` - The service

  - ### optionalService

    public <T extends IdServiceType> Optional<T> optionalService(Class<T> clazz)
    Description copied from interface: `IdServiceDirectoryType`
    Get an optional reference to the given service.
    Specified by:
      `optionalService` in interface `IdServiceDirectoryType`
    Type Parameters:
      `T` - The service type
    Parameters:
      `clazz` - The service interface
    Returns:
      A service reference, if a service exists

  - ### requireService

    public <T extends IdServiceType> T requireService(Class<T> clazz) throws IdServiceException
    Description copied from interface: `IdServiceDirectoryType`
    Get a required reference to the given service.
    Specified by:
      `requireService` in interface `IdServiceDirectoryType`
    Type Parameters:
      `T` - The service type
    Parameters:
      `clazz` - The service interface
    Returns:
      A service reference
    Throws:
      `IdServiceException` - If no service exists

  - ### optionalServices

    public <T extends IdServiceType> List<? extends T> optionalServices(Class<T> clazz) throws IdServiceException
    Description copied from interface: `IdServiceDirectoryType`
    Get references to the given services.
    Specified by:
      `optionalServices` in interface `IdServiceDirectoryType`
    Type Parameters:
      `T` - The service type
    Parameters:
      `clazz` - The service interface
    Returns:
      A service list, if services exist
    Throws:
      `IdServiceException` - If no required

  - ### services

    public List<IdServiceType> services()
    Specified by:
      `services` in interface `IdServiceDirectoryType`
    Returns:
      A read-only list of all the services present

  - ### close

    public void close() throws IOException
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Throws:
      `IOException`