Class 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 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 interface ProviderStrategy<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