use of org.drools.core.rule.AsyncReceive in project drools by kiegroup.
the class AsyncReceiveBuilder method build.
@Override
public void build(BuildContext context, BuildUtils utils, RuleConditionElement rce) {
final AsyncReceive receive = (AsyncReceive) rce;
context.pushRuleComponent(receive);
@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];
context.setTupleSource(utils.attachNode(context, CoreComponentFactory.get().getNodeFactoryService().buildAsyncReceiveNode(context.getNextNodeId(), receive, context.getTupleSource(), alphaNodeFieldConstraints, betaConstraints, context)));
context.setAlphaConstraints(null);
context.setBetaconstraints(null);
context.popRuleComponent();
}
use of org.drools.core.rule.AsyncReceive in project drools by kiegroup.
the class KiePackagesBuilder method addPatternForVariable.
private Pattern addPatternForVariable(RuleContext ctx, GroupElement group, Variable patternVariable, Condition.Type type) {
Pattern pattern = null;
// If the variable is already bound to the result of previous accumulate result pattern, then find it.
if (patternVariable instanceof org.drools.model.Declaration) {
org.drools.model.Declaration decl = (org.drools.model.Declaration) patternVariable;
if (decl.getSource() == null) {
Accumulate accSource = ctx.getAccumulateSource(patternVariable);
if (accSource != null) {
for (RuleConditionElement element : group.getChildren()) {
if (element instanceof Pattern && ((Pattern) element).getSource() == accSource) {
pattern = (Pattern) element;
break;
}
}
}
}
}
PatternSource priorSource = null;
if (pattern != null && type == Condition.Type.ACCUMULATE) {
// so it would be potentially tricky if this was a multi var, with multiple bindings.
if (pattern.getSource() instanceof SingleAccumulate) {
group.getChildren().remove(pattern);
priorSource = pattern.getSource();
pattern = null;
}
}
if (pattern == null) {
pattern = new Pattern(ctx.getNextPatternIndex(), // tupleIndex will be set by ReteooBuilder
0, // tupleIndex will be set by ReteooBuilder
0, getObjectType(patternVariable), patternVariable.getName(), true);
pattern.setSource(priorSource);
}
if (patternVariable instanceof org.drools.model.Declaration) {
org.drools.model.Declaration decl = (org.drools.model.Declaration) patternVariable;
if (decl.getSource() != null) {
if (decl.getSource() instanceof EntryPoint) {
pattern.setSource(new EntryPointId(((EntryPoint) decl.getSource()).getName()));
} else if (decl.getSource() instanceof WindowReference) {
WindowReference<?> window = (WindowReference) decl.getSource();
if (!ctx.getPkg().getWindowDeclarations().containsKey(window.getName())) {
createWindowReference(ctx, window);
}
pattern.setSource(new org.drools.core.rule.WindowReference(window.getName()));
} else if (decl.getSource() instanceof From) {
pattern.setSource(buildFrom(ctx, pattern, (From) decl.getSource()));
} else if (decl.getSource() instanceof UnitData) {
UnitData unitData = (UnitData) decl.getSource();
pattern.setSource(new EntryPointId(ctx.getRule().getRuleUnitClassName() + "." + unitData.getName()));
} else {
throw new UnsupportedOperationException("Unknown source: " + decl.getSource());
}
}
if (decl.getWindow() != null) {
pattern.addBehavior(createWindow(decl.getWindow()));
ctx.setNeedStreamMode();
}
} else if (patternVariable instanceof Exchange) {
if (type == Condition.Type.SENDER) {
Function0 supplier = ((Exchange) patternVariable).getMessageSupplier();
DataProvider provider = new LambdaDataProvider(x -> supplier.apply(), false);
pattern.setSource(new AsyncSend(pattern, patternVariable.getName(), provider));
} else if (type == Condition.Type.RECEIVER) {
pattern.setSource(new AsyncReceive(pattern, patternVariable.getName()));
} else {
throw new UnsupportedOperationException();
}
}
ctx.registerPattern(patternVariable, pattern);
return pattern;
}
Aggregations