Class PreferPrimaryDestinationConnectionStrategy

java.lang.Object
net.logstash.logback.appender.destination.PreferPrimaryDestinationConnectionStrategy
All Implemented Interfaces:
DestinationConnectionStrategy

public class PreferPrimaryDestinationConnectionStrategy extends Object implements DestinationConnectionStrategy
The first destination is considered the "primary" destination. The remaining destinations are considered "secondary" destinations.

Prefer to connect to the primary destination. If the primary destination is down, try other destinations.

Connections are attempted to each destination in order until a connection succeeds. Logs will be sent to the first destination for which the connection succeeds until the connection breaks or (if the connection is to a secondary destination) the secondaryConnectionTTL elapses.

  • Constructor Details

    • PreferPrimaryDestinationConnectionStrategy

      public PreferPrimaryDestinationConnectionStrategy()
  • Method Details

    • selectNextDestinationIndex

      public int selectNextDestinationIndex(int previousDestinationIndex, int numDestinations)
      Description copied from interface: DestinationConnectionStrategy
      Returns the index of the destination to which to connect next.
      Specified by:
      selectNextDestinationIndex in interface DestinationConnectionStrategy
      Parameters:
      previousDestinationIndex - The previous destination index to which a connection was attempted (either success or failure)
      numDestinations - The total number of destinations available.
      Returns:
      the index of the destination to which to connect next.
    • connectSuccess

      public void connectSuccess(long connectionStartTimeInMillis, int connectedDestinationIndex, int numDestinations)
      Description copied from interface: DestinationConnectionStrategy
      Called when a connection was successful to the given connectedDestinationIndex.
      Specified by:
      connectSuccess in interface DestinationConnectionStrategy
      Parameters:
      connectionStartTimeInMillis - The time in millis at which the connection was initiated (not completed).
      connectedDestinationIndex - The index of the destination which was successfully connected.
      numDestinations - The total number of destinations available.
    • connectFailed

      public void connectFailed(long connectionStartTimeInMillis, int failedDestinationIndex, int numDestinations)
      Description copied from interface: DestinationConnectionStrategy
      Called when a connection fails to the given failedDestinationIndex.
      Specified by:
      connectFailed in interface DestinationConnectionStrategy
      Parameters:
      connectionStartTimeInMillis - The time in millis at which the connection was initiated (not completed).
      failedDestinationIndex - The index of the destination which failed to connect.
      numDestinations - The total number of destinations available.
    • shouldReconnect

      public boolean shouldReconnect(long currentTimeInMillis, int currentDestinationIndex, int numDestinations)
      Description copied from interface: DestinationConnectionStrategy
      Returns whether the connection should be reestablished.
      Specified by:
      shouldReconnect in interface DestinationConnectionStrategy
      Parameters:
      currentTimeInMillis - The time in millis for which to reevaluate whether the connection should be reestablished.
      currentDestinationIndex - The index of the destination which is currently connected
      numDestinations - The total number of destinations available.
      Returns:
      true if the connection should be reestablished (to the destination returned by the next call to DestinationConnectionStrategy.selectNextDestinationIndex(int, int), false otherwise.
    • getSecondaryConnectionTTL

      public Duration getSecondaryConnectionTTL()
    • setSecondaryConnectionTTL

      public void setSecondaryConnectionTTL(Duration secondaryConnectionTTL)
      Time period for connections to secondary destinations to be used before attempting to reconnect to primary destination. When the value is null (the default), the feature is disabled: the appender will stay on the current destination until an error occurs.
      Parameters:
      secondaryConnectionTTL - time to stay connected to a secondary connection before attempting to reconnect to the primary
    • getMinConnectionTimeBeforePrimary

      public Duration getMinConnectionTimeBeforePrimary()
    • setMinConnectionTimeBeforePrimary

      public void setMinConnectionTimeBeforePrimary(Duration minConnectionTimeBeforePrimary)
      The minimum amount of time that a connection must remain open before the primary is retried on the next reopen attempt.

      This is used to prevent a connection storm against the primary if the primary accepts connections and then immediately closes them.

      When null, the primary will always be retried first, regardless of how long the previous connection remained open.

      Parameters:
      minConnectionTimeBeforePrimary - The minimum amount of time that a connection must remain open before the primary is retried on the next reopen attempt.