Drools Expert - integration
Dynamic Rules Changes⌘
动态规则修改。
addRule⌘
String rule = rules.get(ruleName);
CommonTestMethodBase testBaseMethod = new CommonTestMethodBase();
kbase.addKnowledgePackages(testBaseMethod.loadKnowledgePackagesFromString( rule ));
添加规则。
String rule = rules.get(ruleName);
CommonTestMethodBase testBaseMethod = new CommonTestMethodBase();
kbase.addKnowledgePackages(testBaseMethod.loadKnowledgePackagesFromString( rule ));
removeRule⌘
kbase.removeRule("defaultpkg", firingRule.getName());
删除规则。
kbase.removeRule("defaultpkg", firingRule.getName());
Dynamic Rule Load⌘
// Create an in-memory jar for version 1.0.0
ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-upgrade-java", "1.0.0" );
Resource javaResource = ResourceFactory.newByteArrayResource(javaSrc.getBytes()).setResourceType( ResourceType.JAVA )
.setSourcePath( "org/drools/compiler/test/PersonObject.java" );
Resource drlResource = ResourceFactory.newByteArrayResource( person_drl.getBytes() ).setResourceType( ResourceType.DRL )
.setSourcePath( "kbase1/person.drl" );
KieModule km = createAndDeployJar( ks, kmodule, releaseId1, javaResource, drlResource );
// update container
kieContainer.updateToVersion(releaseId2);
动态规则加载。
// Create an in-memory jar for version 1.0.0
ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-upgrade-java", "1.0.0" );
Resource javaResource = ResourceFactory.newByteArrayResource(javaSrc.getBytes()).setResourceType( ResourceType.JAVA )
.setSourcePath( "org/drools/compiler/test/PersonObject.java" );
Resource drlResource = ResourceFactory.newByteArrayResource( person_drl.getBytes() ).setResourceType( ResourceType.DRL )
.setSourcePath( "kbase1/person.drl" );
KieModule km = createAndDeployJar( ks, kmodule, releaseId1, javaResource, drlResource );
// update container
kieContainer.updateToVersion(releaseId2);
Dynamic Rule Removal⌘
kbase.removeRule("org.kie.test", ruleName);
动态规则删除。
kbase.removeRule("org.kie.test", ruleName);
Dynamic Rules Test⌘
动态规则测试。
KieScanner⌘
It continuously monitors your Maven repository to check if a new release of a Kie project has been installed and if so, deploys it in the KieContainer wrapping that project.
Example 2.12. Registering and starting a KieScanner on a KieContainer
KieServices kieServices = KieServices.Factory.get();
ReleaseId releaseId = kieServices.newReleaseId( "org.acme", "myartifact", "1.0-SNAPSHOT" );
KieContainer kContainer = kieServices.newKieContainer( releaseId );
KieScanner kScanner = kieServices.newKieScanner( kContainer );
// Start the KieScanner polling the Maven repository every 10 seconds
kScanner.start( 10000L );
In this example the KieScanner is configured to run with a fixed time interval, but it is also possible to run it on demand by invoking the scanNow() method on it. If the KieScanner finds, in the Maven repository, an updated version of the Kie project used by that KieContainer it automatically downloads the new version and triggers an incremental build of the new project. From this moment all the new KieBases and KieSessions created from that KieContainer will use the new project version.
KieScanner。
不间断的监视你的Maven repository检查是否a Kie项目有新的发行版本,如果有,在包含该项目的KieContainer中进行部署
例 2.12. 在KieContainer里注册并启动一个KieScanner
KieServices kieServices = KieServices.Factory.get();
ReleaseId releaseId = kieServices.newReleaseId( "org.acme", "myartifact", "1.0-SNAPSHOT" );
KieContainer kContainer = kieServices.newKieContainer( releaseId );
KieScanner kScanner = kieServices.newKieScanner( kContainer );
// Start the KieScanner polling the Maven repository every 10 seconds
kScanner.start( 10000L );
本例中,KieScanner配置为以固定时间间隔运行, 也可以通过调用它的scanNow()方法,按需运行. 如果KieScanner在Maven repository找到一个KieContainer所使用的Kie项目的更新了的版本,它将自动下载该新版本,并且对新的项目开始进行增量编译。而从此刻起,所有的由KieContainer建立的新的KieBases 和 KieSessions 都将使用这个新项目版本。