Skip to content

Instantly share code, notes, and snippets.

@tkobayas
Created December 2, 2019 07:08
Show Gist options
  • Save tkobayas/8836018dd844ab672eec30c44c53083d to your computer and use it in GitHub Desktop.
Save tkobayas/8836018dd844ab672eec30c44c53083d to your computer and use it in GitHub Desktop.
ksession reset : the other idea
public void resetAllMemories(StatefulKnowledgeSession session) {
InternalKnowledgeBase kBase = (InternalKnowledgeBase) session.getKieBase();
for (int i = 0; i < memories.length(); i++) {
Memory memory = memories.get(i);
if (memory != null) {
memory.reset();
if (memory instanceof PathMemory) {
SegmentMemory[] smems = ((PathMemory) memory).getSegmentMemories();
if (smems != null) {
for (SegmentMemory smem : smems) {
resetSegmentMemory(session, kBase, smem);
}
}
} else {
SegmentMemory smem = memory.getSegmentMemory();
resetSegmentMemory(session, kBase, smem);
}
}
}
}
private void resetSegmentMemory(StatefulKnowledgeSession session, InternalKnowledgeBase kBase, SegmentMemory smem) {
if (smem != null) {
smem.reset(kBase.getSegmentPrototype(smem));
if (smem.isSegmentLinked()) {
smem.notifyRuleLinkSegment((InternalWorkingMemory) session);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment