use of org.drools.tms.agenda.TruthMaintenanceSystemActivation 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.TruthMaintenanceSystemActivation in project drools by kiegroup.
the class TruthMaintenanceSystemKnowledgeHelper method bolster.
@Override
public InternalFactHandle bolster(final Object object, final Object value) {
if (object == null || !activation.isMatched()) {
return null;
}
InternalFactHandle handle = getFactHandleFromWM(object);
NamedEntryPoint ep = (NamedEntryPoint) reteEvaluator.getEntryPoint(EntryPointId.DEFAULT.getEntryPointId());
ObjectTypeConf otc = ep.getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(ep.getEntryPoint(), object);
BeliefSet beliefSet = null;
if (handle == null) {
handle = RuntimeComponentFactory.get().getFactHandleFactoryService().newFactHandle(object, otc, reteEvaluator, ep);
}
if (handle.getEqualityKey() == null) {
handle.setEqualityKey(new TruthMaintenanceSystemEqualityKey(handle, EqualityKey.STATED));
} else {
beliefSet = ((TruthMaintenanceSystemEqualityKey) handle.getEqualityKey()).getBeliefSet();
}
BeliefSystem beliefSystem = value instanceof BeliefSystemMode ? ((BeliefSystemMode) value).getBeliefSystem() : ((TruthMaintenanceSystemImpl) TruthMaintenanceSystemFactory.get().getOrCreateTruthMaintenanceSystem(toStatefulKnowledgeSession())).getBeliefSystem();
if (beliefSet == null) {
beliefSet = beliefSystem.newBeliefSet(handle);
((TruthMaintenanceSystemEqualityKey) handle.getEqualityKey()).setBeliefSet(beliefSet);
}
return beliefSystem.insert(beliefSystem.asMode(value), activation.getRule(), (TruthMaintenanceSystemActivation) activation, object, beliefSet, activation.getPropagationContext(), otc).getFactHandle();
}
use of org.drools.tms.agenda.TruthMaintenanceSystemActivation in project drools by kiegroup.
the class TruthMaintenanceSystemKnowledgeHelper method setActivation.
@Override
public void setActivation(final Activation agendaItem) {
TruthMaintenanceSystemActivation tmsActivation = (TruthMaintenanceSystemActivation) agendaItem;
this.previousJustified = tmsActivation.getLogicalDependencies();
this.previousBlocked = tmsActivation.getBlocked();
super.setActivation(agendaItem);
tmsActivation.setLogicalDependencies(null);
tmsActivation.setBlocked(null);
}
Aggregations