use of org.kie.internal.command.RegistryContext in project drools by kiegroup.
the class NewContextCommand method execute.
@Override
public Void execute(Context context) {
Context returned = ((RegistryContext) context).getContextManager().createContext(name);
((RequestContextImpl) context).setApplicationContext(returned);
return null;
}
use of org.kie.internal.command.RegistryContext in project drools by kiegroup.
the class StatelessKnowledgeSessionImpl method execute.
public <T> T execute(Command<T> command) {
StatefulKnowledgeSession ksession = newWorkingMemory();
RegistryContext context = new ContextImpl().register(KieSession.class, ksession);
try {
if (command instanceof BatchExecutionCommand) {
context.register(ExecutionResultImpl.class, new ExecutionResultImpl());
}
((StatefulKnowledgeSessionImpl) ksession).startBatchExecution();
Object o = ((ExecutableCommand) command).execute(context);
// did the user take control of fireAllRules, if not we will auto execute
boolean autoFireAllRules = true;
if (command instanceof FireAllRulesCommand) {
autoFireAllRules = false;
} else if (command instanceof BatchExecutionCommandImpl) {
for (Command nestedCmd : ((BatchExecutionCommandImpl) command).getCommands()) {
if (nestedCmd instanceof FireAllRulesCommand) {
autoFireAllRules = false;
break;
}
}
}
if (autoFireAllRules) {
ksession.fireAllRules();
}
if (command instanceof BatchExecutionCommand) {
return (T) context.lookup(ExecutionResultImpl.class);
} else {
return (T) o;
}
} finally {
((StatefulKnowledgeSessionImpl) ksession).endBatchExecution();
dispose(ksession);
}
}
use of org.kie.internal.command.RegistryContext in project drools by kiegroup.
the class AddCoverageListenerCommand method execute.
@Override
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
ksession.addEventListener(coverageAgendaListener);
return null;
}
use of org.kie.internal.command.RegistryContext in project drools by kiegroup.
the class RuleStatefulScenarioExecutableBuilder method run.
@Override
public Map<String, Object> run() {
Objects.requireNonNull(executableBuilder, "Executable builder is null, please invoke create(KieContainer, )");
CoverageAgendaListener coverageAgendaListener = new CoverageAgendaListener();
kieSessionFluent.addCommand(new AddCoverageListenerCommand(coverageAgendaListener));
kieSessionFluent.addCommand(context -> {
KieSession kieSession = ((RegistryContext) context).lookup(KieSession.class);
return getAvailableRules(kieSession.getKieBase(), agendaGroupName);
}).out(RULES_AVAILABLE);
kieSessionFluent.fireAllRules();
internalConditions.values().forEach(factToCheck -> kieSessionFluent.addCommand(new ValidateFactCommand(factToCheck)));
kieSessionFluent.dispose().end();
RequestContext execute = createExecutableRunner().execute(executableBuilder.getExecutable());
Map<String, Object> toReturn = new HashMap<>(execute.getOutputs());
toReturn.put(COVERAGE_LISTENER, coverageAgendaListener);
return toReturn;
}
use of org.kie.internal.command.RegistryContext in project drools by kiegroup.
the class ModifyCommand method execute.
public Object execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
EntryPoint wmep = ksession.getEntryPoint(factHandle.getEntryPointName());
Object object = wmep.getObject(this.factHandle);
CoreComponentsBuilder.get().getMVELExecutor().eval(getMvelExpr(), object);
wmep.update(factHandle, object);
return object;
}
Aggregations