Class StickyLoadBalancer
- java.lang.Object
-
- io.smallrye.stork.loadbalancer.random.StickyLoadBalancer
-
- All Implemented Interfaces:
LoadBalancer,CallStatisticsCollector
public class StickyLoadBalancer extends Object implements LoadBalancer, CallStatisticsCollector
Select a single instance and use it until it fails. On failure, store the time of failure in `failedInstances` map.When new instance selection is needed:
- if there's an instance for which we don't have a failure recorded, use it
- otherwise, pick the instance whose failure was the longest time away and:
- return it if
failureBackOffhas passed since its last failure - throw NoAcceptableServiceInstanceFoundException if it has not
- return it if
-
-
Constructor Summary
Constructors Constructor Description StickyLoadBalancer(Duration failureBackOff)Creates a new Sticky load balancer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidrecordEnd(long serviceInstanceId, Throwable error)ServiceInstanceselectServiceInstance(Collection<ServiceInstance> serviceInstances)Selects the service instance-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.smallrye.stork.spi.CallStatisticsCollector
recordReply, recordStart
-
Methods inherited from interface io.smallrye.stork.api.LoadBalancer
requiresStrictRecording
-
-
-
-
Constructor Detail
-
StickyLoadBalancer
public StickyLoadBalancer(Duration failureBackOff)
Creates a new Sticky load balancer- Parameters:
failureBackOff- the failure backoff
-
-
Method Detail
-
selectServiceInstance
public ServiceInstance selectServiceInstance(Collection<ServiceInstance> serviceInstances)
Selects the service instance- Specified by:
selectServiceInstancein interfaceLoadBalancer- Parameters:
serviceInstances- instances to choose from- Returns:
- the selected instance
-
recordEnd
public void recordEnd(long serviceInstanceId, Throwable error)- Specified by:
recordEndin interfaceCallStatisticsCollector
-
-