Interface RetryStrategy

All Known Implementing Classes:
LinearBackoffRetryStrategy

public interface RetryStrategy

重試策略介面

定義重試操作的通用介面,支援不同的退避策略(線性、指數等)。

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    重試回調介面,用於追蹤重試狀態
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    execute(Callable<T> operation, int maxRetries)
    執行帶重試機制的操作
    <T> T
    execute(Callable<T> operation, int maxRetries, RetryStrategy.RetryCallback callback)
    執行帶重試機制的操作(帶回調)
  • Method Details

    • execute

      <T> T execute(Callable<T> operation, int maxRetries) throws Exception
      執行帶重試機制的操作
      Type Parameters:
      T - 返回值類型
      Parameters:
      operation - 要執行的操作
      maxRetries - 最大重試次數(不包含首次嘗試)
      Returns:
      操作結果
      Throws:
      Exception - 如果所有重試都失敗
    • execute

      <T> T execute(Callable<T> operation, int maxRetries, RetryStrategy.RetryCallback callback) throws Exception
      執行帶重試機制的操作(帶回調)
      Type Parameters:
      T - 返回值類型
      Parameters:
      operation - 要執行的操作
      maxRetries - 最大重試次數(不包含首次嘗試)
      callback - 重試回調
      Returns:
      操作結果
      Throws:
      Exception - 如果所有重試都失敗