Record Class SagaResult<T>

java.lang.Object
java.lang.Record
cloud.opencode.base.event.saga.SagaResult<T>
Type Parameters:
T - the context type - 上下文类型
Record Components:
sagaId - the unique saga execution ID - 唯一的 saga 执行 ID
sagaName - the saga name - saga 名称
status - the final status - 最终状态
context - the saga context - saga 上下文
startTime - the execution start time - 执行开始时间
endTime - the execution end time - 执行结束时间
failedStep - the name of the failed step (if any) - 失败步骤的名称(如果有)
error - the error that caused failure (if any) - 导致失败的错误(如果有)

Features | 主要功能:

  • Saga execution result tracking - Saga执行结果跟踪
  • Duration and error information - 时长和错误信息

Usage Examples | 使用示例:

SagaResult<MyContext> result = saga.execute(context);
if (result.isSuccess()) {
    System.out.println("Completed in " + result.getDuration());
}

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)

public record SagaResult<T>(String sagaId, String sagaName, SagaStatus status, T context, Instant startTime, Instant endTime, String failedStep, Throwable error) extends Record
Saga Result - The result of a saga execution Saga 结果 - saga 执行的结果
Since:
JDK 25, opencode-base-event V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • SagaResult

      public SagaResult(String sagaId, String sagaName, SagaStatus status, T context, Instant startTime, Instant endTime, String failedStep, Throwable error)
      Creates an instance of a SagaResult record class.
      Parameters:
      sagaId - the value for the sagaId record component
      sagaName - the value for the sagaName record component
      status - the value for the status record component
      context - the value for the context record component
      startTime - the value for the startTime record component
      endTime - the value for the endTime record component
      failedStep - the value for the failedStep record component
      error - the value for the error record component
  • Method Details

    • isSuccess

      public boolean isSuccess()
      Checks if the saga completed successfully. 检查 saga 是否成功完成。
      Returns:
      true if completed - 如果完成返回 true
    • isCompensated

      public boolean isCompensated()
      Checks if the saga failed and was compensated. 检查 saga 是否失败并已补偿。
      Returns:
      true if compensated - 如果已补偿返回 true
    • isFailed

      public boolean isFailed()
      Checks if the saga failed. 检查 saga 是否失败。
      Returns:
      true if failed - 如果失败返回 true
    • getDuration

      public Duration getDuration()
      Gets the execution duration. 获取执行时长。
      Returns:
      the duration - 时长
    • getErrorMessage

      public String getErrorMessage()
      Gets the error message if any. 获取错误消息(如果有)。
      Returns:
      the error message or null - 错误消息或 null
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • sagaId

      public String sagaId()
      Returns the value of the sagaId record component.
      Returns:
      the value of the sagaId record component
    • sagaName

      public String sagaName()
      Returns the value of the sagaName record component.
      Returns:
      the value of the sagaName record component
    • status

      public SagaStatus status()
      Returns the value of the status record component.
      Returns:
      the value of the status record component
    • context

      public T context()
      Returns the value of the context record component.
      Returns:
      the value of the context record component
    • startTime

      public Instant startTime()
      Returns the value of the startTime record component.
      Returns:
      the value of the startTime record component
    • endTime

      public Instant endTime()
      Returns the value of the endTime record component.
      Returns:
      the value of the endTime record component
    • failedStep

      public String failedStep()
      Returns the value of the failedStep record component.
      Returns:
      the value of the failedStep record component
    • error

      public Throwable error()
      Returns the value of the error record component.
      Returns:
      the value of the error record component