+
+ private void handleStop(StopReason reason) {
+ synchronized (this) {
+ List<Function1<StopReason, Object>> stopFunctions = new ArrayList<>(scheduledWhenStopped);
+ scheduledWhenStopped.clear();
+
+ SCLContext context = SCLContext.getCurrent();
+ Object oldActionContext = context.put("sequenceAction", this);
+ try {
+ stopFunctions.forEach(f -> {
+ try {
+ f.apply(reason);
+ } catch (Exception e) {
+ if (this.exceptions == null)
+ this.exceptions = new ArrayList<>();
+ this.exceptions.add(new RuntimeException("Stop action failure at " + currentTime + ": " + e.getMessage(), e));
+ }
+ });
+ } finally {
+ context.put("sequenceAction", oldActionContext);
+ }
+ }
+ }