Package io.smallrye.stork.api
Class Service
java.lang.Object
io.smallrye.stork.api.Service
Represents a Service.
This container gives you access to the service instances and to the selected service instance.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionService(String serviceName, String serviceSelectionType, String serviceDiscoveryType, ObservationCollector collector, LoadBalancer loadBalancer, ServiceDiscovery serviceDiscovery, ServiceRegistrar<?> serviceRegistrar, boolean requiresStrictRecording) Creates a new Service. -
Method Summary
Modifier and TypeMethodDescriptionio.smallrye.mutiny.Uni<List<ServiceInstance>>Provide a collection of availableServiceInstancesGet the underlying load balancer instance.Get the underlying service discoveryGet the underlying service registrario.smallrye.mutiny.Uni<ServiceInstance>Selects a service instance.selectInstance(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 instanceselectInstanceAndRecordStart(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 Details
-
Service
public Service(String serviceName, String serviceSelectionType, String serviceDiscoveryType, ObservationCollector collector, LoadBalancer loadBalancer, ServiceDiscovery serviceDiscovery, ServiceRegistrar<?> serviceRegistrar, boolean requiresStrictRecording) Creates a new Service.- Parameters:
serviceName- the name, must not benull, must not be blankserviceDiscoveryType- the type of the service discovery (for observability purpose)serviceSelectionType- the type of the service selection (for observability purpose)collector- the observation collector, must not benullloadBalancer- the load balancer, can benullserviceDiscovery- the service discovery, must not benullserviceRegistrar- the service registrar, can benullrequiresStrictRecording- whether strict recording must be enabled
-
-
Method Details
-
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
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
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:
-
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:
-
getInstances
Provide a collection of availableServiceInstances- Returns:
- a Uni producing the list of
ServiceInstances.
-
getLoadBalancer
Get the underlying load balancer instance.- Returns:
- load balancer
-
getServiceDiscovery
Get the underlying service discovery- Returns:
- service discovery
-
getServiceRegistrar
Get the underlying service registrar- Returns:
- service registrar
-
getObservations
-
getServiceName
- Returns:
- the service name.
-