我试图以周期性的间隔插入由KieRunTimeLogger函数生成的日志中,因为我的“ claim id”(我从getter中获取的变量)随着在对象上的迭代而变化,并且仅在最后一个值插入之后称为“ Ksession.execute”。
我使用了一个名为“ globalStringK”的全局字符串(在下面的日志中)来附加所有已解析的“声明ID”。但是,请查看日志中的“声明ID”,只有最后一个“数字被执行”。
该日志显示了已在.drl文件中命中的所有规则,但是我需要及时插入“领取ID”,以便说出哪个规则命中了哪个对象,而不是被覆盖。
我指的是这些https://access.redhat.com/documentation/en-us/red_hat_jboss_bpm_suite/6.1/html/development_guide/sect-kie_sessions,并尝试使用以下链接并尝试添加此链接。这是正确的方法吗?
例如
StatelessKieSession kSession = kContainer.newStatelessKieSession();
Applicant applicant = new Applicant( "Mr John Smith", 16 );
assertTrue( applicant.isValid() );
ksession.execute( applicant );
assertFalse( applicant.isValid() );
这是我为应用程序生成的对象流生成的日志。
<object-stream>
<org.drools.core.audit.WorkingMemoryLog>
<version>6.1</version>
<events>
<org.drools.core.audit.event.ObjectLogEvent>
<type>1</type>
<factId>1</factId>
<objectToString>globalStringK = EK0970218 XB9772517 DQ6175084 EK0970518</objectToString>
</org.drools.core.audit.event.ObjectLogEvent>
<org.drools.core.audit.event.ObjectLogEvent>
<type>1</type>
<factId>1</factId>
<objectToString>claim ID = EK0970518</objectToString>
</org.drools.core.audit.event.ObjectLogEvent>
<org.drools.core.audit.event.ObjectLogEvent>
<type>1</type>
<factId>1</factId>
<objectToString>com.rsrit.cob.Variables.ClaimInfo@5774994a</objectToString>
</org.drools.core.audit.event.ObjectLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>4</type>
<activationId>recovery default [1]</activationId>
<rule>recovery default</rule>
<declarations>$a1=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>6</type>
<activationId>recovery default [1]</activationId>
<rule>recovery default</rule>
<declarations>$a1=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>7</type>
<activationId>recovery default [1]</activationId>
<rule>recovery default</rule>
<declarations>$a1=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>4</type>
<activationId>checking primacy [1]</activationId>
<rule>checking primacy</rule>
<declarations>$a2=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>6</type>
<activationId>checking primacy [1]</activationId>
<rule>checking primacy</rule>
<declarations>$a2=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>7</type>
<activationId>checking primacy [1]</activationId>
<rule>checking primacy</rule>
<declarations>$a2=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>4</type>
<activationId>procedures [1, 1]</activationId>
<rule>procedures</rule>
<declarations>$a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>6</type>
<activationId>procedures [1, 1]</activationId>
<rule>procedures</rule>
<declarations>$a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>7</type>
<activationId>procedures [1, 1]</activationId>
<rule>procedures</rule>
<declarations>$a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>4</type>
<activationId>provider within country [1, 1, 1]</activationId>
<rule>provider within country</rule>
<declarations>$a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>6</type>
<activationId>provider within country [1, 1, 1]</activationId>
<rule>provider within country</rule>
<declarations>$a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>7</type>
<activationId>provider within country [1, 1, 1]</activationId>
<rule>provider within country</rule>
<declarations>$a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>4</type>
<activationId>claim_line_item [1, 1, 1, 1]</activationId>
<rule>claim_line_item</rule>
<declarations>$a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>6</type>
<activationId>claim_line_item [1, 1, 1, 1]</activationId>
<rule>claim_line_item</rule>
<declarations>$a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>7</type>
<activationId>claim_line_item [1, 1, 1, 1]</activationId>
<rule>claim_line_item</rule>
<declarations>$a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>4</type>
<activationId>claim_line_item_part_type_B [1, 1, 1, 1, 1]</activationId>
<rule>claim_line_item_part_type_B</rule>
<declarations>$a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a7=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>6</type>
<activationId>claim_line_item_part_type_B [1, 1, 1, 1, 1]</activationId>
<rule>claim_line_item_part_type_B</rule>
<declarations>$a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a7=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>7</type>
<activationId>claim_line_item_part_type_B [1, 1, 1, 1, 1]</activationId>
<rule>claim_line_item_part_type_B</rule>
<declarations>$a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a7=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>4</type>
<activationId>event_name_phase1_b [1, 1, 1, 1, 1, 1]</activationId>
<rule>event_name_phase1_b</rule>
<declarations>$a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a7=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a10=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>6</type>
<activationId>event_name_phase1_b [1, 1, 1, 1, 1, 1]</activationId>
<rule>event_name_phase1_b</rule>
<declarations>$a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a7=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a10=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>7</type>
<activationId>event_name_phase1_b [1, 1, 1, 1, 1, 1]</activationId>
<rule>event_name_phase1_b</rule>
<declarations>$a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a7=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a10=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>4</type>
<activationId>event_dates_B [1, 1, 1, 1, 1, 1, 1, 2]</activationId>
<rule>event_dates_B</rule>
<declarations>$a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a7=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a10=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a13=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1,2</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>6</type>
<activationId>event_dates_B [1, 1, 1, 1, 1, 1, 1, 2]</activationId>
<rule>event_dates_B</rule>
<declarations>$a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a7=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a10=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a13=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1,2</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>7</type>
<activationId>event_dates_B [1, 1, 1, 1, 1, 1, 1, 2]</activationId>
<rule>event_dates_B</rule>
<declarations>$a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a7=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a10=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a13=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1,2</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>4</type>
<activationId>SPECIAL_PARTB_CASE [1, 1, 1, 1, 1, 1, 1, 2, 1]</activationId>
<rule>SPECIAL_PARTB_CASE</rule>
<declarations>$a15=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a7=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a10=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a13=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1,2</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>6</type>
<activationId>SPECIAL_PARTB_CASE [1, 1, 1, 1, 1, 1, 1, 2, 1]</activationId>
<rule>SPECIAL_PARTB_CASE</rule>
<declarations>$a15=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a7=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a10=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a13=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1,2</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ObjectLogEvent>
<type>2</type>
<factId>1</factId>
<objectToString>com.rsrit.cob.Variables.ClaimInfo@5774994a</objectToString>
</org.drools.core.audit.event.ObjectLogEvent>
<org.drools.core.audit.event.ObjectLogEvent>
<type>2</type>
<factId>1</factId>
<objectToString>com.rsrit.cob.Variables.ClaimInfo@5774994a</objectToString>
</org.drools.core.audit.event.ObjectLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>7</type>
<activationId>SPECIAL_PARTB_CASE [1, 1, 1, 1, 1, 1, 1, 2, 1]</activationId>
<rule>SPECIAL_PARTB_CASE</rule>
<declarations>$a15=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a2=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a3=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a4=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a5=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a7=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a10=com.rsrit.cob.Variables.ClaimInfo@5774994a; $a13=com.rsrit.cob.Variables.ClaimInfo@5774994a</declarations>
<factHandleIds>1,2</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
</events>
</org.drools.core.audit.W
orkingMemoryLog>
我的rulesExecutor代码
package com.rsrit.cob.drools;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.Serializable;
import java.util.ArrayList;
import javax.validation.constraints.AssertTrue;
import org.kie.api.KieServices;
import org.kie.api.logger.KieRuntimeLogger;
import org.kie.api.runtime.StatelessKieSession;
import org.kie.internal.command.CommandFactory;
import org.kie.api.runtime.rule.EntryPoint;
import org.kie.api.runtime.rule.FactHandle;
import org.kie.api.command.*;
import org.kie.*;
import java.util.*;
import com.rsrit.cob.Variables.ClaimInfo;
import com.rsrit.cob.drools.KieSessionFactory;
@SuppressWarnings("serial")
public class RulesExecutor implements Serializable{
public static BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
@SuppressWarnings("unchecked")
public ClaimInfo evalRules(ClaimInfo claimObj,String ruleFileLoc){
if (ruleFileLoc != null){
StatelessKieSession ksession = KieSessionFactory.getKieSession(ruleFileLoc);
KieRuntimeLogger logger = KieServices.Factory.get().getLoggers().newFileLogger(ksession,"C://Users/katuk/eclipse-workspace/COB");
String claim_Id = claimObj.getClm_id();
int claim_Id_int = Integer.parseInt(claim_Id);
KieSessionFactory.globalStringK = KieSessionFactory.globalStringK + "\t" +claim_Id;
ksession.execute("globalStringK = "+KieSessionFactory.globalStringK);
ksession.setGlobal(KieSessionFactory.globalStringK, claim_Id);
ksession.execute("claim ID = "+claim_Id);
System.out.println("claim id = "+claim_Id);
ksession.execute(CommandFactory.newInsert(claimObj));
logger.close();
}else{
try{
log.write("Rules File Location is Invalid or Null\n");
log.flush();
}catch(Exception e){
e.printStackTrace();
}
}
return claimObj;
}
}