@Override
public KieSession execute(Context context) {
return id != null ? kieContainer.newKieSession( id ) : kieContainer.newKieSession();
}
});
addCommand( new SetVariableCommandFromLastReturn( StatefulKnowledgeSession.class.getName() ) );
return new DefaultStatefulKnowledgeSessionSimFluent( this );
}
};
// @formatter:off
int counter = 0;
int remainingInstances = numberOfAllInstances;
for (SimulationPath path : paths) {
// only paths that can be started are considered
if (!path.isStartable()) {
continue;
}
double probability = path.getProbability();
f.newPath("path" + counter);
int instancesOfPath = 1;
// count how many instances/steps should current path have
if (numberOfAllInstances > 1) {
instancesOfPath = (int) Math.round((numberOfAllInstances * probability));
// ensure that we won't exceed total number of instance due to rounding
if (instancesOfPath > remainingInstances) {
instancesOfPath = remainingInstances;
}
remainingInstances -= instancesOfPath;
for (int i = 0; i < instancesOfPath; i++) {
f.newStep( interval * i )
.newKieSession( releaseId, null)
.end()
.addCommand(new SimulateProcessPathCommand(processId, context, path))
.addCommand( new SetVariableCommandFromLastReturn( StatefulKnowledgeSession.class.getName() ))
.addCommand(new DisposeCommand());
}
} else {
f.newStep(interval)
.newKieSession(releaseId, null)
.end()
.addCommand(new SimulateProcessPathCommand(processId, context, path))
.addCommand( new SetVariableCommandFromLastReturn( StatefulKnowledgeSession.class.getName() ))
.addCommand(new DisposeCommand());
break;
}
counter++;