Interface ServiceRegistry


@Contract @Describe public interface ServiceRegistry
Entry point to services in Helidon.

The service registry has knowledge about all the services within your application.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final TypeName
    Type name of this interface.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> List<T>
    all(TypeName contract)
    Get all service instances matching the contract with the expectation that there may not be a match available.
    <T> List<T>
    all(Lookup lookup)
    Get all service instances matching the lookup with the expectation that there may not be a match available.
    default <T> List<T>
    all(Class<T> contract)
    Get all service instances matching the contract with the expectation that there may not be a match available.
    Get all services for a specific contract.
    default List<ServiceInfo>
    allServices(Class<?> contract)
    Get all services for a specific contract.
    <T> Optional<T>
    first(TypeName contract)
    Get the first service instance matching the contract with the expectation that there may not be a match available.
    <T> Optional<T>
    first(Lookup lookup)
    Get the first service instance matching the contract with the expectation that there may not be a match available.
    default <T> Optional<T>
    first(Class<T> contract)
    Get the first service instance matching the contract with the expectation that there may not be a match available.
    <T> T
    get(TypeName contract)
    Get the first service instance matching the contract with the expectation that there is a match available.
    <T> T
    get(Lookup lookup)
    Get the first service instance matching the lookup with the expectation that there is a match available.
    <T> Optional<T>
    get(ServiceInfo serviceInfo)
    Provide a value for a specific service info instance.
    default <T> T
    get(Class<T> contract)
    Get the first service instance matching the contract with the expectation that there is a match available.
    A lookup method that provides a list of qualified instances, rather than just a service instance.
    A lookup method operating on the service descriptors, rather than service instances.
    Provides registry metrics information.
    <T> Supplier<T>
    supply(TypeName contract)
    Get the first service supplier matching the contract with the expectation that there is a match available.
    <T> Supplier<T>
    supply(Lookup lookup)
    Get the first service supplier matching the lookup with the expectation that there is a match available.
    default <T> Supplier<T>
    supply(Class<T> contract)
    Get the first service supplier matching the contract with the expectation that there is a match available.
    <T> Supplier<List<T>>
    supplyAll(TypeName contract)
    Lookup a supplier of a list of instances of the requested contract, with the expectation that there may not be a match available.
    <T> Supplier<List<T>>
    supplyAll(Lookup lookup)
    Lookup a supplier of all services matching the lookup with the expectation that there may not be a match available.
    default <T> Supplier<List<T>>
    supplyAll(Class<T> contract)
    Lookup a supplier of a list of instances of the requested contract, with the expectation that there may not be a match available.
    Get the first service supplier matching the contract with the expectation that there may not be a match available.
    Find the first service matching the lookup with the expectation that there may not be a match available.
    default <T> Supplier<Optional<T>>
    supplyFirst(Class<T> contract)
    Get the first service supplier matching the contract with the expectation that there may not be a match available.
  • Field Details

    • TYPE

      static final TypeName TYPE
      Type name of this interface.
  • Method Details

    • get

      default <T> T get(Class<T> contract)
      Get the first service instance matching the contract with the expectation that there is a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract to look-up
      Returns:
      the best service instance matching the contract
      Throws:
      ServiceRegistryException - if there is no service that could satisfy the lookup, or the resolution to instance failed
    • get

      <T> T get(TypeName contract)
      Get the first service instance matching the contract with the expectation that there is a match available.
      Type Parameters:
      T - type of the contract (we will "blindly" cast the result to the expected type, make sure you use the right one)
      Parameters:
      contract - contract to look-up
      Returns:
      the best service instance matching the contract
      Throws:
      ServiceRegistryException - if there is no service that could satisfy the lookup, or the resolution to instance failed
    • first

      default <T> Optional<T> first(Class<T> contract)
      Get the first service instance matching the contract with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract to look-up
      Returns:
      the best service instance matching the contract, or an empty Optional if none match
      Throws:
      ServiceRegistryException - if there is no service that could satisfy the lookup, or the resolution to instance failed
    • first

      <T> Optional<T> first(TypeName contract)
      Get the first service instance matching the contract with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract to look-up
      Returns:
      the best service instance matching the contract, or an empty Optional if none match
      Throws:
      ServiceRegistryException - if there is no service that could satisfy the lookup, or the resolution to instance failed
    • all

      default <T> List<T> all(Class<T> contract)
      Get all service instances matching the contract with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract to look-up
      Returns:
      list of services matching the criteria, may be empty if none matched, or no instances were provided
    • all

      <T> List<T> all(TypeName contract)
      Get all service instances matching the contract with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract to look-up
      Returns:
      list of services matching the criteria, may be empty if none matched, or no instances were provided
    • supply

      default <T> Supplier<T> supply(Class<T> contract)
      Get the first service supplier matching the contract with the expectation that there is a match available. The provided Supplier.get() may throw an ServiceRegistryException in case the matching service cannot provide a value (either because of scope mismatch, or because an instance was not provided by the service provider.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract to find
      Returns:
      the best service supplier matching the lookup
      Throws:
      ServiceRegistryException - if there is no service that could satisfy the lookup
    • supply

      <T> Supplier<T> supply(TypeName contract)
      Get the first service supplier matching the contract with the expectation that there is a match available. The provided Supplier.get() may throw an ServiceRegistryException in case the matching service cannot provide a value (either because of scope mismatch, or because an instance was not provided by the service provider.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract to find
      Returns:
      the best service supplier matching the lookup
      Throws:
      ServiceRegistryException - if there is no service that could satisfy the lookup
    • supplyFirst

      default <T> Supplier<Optional<T>> supplyFirst(Class<T> contract)
      Get the first service supplier matching the contract with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract we look for
      Returns:
      supplier of an optional instance
    • supplyFirst

      <T> Supplier<Optional<T>> supplyFirst(TypeName contract)
      Get the first service supplier matching the contract with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract we look for
      Returns:
      supplier of an optional instance
    • supplyAll

      default <T> Supplier<List<T>> supplyAll(Class<T> contract)
      Lookup a supplier of a list of instances of the requested contract, with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract we look for
      Returns:
      a supplier of list of instances
    • supplyAll

      <T> Supplier<List<T>> supplyAll(TypeName contract)
      Lookup a supplier of a list of instances of the requested contract, with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract we look for
      Returns:
      a supplier of list of instances
    • get

      <T> Optional<T> get(ServiceInfo serviceInfo)
      Provide a value for a specific service info instance. This method uses instance equality for service info, so be careful to use the singleton instance from the service descriptor, or instances provided by allServices(Class).
      Type Parameters:
      T - type of the expected instance, we just cast to it, so this may cause runtime issues if assigned to invalid type
      Parameters:
      serviceInfo - service info instance
      Returns:
      value of the service described by the service info provided (always a single value), as there is support for providers that are Supplier of an instance, and that may return Optional, we may not get a value, hence we return Optional as well
    • allServices

      default List<ServiceInfo> allServices(Class<?> contract)
      Get all services for a specific contract. The list may be empty if there are no services available. To get an instance, use get(ServiceInfo).
      Parameters:
      contract - contract we look for
      Returns:
      list of service metadata of services that satisfy the provided contract
    • allServices

      List<ServiceInfo> allServices(TypeName contract)
      Get all services for a specific contract. The list may be empty if there are no services available. To get an instance, use get(ServiceInfo).
      Parameters:
      contract - contract we look for
      Returns:
      list of service metadata of services that satisfy the provided contract
    • get

      <T> T get(Lookup lookup)
      Get the first service instance matching the lookup with the expectation that there is a match available.
      Type Parameters:
      T - type of the service, if you use any other than Object, make sure you have configured appropriate contracts in the lookup, as we cannot infer this
      Parameters:
      lookup - lookup criteria to find matching services
      Returns:
      the best service instance matching the lookup, cast to the expected type; please use a Object as the type if the result may contain an unknown instance
      Throws:
      ServiceRegistryException - if there is no service that could satisfy the lookup, or the resolution to instance failed
    • first

      <T> Optional<T> first(Lookup lookup)
      Get the first service instance matching the contract with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the service, if you use any other than Object, make sure you have configured appropriate contracts in the lookup, as we cannot infer this
      Parameters:
      lookup - lookup criteria to find matching services
      Returns:
      the best service instance matching the lookup, cast to the expected type; please use a Object as the type if the result may contain an unknown instance
    • all

      <T> List<T> all(Lookup lookup)
      Get all service instances matching the lookup with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the service, if you use any other than Object, make sure you have configured appropriate contracts in the lookup, as we cannot infer this
      Parameters:
      lookup - lookup criteria to find matching services
      Returns:
      list of services matching the criteria, may be empty if none matched, or no instances were provided
    • supply

      <T> Supplier<T> supply(Lookup lookup)
      Get the first service supplier matching the lookup with the expectation that there is a match available. The provided Supplier.get() may throw an ServiceRegistryException in case the matching service cannot provide a value (either because of scope mismatch, or because there is no available instance, and we use a runtime resolution through Service.ServicesFactory, Service.InjectionPointFactory, or similar).
      Type Parameters:
      T - type of the service, if you use any other than Object, make sure you have configured appropriate contracts in the lookup, as we cannot infer this
      Parameters:
      lookup - lookup criteria to find matching services
      Returns:
      the best service supplier matching the lookup, cast to the expected type; please use a Object as the type if the result may contain an unknown instance
      Throws:
      ServiceRegistryException - if there is no service that could satisfy the lookup
    • supplyFirst

      <T> Supplier<Optional<T>> supplyFirst(Lookup lookup)
      Find the first service matching the lookup with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the service, if you use any other than Object, make sure you have configured appropriate contracts in the lookup, as we cannot infer this
      Parameters:
      lookup - lookup criteria to find matching services
      Returns:
      the best service matching the lookup, cast to the expected type; please use a Object as the type if the result may contain an unknown instance
    • supplyAll

      <T> Supplier<List<T>> supplyAll(Lookup lookup)
      Lookup a supplier of all services matching the lookup with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the service, if you use any other than Object, make sure you have configured appropriate contracts in the lookup, as we cannot infer this
      Parameters:
      lookup - lookup criteria to find matching services
      Returns:
      supplier of list of services ordered, may be empty if there is no match
    • lookupServices

      List<ServiceInfo> lookupServices(Lookup lookup)
      A lookup method operating on the service descriptors, rather than service instances. This is useful for tools that need to analyze the structure of the registry, for testing etc.

      The registry is optimized for look-ups based on service type and service contracts, all other lookups trigger a full registry scan.

      Parameters:
      lookup - lookup criteria to find matching services
      Returns:
      a list of service descriptors that match the lookup criteria
    • lookupInstances

      <T> List<ServiceInstance<T>> lookupInstances(Lookup lookup)
      A lookup method that provides a list of qualified instances, rather than just a service instance. This is to align with the possible injection points in services.

      The registry is optimized for look-ups based on service type and service contracts, all other lookups trigger a full registry scan.

      Type Parameters:
      T - type of the expected result, use Object for results with more than one contract
      Parameters:
      lookup - lookup criteria to find matching services
      Returns:
      a list of qualified service instances that match the lookup criteria
    • metrics

      RegistryMetrics metrics()
      Provides registry metrics information.
      Returns:
      registry metrics