本文整理汇总了Java中org.kie.internal.builder.KnowledgeBuilderFactory.newKnowledgeBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java KnowledgeBuilderFactory.newKnowledgeBuilder方法的具体用法?Java KnowledgeBuilderFactory.newKnowledgeBuilder怎么用?Java KnowledgeBuilderFactory.newKnowledgeBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kie.internal.builder.KnowledgeBuilderFactory
的用法示例。
在下文中一共展示了KnowledgeBuilderFactory.newKnowledgeBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadDrools
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
private void loadDrools() {
try {
logger.info("Initializing Drools rule engine");
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
addDrls(kbuilder);
KieSessionConfiguration config = KieServices.Factory.get().newKieSessionConfiguration();
config.setOption(ClockTypeOption.get("pseudo"));
logger.debug("Compiling rules");
kSession = kbuilder.newKieBase().newKieSession(config, null);
homeioSessionClock = new HomeioSessionClock(kSession.getSessionClock());
initGlobals();
droolsInitialized = true;
logger.debug("Successfully initialized Drools rule engine");
} catch (Exception e) {
logger.error("Exiting because of an exception during the Drools initialization ", e);
new RuntimeException("Exiting because of an exception during the Drools initialization");
}
}
示例2: loadDrools
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
private void loadDrools() {
try {
logger.info("Initializing Drools rule engine");
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
addDrls(kbuilder);
logger.debug("Compiling rules");
kSession = kbuilder.newKieBase().newKieSession();
initGlobals();
droolsInitialized = true;
logger.info("Successfully initialized Drools rule engine");
} catch (Exception e) {
logger.error("Exiting because of an exception during the Drools initialization ", e);
new RuntimeException("Exiting because of an exception during the Drools initialization");
}
}
示例3: addRule
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
/**
* 单一规则上线
*
* @param packageName
* @param ruleName
*/
public void addRule(String packageName, String ruleName) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(packageName + "/" + ruleName + ".drl"), ResourceType.DRL);
if (kbuilder.hasErrors()) {
logger.error("Unable to compile drl. " + packageName + ruleName + ".drl");
return;
} else {
if (kbase.getRule(packageName, ruleName) != null) {
logger.info("update rule: " + packageName + "." + ruleName);
} else {
logger.info("add rule: " + packageName + "." + ruleName);
}
}
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
kieSession = kbase.newStatelessKieSession();
setGlobal();
printRules();
}
示例4: testCallService
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
@Test
public void testCallService() throws Exception {
final Holder holder = new Holder();
serviceDomain.registerService(new QName("CallService"), new InOnlyService(), new BaseHandler(){
public void handleMessage(Exchange exchange) throws HandlerException {
holder.setValue("message handled");
}
});
serviceDomain.registerServiceReference(new QName("CallService"), new InOnlyService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(CALL_SERVICE_BPMN), ResourceType.BPMN2);
KieBase kbase = kbuilder.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
ssth.setProcessRuntime(ksession);
ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
ksession.startProcess("CallService");
ksession.halt();
ksession.dispose();
Assert.assertEquals("message handled", holder.getValue());
}
示例5: runFaultBoundaryProcess
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
private void runFaultBoundaryProcess(final boolean bomb) throws Exception {
serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler(){
public void handleMessage(Exchange exchange) throws HandlerException {
if (bomb) {
throw new HandlerException("BOOM!");
}
}
});
serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(FAULT_BOUNDARY_PROCESS_BPMN), ResourceType.BPMN2);
KieBase kbase = kbuilder.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
ssth.setProcessRuntime(ksession);
ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultBoundaryProcess");
String output = (String)wpi.getVariable("TestOutput");
Assert.assertEquals(bomb ? "Failure" : "Success", output);
ksession.halt();
ksession.dispose();
}
示例6: testCallService
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
@Test
public void testCallService() throws Exception {
final Holder holder = new Holder();
serviceDomain.registerService(new QName("CallService"), new InOnlyService(), new BaseHandler() {
public void handleMessage(Exchange exchange) throws HandlerException {
holder.setValue("message handled");
}
});
serviceDomain.registerServiceReference(new QName("CallService"), new InOnlyService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(CALL_SERVICE_BPMN), ResourceType.BPMN2);
KieBase kbase = kbuilder.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
ssth.setProcessRuntime(ksession);
ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
ksession.startProcess("CallService");
ksession.halt();
ksession.dispose();
Assert.assertEquals("message handled", holder.getValue());
}
示例7: runFaultBoundaryProcess
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
private void runFaultBoundaryProcess(final boolean bomb) throws Exception {
serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler() {
public void handleMessage(Exchange exchange) throws HandlerException {
if (bomb) {
throw new HandlerException("BOOM!");
}
}
});
serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(FAULT_BOUNDARY_PROCESS_BPMN), ResourceType.BPMN2);
KieBase kbase = kbuilder.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
ssth.setProcessRuntime(ksession);
ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultBoundaryProcess");
String output = (String)wpi.getVariable("TestOutput");
Assert.assertEquals(bomb ? "Failure" : "Success", output);
ksession.halt();
ksession.dispose();
}
示例8: addPackage
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
/**
* 规则集上线
*
* @param packageName
*/
public void addPackage(String packageName) {
try {
File path = new File(this.getClass().getClassLoader().getResource(packageName).toURI().getPath());
if (path.isDirectory()) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
File[] files = path.listFiles();
for (File file : files) {
if (file.getName().endsWith(".drl")) {
kbuilder.add(ResourceFactory.newClassPathResource(packageName + "/" + file.getName()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
logger.error("Unable to compile drl. " + packageName + file.getName());
return;
} else {
String ruleName = file.getName().replace(".drl", "");
if (kbase.getRule(packageName, ruleName) != null) {
logger.info("update rule: " + packageName + "." + ruleName);
} else {
logger.info("add rule: " + packageName + "." + ruleName);
}
}
}
}
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
kieSession = kbase.newStatelessKieSession();
setGlobal();
printRules();
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
示例9: runFaultResultProcess
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
private void runFaultResultProcess(final boolean bomb) throws Exception {
serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler(){
public void handleMessage(Exchange exchange) throws HandlerException {
if (bomb) {
throw new HandlerException("BOOM!");
}
}
});
serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(FAULT_RESULT_PROCESS_BPMN), ResourceType.BPMN2);
KieBase kbase = kbuilder.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
ssth.setProcessRuntime(ksession);
ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultResultProcess");
HandlerException he = (HandlerException)wpi.getVariable("faultResult");
if (bomb) {
Assert.assertNotNull(he);
Assert.assertEquals("BOOM!", he.getMessage());
} else {
Assert.assertNull(he);
}
ksession.halt();
ksession.dispose();
}
示例10: runFaultEventProcess
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
private void runFaultEventProcess(final boolean bomb) throws Exception {
serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler(){
public void handleMessage(Exchange exchange) throws HandlerException {
if (bomb) {
throw new HandlerException("BOOM!");
}
}
});
serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(FAULT_EVENT_PROCESS_BPMN), ResourceType.BPMN2);
KieBase kbase = kbuilder.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
ssth.setProcessRuntime(ksession);
ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultEventProcess");
HandlerException he = (HandlerException)wpi.getVariable("faultEvent");
if (bomb) {
Assert.assertNotNull(he);
Assert.assertEquals("BOOM!", he.getMessage());
} else {
Assert.assertNull(he);
}
ksession.halt();
ksession.dispose();
}
示例11: getDistributeSimplifyKnowledgeBase
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
/**
* Returns Drools ( <A href="http://drools.org">http://drools.org</A> ) knowledge base for algebraic simplification.
*
* @return Drools ( <A href="http://drools.org">http://drools.org</A> ) knowledge base for algebraic simplification.
*/
public static KnowledgeBase getDistributeSimplifyKnowledgeBase()
{
if( distributeSimplifyKnowledgeBase == null )
{
OptimizerFactory.setDefaultOptimizer( OptimizerFactory.SAFE_REFLECTIVE );
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
// Load in the reng support as a separate cross-cutting concern.
builder.add( ResourceFactory.newClassPathResource( "reng.drl" ) ,
ResourceType.DRL );
builder.add( ResourceFactory.newClassPathResource( "distributeSimplify.drl" ) ,
ResourceType.DRL );
if( LoggingConfiguration.LOGGING_ON )
{
builder.add( ResourceFactory.newClassPathResource( "logging.drl" ) ,
ResourceType.DRL );
}
if( builder.hasErrors() )
{
throw( new RuntimeException( builder.getErrors().toString() ) );
}
distributeSimplifyKnowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
distributeSimplifyKnowledgeBase.addKnowledgePackages( builder.getKnowledgePackages() );
}
return( distributeSimplifyKnowledgeBase );
}
示例12: getDistributeSimplify2KnowledgeBase
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
/**
* Returns Drools ( <A href="http://drools.org">http://drools.org</A> ) knowledge base for algebraic simplification.
*
* @return Drools ( <A href="http://drools.org">http://drools.org</A> ) knowledge base for algebraic simplification.
*/
public static KnowledgeBase getDistributeSimplify2KnowledgeBase()
{
if( distributeSimplify2KnowledgeBase == null )
{
OptimizerFactory.setDefaultOptimizer( OptimizerFactory.SAFE_REFLECTIVE );
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
// Load in the reng support as a separate cross-cutting concern.
builder.add( ResourceFactory.newClassPathResource( "reng.drl" ) ,
ResourceType.DRL );
builder.add( ResourceFactory.newClassPathResource( "distributeSimplify2.drl" ) ,
ResourceType.DRL );
if( LoggingConfiguration.LOGGING_ON )
{
builder.add( ResourceFactory.newClassPathResource( "logging.drl" ) ,
ResourceType.DRL );
}
if( builder.hasErrors() )
{
throw( new RuntimeException( builder.getErrors().toString() ) );
}
distributeSimplify2KnowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
distributeSimplify2KnowledgeBase.addKnowledgePackages( builder.getKnowledgePackages() );
}
return( distributeSimplify2KnowledgeBase );
}
示例13: runFaultResultProcess
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
private void runFaultResultProcess(final boolean bomb) throws Exception {
serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler() {
public void handleMessage(Exchange exchange) throws HandlerException {
if (bomb) {
throw new HandlerException("BOOM!");
}
}
});
serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(FAULT_RESULT_PROCESS_BPMN), ResourceType.BPMN2);
KieBase kbase = kbuilder.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
ssth.setProcessRuntime(ksession);
ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultResultProcess");
HandlerException he = (HandlerException)wpi.getVariable("faultResult");
if (bomb) {
Assert.assertNotNull(he);
Assert.assertEquals("BOOM!", he.getMessage());
} else {
Assert.assertNull(he);
}
ksession.halt();
ksession.dispose();
}
示例14: runFaultEventProcess
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
private void runFaultEventProcess(final boolean bomb) throws Exception {
serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler() {
public void handleMessage(Exchange exchange) throws HandlerException {
if (bomb) {
throw new HandlerException("BOOM!");
}
}
});
serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(FAULT_EVENT_PROCESS_BPMN), ResourceType.BPMN2);
KieBase kbase = kbuilder.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
ssth.setProcessRuntime(ksession);
ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultEventProcess");
HandlerException he = (HandlerException)wpi.getVariable("faultEvent");
if (bomb) {
Assert.assertNotNull(he);
Assert.assertEquals("BOOM!", he.getMessage());
} else {
Assert.assertNull(he);
}
ksession.halt();
ksession.dispose();
}
示例15: main
import org.kie.internal.builder.KnowledgeBuilderFactory; //导入方法依赖的package包/类
public static void main(String[] args) {
//rule,rule2可以放在数据库中,有个唯一code和他们对于,代码要执行规则的时候,根据code从数据库获取出来就OK了,这样自己开发的规则管理系统那边对数据库里的规则进行维护就行了
String rule = "package com.neo.drools\r\n";
rule += "import com.neo.drools.model.Message;\r\n";
rule += "rule \"rule1\"\r\n";
rule += "\twhen\r\n";
rule += "Message( status == 1, myMessage : msg )";
rule += "\tthen\r\n";
rule += "\t\tSystem.out.println( 1+\":\"+myMessage );\r\n";
rule += "end\r\n";
String rule2 = "package com.neo.drools\r\n";
rule += "import com.neo.drools.model.Message;\r\n";
rule += "rule \"rule2\"\r\n";
rule += "\twhen\r\n";
rule += "Message( status == 2, myMessage : msg )";
rule += "\tthen\r\n";
rule += "\t\tSystem.out.println( 2+\":\"+myMessage );\r\n";
rule += "end\r\n";
StatefulKnowledgeSession kSession = null;
try {
KnowledgeBuilder kb = KnowledgeBuilderFactory.newKnowledgeBuilder();
//装入规则,可以装入多个
kb.add(ResourceFactory.newByteArrayResource(rule.getBytes("utf-8")), ResourceType.DRL);
kb.add(ResourceFactory.newByteArrayResource(rule2.getBytes("utf-8")), ResourceType.DRL);
KnowledgeBuilderErrors errors = kb.getErrors();
for (KnowledgeBuilderError error : errors) {
System.out.println(error);
}
KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
kBase.addKnowledgePackages(kb.getKnowledgePackages());
kSession = kBase.newStatefulKnowledgeSession();
Message message1 = new Message();
message1.setStatus(1);
message1.setMsg("hello world!");
Message message2 = new Message();
message2.setStatus(2);
message2.setMsg("hi world!");
kSession.insert(message1);
kSession.insert(message2);
kSession.fireAllRules();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} finally {
if (kSession != null)
kSession.dispose();
}
}