use of org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem in project drools by kiegroup.
the class TruthMaintenanceSystemKnowledgeHelper method blockMatch.
@Override
public void blockMatch(Match act) {
TruthMaintenanceSystemAgendaItem targetMatch = (TruthMaintenanceSystemAgendaItem) act;
// iterate to find previous equal logical insertion
LogicalDependency<SimpleMode> dep = null;
if (this.previousBlocked != null) {
for (dep = this.previousBlocked.getFirst(); dep != null; dep = dep.getNext()) {
if (targetMatch == dep.getJustified()) {
this.previousBlocked.remove(dep);
break;
}
}
}
if (dep == null) {
SimpleMode mode = new SimpleMode();
dep = new SimpleLogicalDependency((TruthMaintenanceSystemActivation) this.activation, targetMatch, mode);
mode.setObject(dep);
}
((TruthMaintenanceSystemActivation) this.activation).addBlocked(dep);
if (targetMatch.getBlockers().size() == 1 && targetMatch.isQueued()) {
if (targetMatch.getRuleAgendaItem() == null) {
// it wasn't blocked before, but is now, so we must remove it from all groups, so it cannot be executed.
targetMatch.remove();
} else {
targetMatch.getRuleAgendaItem().getRuleExecutor().removeLeftTuple(targetMatch.getTuple());
}
if (targetMatch.getActivationGroupNode() != null) {
targetMatch.getActivationGroupNode().getActivationGroup().removeActivation(targetMatch);
}
if (targetMatch.getActivationNode() != null) {
final InternalRuleFlowGroup ruleFlowGroup = (InternalRuleFlowGroup) targetMatch.getActivationNode().getParentContainer();
ruleFlowGroup.remove(targetMatch);
}
}
}
use of org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem in project drools by kiegroup.
the class TruthMaintenanceSystemKnowledgeHelper method cancelRemainingPreviousLogicalDependencies.
public void cancelRemainingPreviousLogicalDependencies() {
if (this.previousJustified != null) {
for (LogicalDependency<T> dep = this.previousJustified.getFirst(); dep != null; dep = dep.getNext()) {
TruthMaintenanceSystemImpl.removeLogicalDependency(dep, activation.getPropagationContext());
}
}
if (this.previousBlocked != null) {
for (LogicalDependency<SimpleMode> dep = this.previousBlocked.getFirst(); dep != null; ) {
LogicalDependency<SimpleMode> tmp = dep.getNext();
this.previousBlocked.remove(dep);
TruthMaintenanceSystemAgendaItem justified = (TruthMaintenanceSystemAgendaItem) dep.getJustified();
justified.getBlockers().remove(dep.getMode());
if (justified.getBlockers().isEmpty()) {
RuleAgendaItem ruleAgendaItem = justified.getRuleAgendaItem();
toStatefulKnowledgeSession().getAgenda().stageLeftTuple(ruleAgendaItem, justified);
}
dep = tmp;
}
}
}
use of org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem in project drools by kiegroup.
the class TruthMaintenanceSystemKnowledgeHelper method unblockAllMatches.
@Override
public void unblockAllMatches(Match act) {
TruthMaintenanceSystemAgendaItem targetMatch = (TruthMaintenanceSystemAgendaItem) act;
boolean wasBlocked = (targetMatch.getBlockers() != null && !targetMatch.getBlockers().isEmpty());
for (LinkedListEntry entry = (LinkedListEntry) targetMatch.getBlockers().getFirst(); entry != null; ) {
LinkedListEntry tmp = (LinkedListEntry) entry.getNext();
LogicalDependency dep = (LogicalDependency) entry.getObject();
((TruthMaintenanceSystemAgendaItem) dep.getJustifier()).removeBlocked(dep);
entry = tmp;
}
if (wasBlocked) {
RuleAgendaItem ruleAgendaItem = targetMatch.getRuleAgendaItem();
InternalAgenda agenda = toStatefulKnowledgeSession().getAgenda();
agenda.stageLeftTuple(ruleAgendaItem, targetMatch);
}
}
use of org.drools.tms.agenda.TruthMaintenanceSystemAgendaItem in project drools by kiegroup.
the class ProtobufOutputMarshaller method writeActivation.
public static <M extends ModedAssertion<M>> ProtobufMessages.Activation writeActivation(MarshallerWriteContext context, AgendaItem agendaItem, boolean isDormient) {
ProtobufMessages.Activation.Builder _activation = ProtobufMessages.Activation.newBuilder();
RuleImpl rule = agendaItem.getRule();
_activation.setPackageName(rule.getPackage());
_activation.setRuleName(rule.getName());
_activation.setTuple(writeTuple(context, agendaItem, isDormient));
_activation.setSalience(agendaItem.getSalience());
_activation.setIsActivated(agendaItem.isQueued());
_activation.setEvaluated(agendaItem.isRuleAgendaItem());
if (agendaItem.getActivationGroupNode() != null) {
_activation.setActivationGroup(agendaItem.getActivationGroupNode().getActivationGroup().getName());
}
if (agendaItem.getActivationFactHandle() != null) {
_activation.setHandleId(agendaItem.getActivationFactHandle().getId());
}
if (agendaItem instanceof TruthMaintenanceSystemAgendaItem) {
org.drools.core.util.LinkedList<LogicalDependency<M>> list = ((TruthMaintenanceSystemAgendaItem) agendaItem).getLogicalDependencies();
if (list != null && !list.isEmpty()) {
for (LogicalDependency<?> node = list.getFirst(); node != null; node = node.getNext()) {
_activation.addLogicalDependency(((BeliefSet) node.getJustified()).getFactHandle().getId());
}
}
}
return _activation.build();
}
Aggregations