Class ExponentialReconnectionPolicy

  • All Implemented Interfaces:
    ReconnectionPolicy

    public class ExponentialReconnectionPolicy
    extends Object
    implements ReconnectionPolicy
    A reconnection policy that waits exponentially longer between each reconnection attempt (but keeps a constant delay once a maximum delay is reached).
    • Constructor Detail

      • ExponentialReconnectionPolicy

        public ExponentialReconnectionPolicy​(long baseDelayMs,
                                             long maxDelayMs)
        Creates a reconnection policy waiting exponentially longer for each new attempt.
        Parameters:
        baseDelayMs - the base delay in milliseconds to use for the schedules created by this policy.
        maxDelayMs - the maximum delay to wait between two attempts.
    • Method Detail

      • getBaseDelayMs

        public long getBaseDelayMs()
        The base delay in milliseconds for this policy (e.g. the delay before the first reconnection attempt).
        Returns:
        the base delay in milliseconds for this policy.
      • getMaxDelayMs

        public long getMaxDelayMs()
        The maximum delay in milliseconds between reconnection attempts for this policy.
        Returns:
        the maximum delay in milliseconds between reconnection attempts for this policy.
      • newSchedule

        public ReconnectionPolicy.ReconnectionSchedule newSchedule()
        A new schedule that used an exponentially growing delay between reconnection attempts.

        For this schedule, reconnection attempt i will be tried Math.min(2^(i-1) * getBaseDelayMs(), getMaxDelayMs()) milliseconds after the previous one.

        Specified by:
        newSchedule in interface ReconnectionPolicy
        Returns:
        the newly created schedule.
      • init

        public void init​(Cluster cluster)
        Description copied from interface: ReconnectionPolicy
        Gets invoked at cluster startup.
        Specified by:
        init in interface ReconnectionPolicy
        Parameters:
        cluster - the cluster that this policy is associated with.
      • close

        public void close()
        Description copied from interface: ReconnectionPolicy
        Gets invoked at cluster shutdown.

        This gives the policy the opportunity to perform some cleanup, for instance stop threads that it might have started.

        Specified by:
        close in interface ReconnectionPolicy