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 执行 IDsagaName- 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 Summary
ConstructorsConstructorDescriptionSagaResult(String sagaId, String sagaName, SagaStatus status, T context, Instant startTime, Instant endTime, String failedStep, Throwable error) Creates an instance of aSagaResultrecord class. -
Method Summary
Modifier and TypeMethodDescriptioncontext()Returns the value of thecontextrecord component.endTime()Returns the value of theendTimerecord component.final booleanIndicates whether some other object is "equal to" this one.error()Returns the value of theerrorrecord component.Returns the value of thefailedSteprecord component.Gets the execution duration.Gets the error message if any.final inthashCode()Returns a hash code value for this object.booleanChecks if the saga failed and was compensated.booleanisFailed()Checks if the saga failed.booleanChecks if the saga completed successfully.sagaId()Returns the value of thesagaIdrecord component.sagaName()Returns the value of thesagaNamerecord component.Returns the value of thestartTimerecord component.status()Returns the value of thestatusrecord component.final StringtoString()Returns a string representation of this record class.
-
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 aSagaResultrecord class.- Parameters:
sagaId- the value for thesagaIdrecord componentsagaName- the value for thesagaNamerecord componentstatus- the value for thestatusrecord componentcontext- the value for thecontextrecord componentstartTime- the value for thestartTimerecord componentendTime- the value for theendTimerecord componentfailedStep- the value for thefailedSteprecord componenterror- the value for theerrorrecord 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
-
getErrorMessage
Gets the error message if any. 获取错误消息(如果有)。- Returns:
- the error message or null - 错误消息或 null
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object). -
sagaId
-
sagaName
-
status
-
context
-
startTime
-
endTime
-
failedStep
Returns the value of thefailedSteprecord component.- Returns:
- the value of the
failedSteprecord component
-
error
-