this.procedureName = "com.wordpress.salaboy.bpmn2.DefaultFireProcedure";
}
private StatefulKnowledgeSession createDefaultFireProcedureSession(String emergencyId) throws IOException {
System.out.println(">>>> I'm creating the DefaultFireProcedure procedure for emergencyId = "+emergencyId);
GridNode remoteN1 = null;
KnowledgeBuilder kbuilder = null;
KnowledgeBase kbase = null;
if (useLocalKSession) {
KnowledgeBuilderConfiguration kbuilderConf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
kbuilderConf.setOption(AccumulateFunctionOption.get("firefighterDeparmtmentDistanceCalculator", new FirefighterDeparmtmentDistanceCalculator()));
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(kbuilderConf);
KnowledgeBaseConfiguration kbaseConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbaseConf.setOption(EventProcessingOption.STREAM);
kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseConf);
} else {
Map<String, GridServiceDescription> coreServicesMap = new HashMap<String, GridServiceDescription>();
GridServiceDescriptionImpl gsd = new GridServiceDescriptionImpl(WhitePages.class.getName());
Address addr = gsd.addAddress("socket");
addr.setObject(new InetSocketAddress[]{new InetSocketAddress("localhost", 8000)});
coreServicesMap.put(WhitePages.class.getCanonicalName(), gsd);
GridImpl grid = new GridImpl(new ConcurrentHashMap<String, Object>());
GridPeerConfiguration conf = new GridPeerConfiguration();
GridPeerServiceConfiguration coreSeviceConf = new CoreServicesLookupConfiguration(coreServicesMap);
conf.addConfiguration(coreSeviceConf);
GridPeerServiceConfiguration wprConf = new WhitePagesRemoteConfiguration();
conf.addConfiguration(wprConf);
conf.configure(grid);
GridServiceDescription<GridNode> n1Gsd = grid.get(WhitePages.class).lookup("n1");
GridConnection<GridNode> conn = grid.get(ConnectionFactoryService.class).createConnection(n1Gsd);
remoteN1 = conn.connect();
KnowledgeBuilderConfiguration kbuilderConf = remoteN1.get(KnowledgeBuilderFactoryService.class).newKnowledgeBuilderConfiguration();
kbuilderConf.setOption(AccumulateFunctionOption.get("firefighterDeparmtmentDistanceCalculator", new FirefighterDeparmtmentDistanceCalculator()));
kbuilder = remoteN1.get(KnowledgeBuilderFactoryService.class).newKnowledgeBuilder(kbuilderConf);
KnowledgeBaseConfiguration kbaseConf = remoteN1.get(KnowledgeBaseFactoryService.class).newKnowledgeBaseConfiguration();
kbaseConf.setOption(EventProcessingOption.STREAM);
kbase = remoteN1.get(KnowledgeBaseFactoryService.class).newKnowledgeBase(kbaseConf);
}
kbuilder.add(new ByteArrayResource(IOUtils.toByteArray(new ClassPathResource("processes/procedures/MultiVehicleProcedure.bpmn").getInputStream())), ResourceType.BPMN2);
kbuilder.add(new ByteArrayResource(IOUtils.toByteArray(new ClassPathResource("processes/procedures/DefaultFireProcedure.bpmn").getInputStream())), ResourceType.BPMN2);
kbuilder.add(new ByteArrayResource(IOUtils.toByteArray(new ClassPathResource("rules/select_water_refill_destination.drl").getInputStream())), ResourceType.DRL);
kbuilder.add(new ByteArrayResource(IOUtils.toByteArray(new ClassPathResource("rules/defaultFireProcedureEventHandling.drl").getInputStream())), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors != null && errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.out.println(">>>>>>> Error: " + error.getMessage());
}
throw new IllegalStateException("Failed to parse knowledge!");
}
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();
if (useLocalKSession){
KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
}
if (!useLocalKSession){
remoteN1.set("DefaultFireProcedureSession" + this.emergencyId, session);
}
return session;
}