Class ExistingInstanceDescriptor<T>

java.lang.Object
io.helidon.service.registry.ExistingInstanceDescriptor<T>
Type Parameters:
T - type of the instance
All Implemented Interfaces:
Weighted, ServiceDescriptor<T>, ServiceInfo, Comparable<Weighted>

public final class ExistingInstanceDescriptor<T> extends Object implements ServiceDescriptor<T>
A special case service descriptor allowing registration of service instances that do not have a code generated service descriptor, such as for testing.

Note that these instances cannot be used for creating code generated binding, as they do not exist as classes.

  • Method Details

    • create

      public static <T> ExistingInstanceDescriptor<T> create(T instance, Collection<Class<? super T>> contracts, double weight)
      Type Parameters:
      T - type of the service
      Parameters:
      instance - service instance to use
      contracts - contracts of the service (the ones we want service registry to use)
      weight - weight of the service
      Returns:
      a new service descriptor for the provided information
    • serviceType

      public TypeName serviceType()
      Description copied from interface: ServiceInfo
      Type of the service this descriptor describes.
      Specified by:
      serviceType in interface ServiceInfo
      Returns:
      service type
    • descriptorType

      public TypeName descriptorType()
      Description copied from interface: ServiceInfo
      Type of the service descriptor (usually generated).
      Specified by:
      descriptorType in interface ServiceInfo
      Returns:
      descriptor type
    • contracts

      public Set<ResolvedType> contracts()
      Description copied from interface: ServiceInfo
      Set of contracts the described service implements or provides through a factory method.
      Specified by:
      contracts in interface ServiceInfo
      Returns:
      set of contracts
    • instantiate

      public Object instantiate(DependencyContext ctx, InterceptionMetadata metadata)
      Description copied from interface: ServiceDescriptor
      Create a new service instance.
      Specified by:
      instantiate in interface ServiceDescriptor<T>
      Parameters:
      ctx - dependency context with all dependencies of this service
      metadata - metadata handler for interception
      Returns:
      a new instance, must be of the type T or a subclass
    • weight

      public double weight()
      Description copied from interface: Weighted
      Weight of this class (maybe because it is defined dynamically, so it cannot be defined by an annotation). If not dynamic, you can use the Weight annotation rather than implementing this interface as long as it is supported by the library using this Weighted.
      Specified by:
      weight in interface Weighted
      Returns:
      the weight of this service, must be a non-negative number
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object