use of org.drools.core.spi.AlphaNodeFieldConstraint in project drools by kiegroup.
the class PhreakFromNode method doLeftInserts.
public void doLeftInserts(FromNode fromNode, FromMemory fm, LeftTupleSink sink, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples) {
BetaMemory bm = fm.getBetaMemory();
ContextEntry[] context = bm.getContext();
BetaConstraints betaConstraints = fromNode.getBetaConstraints();
AlphaNodeFieldConstraint[] alphaConstraints = fromNode.getAlphaConstraints();
DataProvider dataProvider = fromNode.getDataProvider();
Class<?> resultClass = fromNode.getResultClass();
for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
PropagationContext propagationContext = leftTuple.getPropagationContext();
Map<Object, RightTuple> matches = null;
boolean useLeftMemory = RuleNetworkEvaluator.useLeftMemory(fromNode, leftTuple);
if (useLeftMemory) {
fm.getBetaMemory().getLeftTupleMemory().add(leftTuple);
matches = new LinkedHashMap<Object, RightTuple>();
leftTuple.setContextObject(matches);
}
betaConstraints.updateFromTuple(context, wm, leftTuple);
for (final java.util.Iterator<?> it = dataProvider.getResults(leftTuple, wm, propagationContext, fm.providerContext); it.hasNext(); ) {
final Object object = it.next();
if ((object == null) || !resultClass.isAssignableFrom(object.getClass())) {
// skip anything if it not assignable
continue;
}
RightTuple rightTuple = fromNode.createRightTuple(leftTuple, propagationContext, wm, object);
checkConstraintsAndPropagate(sink, leftTuple, rightTuple, alphaConstraints, betaConstraints, propagationContext, wm, fm, context, useLeftMemory, trgLeftTuples, null);
if (useLeftMemory) {
fromNode.addToCreatedHandlesMap(matches, rightTuple);
}
}
leftTuple.clearStaged();
leftTuple = next;
}
betaConstraints.resetTuple(context);
}
use of org.drools.core.spi.AlphaNodeFieldConstraint in project drools by kiegroup.
the class PatternBuilder method createConstraints.
private Constraints createConstraints(BuildContext context, Pattern pattern) {
Constraints constraints = new Constraints();
// check if cross products for identity patterns should be disabled
checkRemoveIdentities(context, pattern, constraints.betaConstraints);
// checks if this pattern is nested inside a NOT CE
final boolean isNegative = isNegative(context);
for (Constraint constraint : pattern.getConstraints()) {
switch(constraint.getType()) {
case ALPHA:
linkAlphaConstraint((AlphaNodeFieldConstraint) constraint, constraints.alphaConstraints);
break;
case BETA:
linkBetaConstraint((BetaNodeFieldConstraint) constraint, constraints.betaConstraints);
if (isNegative && context.getKnowledgeBase().getConfiguration().getEventProcessingMode() == EventProcessingOption.STREAM && pattern.getObjectType().isEvent() && constraint.isTemporal()) {
checkDelaying(context, constraint);
}
break;
case XPATH:
constraints.xpathConstraints.add((XpathConstraint) constraint);
break;
default:
throw new RuntimeException("Unknown constraint type: " + constraint.getType() + ". This is a bug. Please contact development team.");
}
}
return constraints;
}
use of org.drools.core.spi.AlphaNodeFieldConstraint in project drools by kiegroup.
the class ReactiveFromBuilder method build.
public void build(final BuildContext context, final BuildUtils utils, final RuleConditionElement rce) {
final From from = (From) rce;
context.pushRuleComponent(from);
@SuppressWarnings("unchecked") BetaConstraints betaConstraints = utils.createBetaNodeConstraint(context, context.getBetaconstraints(), true);
AlphaNodeFieldConstraint[] alphaNodeFieldConstraints = context.getAlphaConstraints() != null ? context.getAlphaConstraints().toArray(new AlphaNodeFieldConstraint[context.getAlphaConstraints().size()]) : new AlphaNodeFieldConstraint[0];
ReactiveFromNode node = context.getComponentFactory().getNodeFactoryService().buildReactiveFromNode(context.getNextId(), from.getDataProvider(), context.getTupleSource(), alphaNodeFieldConstraints, betaConstraints, context.isTupleMemoryEnabled(), context, from);
context.setTupleSource(utils.attachNode(context, node));
context.setAlphaConstraints(null);
context.setBetaconstraints(null);
context.incrementCurrentPatternOffset();
int patternOffset = context.getCurrentPatternOffset();
List<XpathConstraint> xpathConstraints = context.getXpathConstraints();
for (XpathConstraint xpathConstraint : xpathConstraints) {
for (XpathConstraint.XpathChunk chunk : xpathConstraint.getChunks()) {
context.setAlphaConstraints(chunk.getAlphaConstraints());
context.setBetaconstraints(chunk.getBetaConstraints());
context.setXpathConstraints(chunk.getXpathConstraints());
build(context, utils, chunk.asFrom());
}
}
context.setCurrentPatternOffset(patternOffset);
}
use of org.drools.core.spi.AlphaNodeFieldConstraint in project drools by kiegroup.
the class CompositeObjectSinkAdapter method removeObjectSink.
public ObjectSinkPropagator removeObjectSink(final ObjectSink sink) {
// dirty it, so it'll rebuild on next get
this.sinks = null;
if (this.sinksMap != null) {
this.sinksMap.remove(sink);
}
if (sink.getType() == NodeTypeEnums.AlphaNode) {
final AlphaNode alphaNode = (AlphaNode) sink;
final AlphaNodeFieldConstraint fieldConstraint = alphaNode.getConstraint();
if (fieldConstraint instanceof IndexableConstraint) {
final IndexableConstraint indexableConstraint = (IndexableConstraint) fieldConstraint;
final FieldValue value = indexableConstraint.getField();
if (isHashable(indexableConstraint)) {
final InternalReadAccessor fieldAccessor = indexableConstraint.getFieldExtractor();
final int index = fieldAccessor.getIndex();
final FieldIndex fieldIndex = unregisterFieldIndex(index);
if (fieldIndex.isHashed()) {
HashKey hashKey = new HashKey(index, value, fieldAccessor);
this.hashedSinkMap.remove(hashKey);
if (fieldIndex.getCount() <= this.alphaNodeHashingThreshold - 1) {
// we have less than three so unhash
unHashSinks(fieldIndex);
}
} else {
this.hashableSinks.remove(alphaNode);
}
if (this.hashableSinks != null && this.hashableSinks.isEmpty()) {
this.hashableSinks = null;
}
return size() == 1 ? new SingleObjectSinkAdapter(getSinks()[0]) : this;
}
}
}
this.otherSinks.remove((ObjectSinkNode) sink);
if (this.otherSinks.isEmpty()) {
this.otherSinks = null;
}
return size() == 1 ? new SingleObjectSinkAdapter(getSinks()[0]) : this;
}
use of org.drools.core.spi.AlphaNodeFieldConstraint in project drools by kiegroup.
the class CompositeObjectSinkAdapter method hashSinks.
void hashSinks(final FieldIndex fieldIndex) {
if (this.hashedSinkMap == null) {
this.hashedSinkMap = new ObjectHashMap();
}
final int index = fieldIndex.getIndex();
final InternalReadAccessor fieldReader = fieldIndex.getFieldExtractor();
ObjectSinkNode currentSink = this.hashableSinks.getFirst();
while (currentSink != null) {
final AlphaNode alphaNode = (AlphaNode) currentSink;
final AlphaNodeFieldConstraint fieldConstraint = alphaNode.getConstraint();
final IndexableConstraint indexableConstraint = (IndexableConstraint) fieldConstraint;
// position to the next sink now because alphaNode may be removed if the index is equal. If we were to do this
// afterwards, currentSink.nextNode would be null
currentSink = currentSink.getNextObjectSinkNode();
// the right field index
if (index == indexableConstraint.getFieldExtractor().getIndex()) {
final FieldValue value = indexableConstraint.getField();
this.hashedSinkMap.put(new HashKey(index, value, fieldReader), alphaNode);
// remove the alpha from the possible candidates of hashable sinks since it is now hashed
hashableSinks.remove(alphaNode);
}
}
if (this.hashableSinks.isEmpty()) {
this.hashableSinks = null;
}
fieldIndex.setHashed(true);
}
Aggregations