KieScanner在运行时不更新KieSessions [英] KieScanner not updating KieSessions at runtime

查看:68
本文介绍了KieScanner在运行时不更新KieSessions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Drools与Eclipse和Maven结合使用来进行许多模式匹配的应用程序.我想使用KieScanner自动更新正在运行的KieSession,而无需重新启动应用程序.但这似乎不起作用.

我将7.24.0.t043用于org.kie和org.drools.

为此,我仅使用本地Maven存储库,因此我已指定路径并在settings.xml中将其设置为true.我还验证了使用最新版本创建新的KieContainer会记录更改的规则.KieScanner.scanNow()似乎不适合我.我查看了错误日志,似乎根本没有任何错误,一切运行正常.我很确定我也将每个版本正确包装到kjars中,并将它们安装在本地Maven存储库中.此外,我将新的kjar版本设为2.0.0-SNAPSHOT.

kContainer.updateToVersion()仅在我在KieSession设置期间的运行器类的开头调用它时对我有用,但如果在下面的while循环中调用它,则不起作用.

kContainer.updateToVersion()仅对我有用.>

在这里,我正在跑步者课程中设置我的KieSession:

  KieServices ks = KieServices.Factory.get();ReleaseId releaseId = ks.newReleaseId("com.app","my-app","1.0.0");KieContainer kContainer = ks.newKieContainer(releaseId);KieScanner kScanner = ks.newKieScanner(kContainer);kScanner.scanNow();KieSession kSession = kContainer.getKieBase().newKieSession(); 

设置完成后,我将对象插入kSession并调用fireAllRules()一次.

我正在使用while循环来打印出对我的对象所做的更改(已将其插入到kSession中):

  while(true){System.out.println("a1的匹配项:" + a1.getMatches());TimeUnit.SECONDS.sleep(10);} 

我希望在更新后的规则之后打印出更新后的匹配项,但是实际的打印出并不会更改匹配项.

Pom文件:

 <?xml version ="1.0" encoding ="UTF-8"?>< project xmlns ="http://maven.apache.org/POM/4.0.0" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation ="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">< modelVersion> 4.0.0</modelVersion>< groupId> com.app</groupId>< artifactId> genentech-maven-poc</artifactId>< version> 0.0.1-SNAPSHOT</version>< name> Genentech Maven POC</name><属性>< maven.compiler.target> 1.8</maven.compiler.target>< maven.compiler.source> 1.8</maven.compiler.source>< runtime.version> 7.24.0.t043</runtime.version></properties><存储库><存储库>< id> local-repo</id>< name>本地Maven仓库</name>< url> file://Users/mtsiang/.m2/repository</url>< snapshots>< enabled> true</enabled>< updatePolicy>始终</updatePolicy></snapshots></存储库></存储库><依赖关系><依赖关系>< groupId> org.slf4j</groupId>< artifactId> slf4j-simple</artifactId>< version> 1.7.26</version></dependency><依赖关系>< groupId> org.kie</groupId>< artifactId> kie-api</artifactId>< version> $ {runtime.version}</version></dependency><依赖关系>< groupId> org.kie</groupId>< artifactId> kie-ci</artifactId>< version> $ {runtime.version}</version>< scope>运行时</scope></dependency><依赖关系>< groupId> org.drools</groupId>< artifactId> drools-core</artifactId>< version> $ {runtime.version}</version></dependency><依赖关系>< groupId> org.drools</groupId>< artifactId> drools-compiler</artifactId>< version> $ {runtime.version}</version></dependency><依赖关系>< groupId> junit</groupId>< artifactId> junit</artifactId>< version> 4.12</version>< scope> test</scope></dependency></dependencies></project> 

如果您需要我提供更多信息,请告诉我,我不确定我还需要包括哪些内容以使您了解问题.

解决方案

因此,我找到了原因.

在指定KieContainer创建和releaseId时,请确保使用"LATEST",如下所示:

  ReleaseId releaseId = ks.newReleaseId("com.app","my-app","LATEST");//代替"1.0.0"KieContainer kContainer = ks.newKieContainer(releaseId); 

通过这种方式,KieScanner将读取Maven回购meta.xml文件中的< release></release> 标记.

要触发新规则,您还需要调用 kSession.update(FACTHANDLE,OBJ); ,然后调用 kSession.fireAllRules(); .

I'm using Drools with Eclipse and Maven for an application doing many-many pattern matching. I wanted to use KieScanner to automatically update the running KieSession without restarting the application. But this doesn't seem to be working.

I am using 7.24.0.t043 for org.kie and org.drools.

I'm only using my local Maven repo for this, so I've specified the path and set true in my settings.xml. I also verified that creating a new KieContainer with the most recent version registers the changed rules. KieScanner.scanNow() doesn't seem to work for me. I've looked through the error logs and there doesn't seem to be any errors at all, everything is running fine. I'm pretty sure I'm also packaging each version correctly into kjars and installing them in my local Maven repo. Additionally, I'm putting my new kjar version as 2.0.0-SNAPSHOT.

kContainer.updateToVersion() works for me only when I call it at the beginning of my runner class during KieSession setup, but does not work if I call it in the while loop below.

Here I am setting up my KieSession in my runner class:

KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("com.app", "my-app", "1.0.0");
KieContainer kContainer = ks.newKieContainer(releaseId);
KieScanner kScanner = ks.newKieScanner(kContainer);
kScanner.scanNow();
KieSession kSession = kContainer.getKieBase().newKieSession();

After setting this up, I insert my objects into kSession and call fireAllRules() once.

I'm using a while loop to print out the changes done to my object (which I've inserted into the kSession):

while (true) {
  System.out.println("Matches of a1: " + a1.getMatches());
  TimeUnit.SECONDS.sleep(10);
}

I expect printing out the updated matches after the updated rules, however the actual printing out is not changing the matches.

Pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.app</groupId>
    <artifactId>genentech-maven-poc</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Genentech Maven POC</name>
    <properties>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
        <runtime.version>7.24.0.t043</runtime.version>
    </properties>
    <repositories>
        <repository>
            <id>local-repo</id>
            <name>Local Maven Repo</name>
            <url>file://Users/mtsiang/.m2/repository</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.26</version>
        </dependency>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-api</artifactId>
            <version>${runtime.version}</version>
        </dependency>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-ci</artifactId>
            <version>${runtime.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-core</artifactId>
            <version>${runtime.version}</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-compiler</artifactId>
            <version>${runtime.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

Please let me know if you need more information from me, I'm not really sure what else I'd need to include for you to get a sense of the problem.

解决方案

So, I found the reason why.

When specifying the KieContainer creation and releaseId, make sure to use "LATEST" as in:

ReleaseId releaseId = ks.newReleaseId("com.app", "my-app", "LATEST"); //instead of "1.0.0"
KieContainer kContainer = ks.newKieContainer(releaseId);

This way, KieScanner will read in the <release></release> tag in the Maven repo metadata.xml file.

To fire the new rules, you'd also need to call kSession.update(FACTHANDLE, OBJ); and then kSession.fireAllRules();.

这篇关于KieScanner在运行时不更新KieSessions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆