Class StickyStrategy<T>
java.lang.Object
org.apache.curator.x.discovery.strategies.StickyStrategy<T>
- All Implemented Interfaces:
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
-
Method Summary
Modifier and TypeMethodDescriptiongetInstance
(InstanceProvider<T> instanceProvider) Given a source of instances, return one of them for a single use.int
Each time a new instance is picked, an internal counter is incremented.
-
Constructor Details
-
StickyStrategy
- Parameters:
masterStrategy
- the strategy to use for picking the sticky instance
-
-
Method Details
-
getInstance
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:
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
-