Created
December 2, 2019 07:08
-
-
Save tkobayas/8836018dd844ab672eec30c44c53083d to your computer and use it in GitHub Desktop.
ksession reset : the other idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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