Merge branch 'dev' into dev_restore-state-machine
This commit is contained in:
commit
a81d4b2f0a
2 changed files with 47 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ public enum SsnEvent {
|
|||
SDF_13,
|
||||
SDF_08,
|
||||
SDF_21,
|
||||
ALL_SDF_RECEIVED,
|
||||
PAUSE,
|
||||
CONTINUE,
|
||||
REPEAT
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package ru.spcex.clearing.session.state.action;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.statemachine.ExtendedState;
|
||||
import org.springframework.statemachine.StateContext;
|
||||
import org.springframework.statemachine.action.Action;
|
||||
import ru.spcex.clearing.session.state.SsnEvent;
|
||||
|
||||
public class SdfReceivedActionV2<S> implements Action<S, SsnEvent> {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final EnumSet<SsnEvent> sdfs;
|
||||
|
||||
public SdfReceivedActionV2(EnumSet<SsnEvent> sdfs) {
|
||||
this.sdfs = sdfs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(StateContext<S, SsnEvent> ctx) {
|
||||
ExtendedState state = ctx.getExtendedState();
|
||||
|
||||
log.info("event {} flag saving received", ctx.getEvent().name());
|
||||
state.getVariables().put(ctx.getEvent().name(), true);
|
||||
|
||||
Function<SsnEvent, Boolean> was = sdf -> state.get(sdf.name(), Object.class) != null;
|
||||
|
||||
boolean everySdfConditionMet = sdfs
|
||||
.stream()
|
||||
.allMatch(was::apply);
|
||||
if (everySdfConditionMet) {
|
||||
log.info("all of {} conditions were met", sdfs);
|
||||
sdfs.forEach(sdf -> state.getVariables().remove(sdf.name()));
|
||||
ctx.getStateMachine().sendEvent(SsnEvent.ALL_SDF_RECEIVED);
|
||||
} else {
|
||||
log.info("conditions: {}",
|
||||
sdfs
|
||||
.stream()
|
||||
.map(sdf -> "%s: %s".formatted(sdf.name(), was.apply(sdf) ? "received" : "waiting"))
|
||||
.collect(Collectors.joining(";", "[", "]"))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue