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);