Interface ServiceInstance


public interface ServiceInstance
Represents an instance of service.
  • Method Details

    • getId

      long getId()
      Returns:
      the service id. The service ids are unique per Stork instance.
    • getHost

      String getHost()
      Returns:
      the host of the service.
    • getPort

      int getPort()
      Returns:
      the port of the service.
    • getPath

      Optional<String> getPath()
      For service behind an API gateway or a proxy, this method return the path. When set, the final location of the service is composed of $host:$port/$path.
      Returns:
      the path if any.
    • isSecure

      boolean isSecure()
      Returns:
      whether the communication should happen over a secure connection
    • getMetadata

      default Metadata<? extends MetadataKey> getMetadata()
      Returns:
      the metadata of the instance, empty if none.
    • getLabels

      default Map<String,String> getLabels()
      Returns:
      the labels of the instance, empty if none.
    • gatherStatistics

      default boolean gatherStatistics()
      Returns:
      whether the interaction with the service are monitored, allowing statistic-based load-balancing.
    • recordStart

      default void recordStart(boolean measureTime)
      Warning Usually should not be called directly. Most client libraries should use Service.selectInstanceAndRecordStart(Collection, boolean) and Service.selectInstanceAndRecordStart(boolean) to select services. These methods invoke this method automatically
      When gatherStatistics is enabled, reports the start of an operation using this service instance.

      The load balancers that keep track of inflight operations should increase the counter on this method. The load balancer that collect times of operations should only take into account operations that have measureTime set to true

      Parameters:
      measureTime - if true, recordReply() will be called for this operation
    • recordReply

      default void recordReply()
      When gatherStatistics is enabled, reports a reply for an operation using this service instance.

      Should be called if and only if recordStart(true) has been called earlier

    • recordEnd

      default void recordEnd(Throwable failure)
      When gatherStatistics is enabled, reports the end of an operation using this service instance.
      Parameters:
      failure - if the operation failed, the throwable depicting the failure, null otherwise