Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequential Logic #5916

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import org.drools.base.common.NetworkNode;
import org.drools.core.reteoo.AlphaNode;
import org.drools.core.reteoo.Sink;
import org.drools.base.reteoo.Sink;
import org.drools.base.rule.ContextEntry;
import org.drools.core.util.index.AlphaRangeIndex;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.NameExpr;
import com.github.javaparser.ast.stmt.Statement;
import org.drools.core.reteoo.Sink;
import org.drools.base.reteoo.NodeTypeEnums;
import org.drools.base.reteoo.Sink;

import static com.github.javaparser.StaticJavaParser.parseStatement;
import static com.github.javaparser.ast.NodeList.nodeList;
Expand All @@ -40,7 +41,11 @@ protected Statement propagateMethod(Sink sink) {
if (sinkCanBeInlined(sink)) {
assertStatement = parseStatement("ALPHATERMINALNODE.collectObject();");
} else {
assertStatement = parseStatement("ALPHATERMINALNODE.assertObject(handle, context, wm);");
String g = "";
if (NodeTypeEnums.isBetaNode(sink)) {
g = "getRightInput().";
}
assertStatement = parseStatement("ALPHATERMINALNODE." + g + "assertObject(handle, context, wm);");
}
replaceNameExpr(assertStatement, "ALPHATERMINALNODE", getVariableName(sink));
return assertStatement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ public boolean isEmpty() {
}

@Override
public void doLinkRiaNode(ReteEvaluator reteEvaluator) {
originalSinkPropagator.doLinkRiaNode(reteEvaluator);
public void doLinkSubnetwork(ReteEvaluator reteEvaluator) {
originalSinkPropagator.doLinkSubnetwork(reteEvaluator);
}

@Override
public void doUnlinkRiaNode(ReteEvaluator reteEvaluator) {
originalSinkPropagator.doUnlinkRiaNode(reteEvaluator);
public void doUnlinkSubnetwork(ReteEvaluator reteEvaluator) {
originalSinkPropagator.doUnlinkSubnetwork(reteEvaluator);
}

public abstract void init(Object... args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.drools.core.reteoo.AlphaNode;
import org.drools.core.reteoo.BetaNode;
import org.drools.core.reteoo.LeftInputAdapterNode;
import org.drools.core.reteoo.Sink;
import org.drools.base.reteoo.Sink;
import org.drools.core.reteoo.WindowNode;
import org.drools.base.rule.ContextEntry;
import org.drools.base.rule.IndexableConstraint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import com.github.javaparser.ast.type.VoidType;
import org.drools.base.common.NetworkNode;
import org.drools.core.reteoo.AlphaNode;
import org.drools.core.reteoo.Sink;
import org.drools.base.reteoo.Sink;

import static com.github.javaparser.StaticJavaParser.parseStatement;
import static com.github.javaparser.ast.NodeList.nodeList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.NameExpr;
import com.github.javaparser.ast.stmt.Statement;
import org.drools.core.reteoo.Sink;
import org.drools.base.reteoo.NodeTypeEnums;
import org.drools.base.reteoo.Sink;

import static com.github.javaparser.StaticJavaParser.parseStatement;
import static com.github.javaparser.ast.NodeList.nodeList;
Expand All @@ -40,8 +41,16 @@ protected Statement propagateMethod(Sink sink) {
if (sinkCanBeInlined(sink)) {
modifyStatement = parseStatement("ALPHATERMINALNODE.collectObject();");
} else {
modifyStatement = parseStatement("ALPHATERMINALNODE.modifyObject(handle, modifyPreviousTuples, context, wm);");
String g = "";
if (NodeTypeEnums.isBetaNode(sink)) {
g = "getRightInput().";
}

modifyStatement = parseStatement("ALPHATERMINALNODE." + g + "modifyObject(handle, modifyPreviousTuples, context, wm);");
}



replaceNameExpr(modifyStatement, "ALPHATERMINALNODE", getVariableName(sink));
return modifyStatement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.drools.core.reteoo.AlphaNode;
import org.drools.core.reteoo.BetaNode;
import org.drools.core.reteoo.RightInputAdapterNode;
import org.drools.core.reteoo.CompositeObjectSinkAdapter;
import org.drools.core.reteoo.CompositeObjectSinkAdapter.FieldIndex;
import org.drools.core.reteoo.CompositePartitionAwareObjectSinkAdapter;
Expand Down Expand Up @@ -201,8 +202,8 @@ private void traverseSink(ObjectSink sink, NetworkHandler handler) {
traversePropagator(alphaNode.getObjectSinkPropagator(), handler);

handler.endNonHashedAlphaNode(alphaNode);
} else if (NodeTypeEnums.isBetaNode( sink ) ) {
BetaNode betaNode = (BetaNode) sink;
} else if (NodeTypeEnums.isBetaRightNode( sink ) ) {
BetaNode betaNode = ((RightInputAdapterNode) sink).getBetaNode();

handler.startBetaNode(betaNode);
handler.endBetaNode(betaNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import org.drools.core.reteoo.LeftInputAdapterNode;
import org.drools.core.reteoo.ModifyPreviousTuples;
import org.drools.core.reteoo.ObjectTypeNode;
import org.drools.core.reteoo.Sink;
import org.drools.base.reteoo.Sink;
import org.drools.core.reteoo.WindowNode;
import org.drools.base.rule.IndexableConstraint;
import org.drools.core.common.PropagationContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import com.github.javaparser.ast.type.VoidType;
import org.drools.base.common.NetworkNode;
import org.drools.core.reteoo.AlphaNode;
import org.drools.core.reteoo.Sink;
import org.drools.base.reteoo.Sink;

import static com.github.javaparser.StaticJavaParser.parseExpression;
import static com.github.javaparser.StaticJavaParser.parseStatement;
Expand Down
30 changes: 30 additions & 0 deletions drools-base/src/main/java/org/drools/base/base/ValueResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

import org.drools.base.RuleBase;
import org.drools.base.rule.accessor.GlobalResolver;
import org.drools.base.phreak.PropagationEntry;
import org.drools.base.time.TimerService;
import org.kie.api.runtime.KieSessionConfiguration;

import java.util.function.Consumer;

public interface ValueResolver {

Expand All @@ -32,4 +37,29 @@ default Object getGlobal(String identifier) {
GlobalResolver getGlobalResolver();

RuleBase getRuleBase();

void addPropagation(PropagationEntry propagationEntry);

KieSessionConfiguration getKieSessionConfiguration();

default <T extends ValueResolver> T as(Class<T> t) {
return (T) this;
}

default void setWorkingMemoryActionListener(Consumer<PropagationEntry> listener) {
throw new UnsupportedOperationException();
}

default Consumer<PropagationEntry> getWorkingMemoryActionListener() {
return null;
}

default void onWorkingMemoryAction(PropagationEntry entry) {
Consumer<PropagationEntry> listener = getWorkingMemoryActionListener();
if (listener != null) {
listener.accept(entry);
}
}

TimerService getTimerService();
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public interface NetworkNode extends Serializable {

NetworkNode[] getSinks();

default boolean isRightInputIsRiaNode() {
default boolean inputIsTupleToObjectNode() {
// not ideal, but this was here to allow NetworkNode to be in drools-base
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.drools.base.base.SalienceInteger;
import org.drools.base.base.ValueResolver;
import org.drools.base.reteoo.BaseTuple;
import org.drools.base.reteoo.sequencing.Sequence;
import org.drools.base.rule.ConsequenceMetaData;
import org.drools.base.rule.Declaration;
import org.drools.base.rule.Dialectable;
Expand All @@ -51,7 +52,7 @@
import org.drools.base.rule.accessor.Salience;
import org.drools.base.rule.accessor.Wireable;
import org.drools.base.rule.consequence.Consequence;
import org.drools.base.time.impl.Timer;
import org.drools.base.time.Timer;
import org.drools.util.StringUtils;
import org.kie.api.definition.rule.Query;
import org.kie.api.io.Resource;
Expand Down Expand Up @@ -545,6 +546,11 @@ public void addPattern(final RuleConditionElement element) {
this.lhsRoot.addChild( element );
}

public void addSequence(final Sequence element) {
this.dirty = true;
this.lhsRoot.addChild( element );
}

/**
* Retrieve the <code>List</code> of <code>Conditions</code> for this
* rule.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.drools.base.phreak;

import org.drools.base.base.ValueResolver;

public interface PropagationEntry<T extends ValueResolver> {

default void execute(T t) {
internalExecute(t);
t.onWorkingMemoryAction(this);
}

void internalExecute(T t);

PropagationEntry getNext();
void setNext(PropagationEntry next);

boolean requiresImmediateFlushing();

boolean isCalledFromRHS();

boolean isPartitionSplittable();
PropagationEntry getSplitForPartition(int partitionNr);

boolean defersExpiration();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.drools.base.phreak.actions;

import org.drools.base.base.ValueResolver;
import org.drools.base.phreak.PropagationEntry;

public abstract class AbstractPropagationEntry<T extends ValueResolver> implements PropagationEntry<T> {
protected PropagationEntry next;

public void setNext(PropagationEntry next) {
this.next = next;
}

public PropagationEntry getNext() {
return next;
}

@Override
public boolean requiresImmediateFlushing() {
return false;
}

@Override
public boolean isCalledFromRHS() {
return false;
}

@Override
public boolean isPartitionSplittable() {
return false;
}

@Override
public boolean defersExpiration() {
return false;
}

@Override
public PropagationEntry getSplitForPartition(int partitionNr) {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,8 @@ public interface BaseTerminalNode extends NetworkNode {

void initInferredMask();

BitMask getDeclaredMask();

void setDeclaredMask(BitMask mask);

BitMask getInferredMask();

void setInferredMask(BitMask mask);

BitMask getNegativeMask();

void setNegativeMask(BitMask mask);

RuleImpl getRule();

GroupElement getSubRule();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.drools.base.reteoo;

import org.drools.base.base.ValueResolver;
import org.drools.base.rule.constraint.AlphaNodeFieldConstraint;
import org.drools.base.util.AbstractLinkedListNode;
import org.drools.base.util.LinkedList;
import org.kie.api.runtime.rule.FactHandle;

public class DynamicFilter extends AbstractLinkedListNode<DynamicFilter> {
private AlphaNodeFieldConstraint constraint;
private LinkedList<SignalAdapter> signalAdapters;
private int activeFilterIndex;

public DynamicFilter(DynamicFilterProto proto) {
this.constraint = proto.getConstraint();
this.activeFilterIndex = proto.getFilterIndex();
this.signalAdapters = new LinkedList<>();
}

public AlphaNodeFieldConstraint getConstraint() {
return constraint;
}

public int getActiveFilterIndex() {
return activeFilterIndex;
}

public void addSignalAdapter(SignalAdapter signalAdapter) {
signalAdapters.add(signalAdapter);
}

public void removeSignalAdapter(SignalAdapter signalAdapter) {
signalAdapters.remove(signalAdapter);
}

public LinkedList<SignalAdapter> getSignalAdapters() {
return signalAdapters;
}

public void assertObject(final FactHandle factHandle,
final ValueResolver valueResolver) {
System.out.println("true : " + factHandle.getObject());

if (constraint.isAllowed(factHandle, valueResolver)) {
for (SignalAdapter signal = signalAdapters.getFirst(); signal != null; signal = signal.getNext()) {
signal.receive(valueResolver, factHandle);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.drools.base.reteoo;

import org.drools.base.rule.constraint.AlphaNodeFieldConstraint;

public class DynamicFilterProto {
private AlphaNodeFieldConstraint constraint;
private int filterIndex;

public DynamicFilterProto(AlphaNodeFieldConstraint constraint, int filterIndex) {
this.constraint = constraint;
this.filterIndex = filterIndex;
}

public AlphaNodeFieldConstraint getConstraint() {
return constraint;
}

public int getFilterIndex() {
return filterIndex;
}
}
Loading
Loading