use of org.drools.kiesession.entrypoints.NamedEntryPoint in project drools by kiegroup.
the class TraitHelperImpl method update.
public void update(final FactHandle handle, BitMask mask, Class<?> modifiedClass, Activation activation) {
InternalFactHandle h = (InternalFactHandle) handle;
((NamedEntryPoint) h.getEntryPoint(workingMemory)).update(h, ((InternalFactHandle) handle).getObject(), mask, modifiedClass, activation);
if (h.isTraitOrTraitable()) {
workingMemory.updateTraits(h, mask, modifiedClass, activation);
}
}
use of org.drools.kiesession.entrypoints.NamedEntryPoint in project drools by kiegroup.
the class TraitHelperImpl method updateManyTraits.
private void updateManyTraits(Object object, BitMask mask, Collection<Thing> originators, Class<?> modifiedClass, Collection<Thing> traits, Activation activation) {
for (Thing t : traits) {
if (!originators.contains(t)) {
InternalFactHandle h = (InternalFactHandle) lookupFactHandle(t);
if (h != null) {
NamedEntryPoint nep = (NamedEntryPoint) h.getEntryPoint(workingMemory);
PropagationContext propagationContext = nep.getPctxFactory().createPropagationContext(nep.getReteEvaluator().getNextPropagationIdCounter(), PropagationContext.Type.MODIFICATION, activation != null ? activation.getRule() : null, activation != null ? activation.getTuple().getTupleSink() : null, h, nep.getEntryPoint(), mask, modifiedClass, null);
nep.update(h, t, t, nep.getObjectTypeConfigurationRegistry().getObjectTypeConf(t), propagationContext);
}
}
}
}
use of org.drools.kiesession.entrypoints.NamedEntryPoint in project drools by kiegroup.
the class FactHandleMarshallingTest method createEventFactHandle.
private InternalFactHandle createEventFactHandle(StatefulKnowledgeSessionImpl wm, InternalKnowledgeBase kBase) {
// EntryPointNode
Rete rete = kBase.getRete();
NodeFactory nFacotry = CoreComponentFactory.get().getNodeFactoryService();
RuleBasePartitionId partionId = RuleBasePartitionId.MAIN_PARTITION;
EntryPointNode entryPointNode = nFacotry.buildEntryPointNode(1, partionId, false, rete, EntryPointId.DEFAULT);
WorkingMemoryEntryPoint wmEntryPoint = new NamedEntryPoint(EntryPointId.DEFAULT, entryPointNode, wm);
EventFactHandle factHandle = new EventFactHandle(1, new Person(), 0, (new Date()).getTime(), 0, wmEntryPoint);
return factHandle;
}
use of org.drools.kiesession.entrypoints.NamedEntryPoint in project drools by kiegroup.
the class ConstraintNormalizationTest method testNormalizationForAlphaIndexing.
@Test
public void testNormalizationForAlphaIndexing() {
final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + "rule R1 when \n" + " $p : Person(\"Toshiya\" == name)\n" + "then\n" + "end\n" + "rule R2 when \n" + " $p : Person(\"Mario\" == name)\n" + "then\n" + "end\n" + "rule R3 when \n" + " $p : Person(\"Luca\" == name)\n" + "then\n" + "end\n";
final KieSession ksession = getKieSession(str);
ObjectTypeNode otn = ((NamedEntryPoint) ksession.getEntryPoint("DEFAULT")).getEntryPointNode().getObjectTypeNodes().entrySet().stream().filter(e -> e.getKey().getClassName().equals(Person.class.getCanonicalName())).map(e -> e.getValue()).findFirst().get();
ObjectSinkPropagator objectSinkPropagator = otn.getObjectSinkPropagator();
CompositeObjectSinkAdapter sinkAdaptor = (CompositeObjectSinkAdapter) objectSinkPropagator;
assertNotNull(sinkAdaptor.getHashedSinkMap());
assertEquals(3, sinkAdaptor.getHashedSinkMap().size());
final Person p = new Person("Toshiya", 45);
ksession.insert(p);
assertEquals(1, ksession.fireAllRules());
}
use of org.drools.kiesession.entrypoints.NamedEntryPoint in project drools by kiegroup.
the class ProtobufOutputMarshaller method writeTruthMaintenanceSystem.
public static void writeTruthMaintenanceSystem(MarshallerWriteContext context, EntryPoint wmep, ProtobufMessages.EntryPoint.Builder _epb) throws IOException {
TruthMaintenanceSystem tms = TruthMaintenanceSystemFactory.get().getOrCreateTruthMaintenanceSystem((NamedEntryPoint) wmep);
ObjectHashMap justifiedMap = tms.getEqualityKeyMap();
if (!justifiedMap.isEmpty()) {
EqualityKey[] keys = new EqualityKey[justifiedMap.size()];
org.drools.core.util.Iterator it = justifiedMap.iterator();
int i = 0;
for (org.drools.core.util.ObjectHashMap.ObjectEntry entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next(); entry != null; entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next()) {
EqualityKey key = (EqualityKey) entry.getKey();
keys[i++] = key;
}
Arrays.sort(keys, EqualityKeySorter.instance);
ProtobufMessages.TruthMaintenanceSystem.Builder _tms = ProtobufMessages.TruthMaintenanceSystem.newBuilder();
// write the assert map of Equality keys
for (EqualityKey key : keys) {
ProtobufMessages.EqualityKey.Builder _key = ProtobufMessages.EqualityKey.newBuilder();
_key.setStatus(key.getStatus());
_key.setHandleId(key.getFactHandle().getId());
if (key.size() > 1) {
// add all the other key's if they exist
FastIterator keyIter = key.fastIterator();
for (DefaultFactHandle handle = key.getFirst().getNext(); handle != null; handle = (DefaultFactHandle) keyIter.next(handle)) {
_key.addOtherHandle(handle.getId());
}
}
if (((TruthMaintenanceSystemEqualityKey) key).getBeliefSet() != null) {
writeBeliefSet(context, ((TruthMaintenanceSystemEqualityKey) key).getBeliefSet(), _key);
}
_tms.addKey(_key.build());
}
_epb.setTms(_tms.build());
}
}
Aggregations