Interface ServiceRegistry

All Superinterfaces:
Iterable<Service>
All Known Implementing Classes:
ForwardingServiceRegistry, SimpleServiceRegistry

public interface ServiceRegistry extends Iterable<Service>
A service registry
Author:
Pete Muir
  • Method Details

    • 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:
    • 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.
    • addAll

      void addAll(Collection<Map.Entry<Class<? extends Service>,Service>> services)
      Add services
      Parameters:
      services - services to be added
    • entrySet

      Set<Map.Entry<Class<? extends Service>,Service>> entrySet()
      Returns a set of all service entries
      Returns:
      all service entries as a set
    • 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 Service> Optional<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
    • cleanupAfterBoot

      void cleanupAfterBoot()