Class ReconnectOptions

  • All Implemented Interfaces:
    Cloneable

    public class ReconnectOptions
    extends Object
    implements Cloneable
    Options that control the reconnection behavior of a client Connection.
    • Field Detail

      • DEFAULT_RECONNECT_ENABLED

        public static final boolean DEFAULT_RECONNECT_ENABLED
        See Also:
        Constant Field Values
      • DEFAULT_WARN_AFTER_RECONNECT_ATTEMPTS

        public static final int DEFAULT_WARN_AFTER_RECONNECT_ATTEMPTS
        See Also:
        Constant Field Values
      • DEFAULT_RECONNECT_DELAY

        public static final int DEFAULT_RECONNECT_DELAY
        See Also:
        Constant Field Values
      • DEFAULT_MAX_RECONNECT_DELAY

        public static final int DEFAULT_MAX_RECONNECT_DELAY
        See Also:
        Constant Field Values
      • DEFAULT_USE_RECONNECT_BACKOFF

        public static final boolean DEFAULT_USE_RECONNECT_BACKOFF
        See Also:
        Constant Field Values
      • DEFAULT_RECONNECT_BACKOFF_MULTIPLIER

        public static final double DEFAULT_RECONNECT_BACKOFF_MULTIPLIER
        See Also:
        Constant Field Values
    • Constructor Detail

      • ReconnectOptions

        public ReconnectOptions()
        Create a new ReconnectOptions instance configured with default configuration settings.
      • ReconnectOptions

        public ReconnectOptions​(ReconnectOptions options)
        Creates a ReconnectOptions instance that is a copy of the given instance.
        Parameters:
        options - The ReconnectOptions instance whose configuration should be copied to this one.
    • Method Detail

      • reconnectEnabled

        public boolean reconnectEnabled()
        Returns true if reconnect is currently enabled for the Connection that these options are assigned to.
        Returns:
        the reconnect enabled configuration state for this options instance.
      • reconnectEnabled

        public ReconnectOptions reconnectEnabled​(boolean reconnectEnabled)
        Set to true to enable reconnection support on the associated Connection or false to disable. When enabled a Connection will attempt to reconnect to a remote based on the configuration set in this options instance.
        Parameters:
        reconnectEnabled - Controls if reconnection is enabled or not for the associated Connection.
        Returns:
        this ReconnectOptions instance.
      • addReconnectLocation

        public ReconnectOptions addReconnectLocation​(String host,
                                                     int port)
        Adds an additional reconnection location that can be used when attempting to reconnect the client following a connection failure.
        Parameters:
        host - The host name of the remote host to attempt a reconnection to.
        port - The port on the remote host to use when connecting.
        Returns:
        this ReconnectOptions instance.
      • reconnectLocations

        public List<ReconnectLocation> reconnectLocations()
        Returns:
        an unmodifiable view of the configured reconnect locations.
      • warnAfterReconnectAttempts

        public int warnAfterReconnectAttempts()
        Returns:
        the number of reconnection attempt before the client should log a warning.
      • warnAfterReconnectAttempts

        public ReconnectOptions warnAfterReconnectAttempts​(int warnAfterReconnectAttempts)
        Controls how often the client will log a message indicating that a reconnection is being attempted. The default is to log every 10 connection attempts.
        Parameters:
        warnAfterReconnectAttempts - The number of attempts before logging an update about not yet reconnecting.
        Returns:
        this ReconnectOptions instance.
      • maxInitialConnectionAttempts

        public int maxInitialConnectionAttempts()
        Returns:
        the configured maximum number of initial connection attempts to try before giving up
      • maxInitialConnectionAttempts

        public ReconnectOptions maxInitialConnectionAttempts​(int maxInitialConnectionAttempts)
        For a client that has never connected to a remote peer before this option controls how many attempts are made to connect before reporting the connection as failed. The default behavior is to use the value of maxReconnectAttempts.
        Parameters:
        maxInitialConnectionAttempts - the maximum number of initial connection attempts to try before giving up.
        Returns:
        this ReconnectOptions instance.
      • maxReconnectAttempts

        public int maxReconnectAttempts()
        Returns:
        the configured maximum number of reconnection attempts to try before giving up
      • maxReconnectAttempts

        public ReconnectOptions maxReconnectAttempts​(int maxReconnectionAttempts)
        The number of reconnection attempts allowed before reporting the connection as failed to the client. The default is no limit or (-1).
        Parameters:
        maxReconnectionAttempts - the maximum number of reconnection attempts to try before giving up.
        Returns:
        this ReconnectOptions instance.
      • reconnectDelay

        public int reconnectDelay()
        Returns:
        the configured reconnect delay to use after between attempts to connect or reconnect.
      • reconnectDelay

        public ReconnectOptions reconnectDelay​(int reconnectDelay)
        Controls the delay between successive reconnection attempts, defaults to 10 milliseconds. If the back off option is not enabled this value remains constant.
        Parameters:
        reconnectDelay - The reconnect delay to apply to successive attempts to reconnect.
        Returns:
        this ReconnectOptions instance.
      • maxReconnectDelay

        public int maxReconnectDelay()
        Returns:
        the configured maximum reconnect attempt delay allowed when using delay back off scheduling.
      • maxReconnectDelay

        public ReconnectOptions maxReconnectDelay​(int maxReconnectDelay)
        The maximum time that the client will wait before attempting a reconnect. This value is only used when the back off feature is enabled to ensure that the delay does not grow too large. Defaults to 30 seconds as the max time between successive connection attempts.
        Parameters:
        maxReconnectDelay - The maximum interval allowed when connection attempt back off is in effect.
        Returns:
        this ReconnectOptions instance.
      • useReconnectBackOff

        public boolean useReconnectBackOff()
        Returns:
        if the reconnection attempts will be delayed using a back off multiplier.
      • useReconnectBackOff

        public ReconnectOptions useReconnectBackOff​(boolean useReconnectBackOff)
        Controls whether the time between reconnection attempts should grow based on a configured multiplier. This option defaults to true.
        Parameters:
        useReconnectBackOff - should connection attempts use a back off of the configured delay.
        Returns:
        this ReconnectOptions instance.
      • reconnectBackOffMultiplier

        public double reconnectBackOffMultiplier()
        Returns:
        the multiplier used when the reconnection back off feature is enabled.
      • reconnectBackOffMultiplier

        public ReconnectOptions reconnectBackOffMultiplier​(double reconnectBackOffMultiplier)
        The multiplier used to grow the reconnection delay value, defaults to 2.0d.
        Parameters:
        reconnectBackOffMultiplier - the delay multiplier used when building delay between reconnection attempts.
        Returns:
        this ReconnectOptions instance.