Class RetryingWriter


public class RetryingWriter extends ProxyWriter
A proxy that attempts to continue writing on failure.
  • Constructor Details

    • RetryingWriter

      public RetryingWriter(DataWriter nestedDataWriter)
  • Method Details

    • getMaxRetryCount

      public int getMaxRetryCount()
      Returns the number of retries allowed for any individual write attempt (default 5).
    • setMaxRetryCount

      public RetryingWriter setMaxRetryCount(int maxRetryCount)
      Sets the number of retries allowed for any individual write attempt (default 5).
    • getMaxErrorCount

      public long getMaxErrorCount()
      Returns the number of retries allowed across all write attempts (default max long - 1).
    • setMaxErrorCount

      public RetryingWriter setMaxErrorCount(long maxErrorCount)
      Sets the number of retries allowed across all write attempts (default max long -1).
    • getInitialRetryDelay

      public long getInitialRetryDelay()
      Returns the amount of time to wait (in milliseconds) after the first error, before retrying (default 1 second).
    • setInitialRetryDelay

      public RetryingWriter setInitialRetryDelay(long initialRetryDelay)
      Sets the amount of time to wait (in milliseconds) after the first error, before retrying (default 1 second).
    • getStrategy

      public IRetryStrategy getStrategy()
      Returns the retry strategy (default RetryStrategy.EXPONENTIAL_BACKOFF).
    • setStrategy

      public RetryingWriter setStrategy(IRetryStrategy strategy)
      Sets the retry strategy (default RetryStrategy.EXPONENTIAL_BACKOFF).
    • getExceptionCount

      public long getExceptionCount()
      Returns the total number of exceptions/failures seen by this writer. This value is also the number of retries as long as maxErrorCount hasn't been exceeded.
    • getFirstException

      public Throwable getFirstException()
      Returns the first exception thrown for any individual write attempt. This value will reset on the next write attempt after a successful retry.
    • getLastException

      public Throwable getLastException()
      Returns the last exception thrown for any individual write attempt. This value will reset on the next write attempt after a successful retry.
    • getDiscardWriter

      public DataWriter getDiscardWriter()
      Returns the discard sink for failing records or null if one was not assigned.
    • setDiscardWriter

      public RetryingWriter setDiscardWriter(DataWriter writer)
      Assign a discard sink for failing records.
      Parameters:
      writer - the discard sink
    • getDiscardReasonFieldName

      public String getDiscardReasonFieldName()
      Returns the field in the record to place the description of the exception that was thrown by the failing write or null if one should not be added.
    • setDiscardReasonFieldName

      public RetryingWriter setDiscardReasonFieldName(String discardReasonFieldName)
      Specifies the field in the record to place the description of the exception that was thrown by the failing write or null if one should not be added.
    • open

      public void open() throws DataException
      Description copied from class: DataEndpoint
      Makes this endpoint ready for reading or writing.
      Overrides:
      open in class ProxyWriter
      Throws:
      DataException
    • close

      public void close() throws DataException
      Description copied from class: DataEndpoint
      Indicates that this endpoint has finished reading or writing.
      Overrides:
      close in class ProxyWriter
      Throws:
      DataException
    • writeImpl

      protected void writeImpl(Record record) throws Throwable
      Description copied from class: DataWriter
      Overridden by subclasses to write the specified record to this DataWriter.

      Contract for subclasses (see also docs/authoring/DataWriter.md):

      Overrides:
      writeImpl in class ProxyWriter
      Throws:
      Throwable
    • onFailure

      protected void onFailure(Record record, Throwable exception)
      Called after each failed write attempt; writes the record to the discard writer, if set, and throws once getMaxErrorCount() is exceeded.
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Endpoint
      Adds this endpoint's current state to a DataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.
      Overrides:
      addExceptionProperties in class ProxyWriter