public WorkingMemorySimulationRepository(boolean fireRulesOnStore, Resource... rules) { this.fireRulesOnStore = fireRulesOnStore; KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); for (Resource path : rules) { kbuilder.add(path, ResourceType.DRL); } if (kbuilder.hasErrors()) { throw new RuntimeException("Error while building knowledge base: " + kbuilder.getErrors()); } this.ksession = kbuilder.newKnowledgeBase().newStatefulKnowledgeSession(); try { // register global for aggregated events ksession.setGlobal("simulation", new ArrayList<AggregatedActivitySimulationEvent>()); ksession.setGlobal("summary", new ArrayList<AggregatedActivitySimulationEvent>()); AggregatedProcessSimulationEvent init = new AggregatedProcessSimulationEvent("", 0, 0, 0); List processOnlyList = new ArrayList<AggregatedSimulationEvent>(); processOnlyList.add(init); ksession.setGlobal("processEventsOnly", processOnlyList); } catch (Exception e) { // catch it as there could be no simulation global declared } }
public WorkingMemorySimulationRepository(boolean fireRulesOnStore, String... rules) { this.fireRulesOnStore = fireRulesOnStore; KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); for (String path : rules) { kbuilder.add(ResourceFactory.newClassPathResource(path), ResourceType.DRL); } if (kbuilder.hasErrors()) { throw new RuntimeException("Error while building knowledge base: " + kbuilder.getErrors()); } this.ksession = kbuilder.newKnowledgeBase().newStatefulKnowledgeSession(); try { // register global for aggregated events ksession.setGlobal("simulation", new ArrayList<AggregatedActivitySimulationEvent>()); } catch (Exception e) { // catch it as there could be no simulation global declared } }
@Test public void testSimulationCommand() { PathFinder finder = PathFinderFactory.getInstance(this.getClass().getResourceAsStream("/BPMN2-ExclusiveSplit.bpmn2")); List<SimulationPath> paths = finder.findPaths(new SimulationFilterPathFormatConverter()); SimulationContext context = SimulationContextFactory.newContext(new HardCodedSimulationDataProvider()); KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder(); builder.add(ResourceFactory.newClassPathResource("BPMN2-ExclusiveSplit.bpmn2"), ResourceType.BPMN2); KnowledgeBase kbase = builder.newKnowledgeBase(); KieSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); config.setOption(ClockTypeOption.get("pseudo") ); for (SimulationPath sp : paths) { StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession(config, EnvironmentFactory.newEnvironment()); ((SessionPseudoClock) session.getSessionClock()).advanceTime(System.currentTimeMillis(), TimeUnit.MILLISECONDS); session.execute(new SimulateProcessPathCommand("com.sample.test", context, sp)); } } }
KnowledgeBase kbase = builder.newKnowledgeBase(); KieSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); config.setOption(ClockTypeOption.get("pseudo") );