Package io.smallrye.stork.api
Class Service
- java.lang.Object
-
- io.smallrye.stork.api.Service
-
public class Service extends Object
Represents a Service.This container gives you access to the service instances and to the selected service instance.
-
-
Constructor Summary
Constructors Constructor Description Service(String serviceName, LoadBalancer loadBalancer, ServiceDiscovery serviceDiscovery, boolean secure, boolean requiresStrictRecording)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description io.smallrye.mutiny.Uni<List<ServiceInstance>>getInstances()Provide a collection of availableServiceInstancesLoadBalancergetLoadBalancer()Get the underlying load balancer instance.ServiceDiscoverygetServiceDiscovery()Get the underlying service discoverybooleanisSecure()io.smallrye.mutiny.Uni<ServiceInstance>selectInstance()Selects a service instance.ServiceInstanceselectInstance(Collection<ServiceInstance> instances)Using the underlying load balancer, select a service instance from the collection of service instances.io.smallrye.mutiny.Uni<ServiceInstance>selectInstanceAndRecordStart(boolean measureTime)Selects a service instance and records a start of an operation using the instanceServiceInstanceselectInstanceAndRecordStart(Collection<ServiceInstance> instances, boolean measureTime)Select a ServiceInstance for this service from a collection and record a start of an operation using the instance.
-
-
-
Constructor Detail
-
Service
public Service(String serviceName, LoadBalancer loadBalancer, ServiceDiscovery serviceDiscovery, boolean secure, boolean requiresStrictRecording)
-
-
Method Detail
-
selectInstance
public io.smallrye.mutiny.Uni<ServiceInstance> selectInstance()
Selects a service instance.The selection looks for the service instances and select the one to use using the load balancer. Note: this method doesn't record a start of an operation using this load balancer and does not synchronize load balancer invocations even if the load balancer is not thread safe
- Returns:
- a Uni with a ServiceInstance, or with
NoServiceInstanceFoundExceptionif the load balancer failed to find a service instance capable of handling a call
-
selectInstance
public ServiceInstance selectInstance(Collection<ServiceInstance> instances)
Using the underlying load balancer, select a service instance from the collection of service instances. Note: this method doesn't record a start of an operation using this load balancer and does not synchronize load balancer invocations even if the load balancer is not thread safe- Parameters:
instances- collection of instances- Returns:
- a ServiceInstance, or with
NoServiceInstanceFoundExceptionif the load balancer failed to find a service instance capable of handling a call - Throws:
NoServiceInstanceFoundException- if all the instances are nto
-
selectInstanceAndRecordStart
public io.smallrye.mutiny.Uni<ServiceInstance> selectInstanceAndRecordStart(boolean measureTime)
Selects a service instance and records a start of an operation using the instanceThe selection looks for the service instances and select the one to use using the load balancer.
- Parameters:
measureTime- whether the operation for which the operation is chosen records time (will callServiceInstance.recordReply())- Returns:
- a Uni with a ServiceInstance, or with
NoServiceInstanceFoundExceptionif the load balancer failed to find a service instance capable of handling a call - See Also:
LoadBalancer.requiresStrictRecording()
-
selectInstanceAndRecordStart
public ServiceInstance selectInstanceAndRecordStart(Collection<ServiceInstance> instances, boolean measureTime)
Select a ServiceInstance for this service from a collection and record a start of an operation using the instance.Access to the underlying LoadBalancer method is serialized.
- Parameters:
instances- instances to choose frommeasureTime- whether the operation for which the operation is chosen records time (will callServiceInstance.recordReply())- Returns:
- the selected instance
- See Also:
selectInstanceAndRecordStart(boolean),LoadBalancer.requiresStrictRecording()
-
getInstances
public io.smallrye.mutiny.Uni<List<ServiceInstance>> getInstances()
Provide a collection of availableServiceInstances- Returns:
- a Uni producing the list of
ServiceInstances.
-
getLoadBalancer
public LoadBalancer getLoadBalancer()
Get the underlying load balancer instance.- Returns:
- load balancer
-
getServiceDiscovery
public ServiceDiscovery getServiceDiscovery()
Get the underlying service discovery- Returns:
- service discovery
-
isSecure
public boolean isSecure()
-
-