Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,24 @@ <V> StateMachine<Data> add(
return this;
}

/** Number of transitions taken so far; pass it to {@link #rollbackTo(int)}. */
int transitionCount() {
return transitionHistory.size();
}

/**
* Undoes the transitions taken after {@code transitionCount} was read, restoring the state the
* machine had at that point. For when the request that caused those transitions is refused before
* its {@link RequestContext} is committed: the events the callbacks added are discarded with the
* context, and the in-memory state must not run ahead of history.
*/
void rollbackTo(int transitionCount) {
while (transitionHistory.size() > transitionCount) {
Transition undone = transitionHistory.remove(transitionHistory.size() - 1);
state = undone.from;
}
}

<R> void action(Action action, RequestContext context, R request, long referenceId) {
Transition transition = new Transition(state, action);
@SuppressWarnings("unchecked")
Expand Down
Loading
Loading