Record Class SagaStep<T>
java.lang.Object
java.lang.Record
cloud.opencode.base.event.saga.SagaStep<T>
- Type Parameters:
T- the context type - 上下文类型- Record Components:
name- the step name - 步骤名称action- the action to execute - 要执行的操作compensation- the compensation action for rollback - 用于回滚的补偿操作timeout- the timeout for this step - 此步骤的超时maxRetries- the maximum number of retries - 最大重试次数Features | 主要功能:
- Individual saga step definition - 单个saga步骤定义
- Action and compensation pairing - 操作和补偿配对
Usage Examples | 使用示例:
SagaStep<OrderContext> step = SagaStep.of( "reserve-inventory", ctx -> inventoryService.reserve(ctx), ctx -> inventoryService.release(ctx) );Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaction()Returns the value of theactionrecord component.Returns the value of thecompensationrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.intReturns the value of themaxRetriesrecord component.name()Returns the value of thenamerecord component.static <T> SagaStep<T> Creates a simple step with only an action.static <T> SagaStep<T> Creates a step with action and compensation.timeout()Returns the value of thetimeoutrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
SagaStep
public SagaStep(String name, Consumer<T> action, Consumer<T> compensation, Duration timeout, int maxRetries) Creates an instance of aSagaSteprecord class.- Parameters:
name- the value for thenamerecord componentaction- the value for theactionrecord componentcompensation- the value for thecompensationrecord componenttimeout- the value for thetimeoutrecord componentmaxRetries- the value for themaxRetriesrecord component
-
-
Method Details
-
of
-
of
Creates a step with action and compensation. 创建带有操作和补偿的步骤。- Type Parameters:
T- the context type - 上下文类型- Parameters:
name- the step name - 步骤名称action- the action - 操作compensation- the compensation - 补偿- Returns:
- the step - 步骤
-
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
name
-
action
-
compensation
Returns the value of thecompensationrecord component.- Returns:
- the value of the
compensationrecord component
-
timeout
-
maxRetries
public int maxRetries()Returns the value of themaxRetriesrecord component.- Returns:
- the value of the
maxRetriesrecord component
-