Class StickyStrategy<T>
- java.lang.Object
-
- org.apache.curator.x.discovery.strategies.StickyStrategy<T>
-
- All Implemented Interfaces:
ProviderStrategy<T>
public class StickyStrategy<T> extends java.lang.Object implements ProviderStrategy<T>
This strategy uses a master strategy to pick the initial instance. Once picked, that instance is always returned. If, however, the currently selected instance is no longer in the list, the master strategy is used to pick a new instance.
-
-
Constructor Summary
Constructors Constructor Description StickyStrategy(ProviderStrategy<T> masterStrategy)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ServiceInstance<T>
getInstance(InstanceProvider<T> instanceProvider)
Given a source of instances, return one of them for a single use.int
getInstanceNumber()
Each time a new instance is picked, an internal counter is incremented.
-
-
-
Constructor Detail
-
StickyStrategy
public StickyStrategy(ProviderStrategy<T> masterStrategy)
- Parameters:
masterStrategy
- the strategy to use for picking the sticky instance
-
-
Method Detail
-
getInstance
public ServiceInstance<T> getInstance(InstanceProvider<T> instanceProvider) throws java.lang.Exception
Description copied from interface:ProviderStrategy
Given a source of instances, return one of them for a single use.- Specified by:
getInstance
in interfaceProviderStrategy<T>
- Parameters:
instanceProvider
- the instance provider- Returns:
- the instance to use
- Throws:
java.lang.Exception
- any errors
-
getInstanceNumber
public int getInstanceNumber()
Each time a new instance is picked, an internal counter is incremented. This way you can track when/if the instance changes. The instance can change when the selected instance is not in the current list of instances returned by the instance provider- Returns:
- instance number
-
-