Class StickyStrategy<T>

java.lang.Object
org.apache.curator.x.discovery.strategies.StickyStrategy<T>
All Implemented Interfaces:
ProviderStrategy<T>

public class StickyStrategy<T> extends 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 Details

    • StickyStrategy

      public StickyStrategy(ProviderStrategy<T> masterStrategy)
      Parameters:
      masterStrategy - the strategy to use for picking the sticky instance
  • Method Details

    • getInstance

      public ServiceInstance<T> getInstance(InstanceProvider<T> instanceProvider) throws Exception
      Description copied from interface: ProviderStrategy
      Given a source of instances, return one of them for a single use.
      Specified by:
      getInstance in interface ProviderStrategy<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