use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.
the class GetContextCommand method execute.
@Override
public Void execute(Context context) {
Context returned = ((RegistryContext) context).getContextManager().getContext(name);
((RequestContextImpl) context).setApplicationContext(returned);
return null;
}
use of org.drools.core.command.impl.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.drools.core.command.impl.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) {
((RegistryContext) 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) ((RegistryContext) context).lookup(ExecutionResultImpl.class);
} else {
return (T) o;
}
} finally {
((StatefulKnowledgeSessionImpl) ksession).endBatchExecution();
dispose(ksession);
}
}
use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.
the class UpdateInEntryPointCommand method execute.
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
EntryPoint ep = ksession.getEntryPoint(entryPoint);
if (modifiedProperties != null) {
ep.update(handle, object, modifiedProperties);
} else {
ep.update(handle, object);
}
return null;
}
use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.
the class GetFactHandlesInEntryPointCommand method execute.
public Collection<FactHandle> execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
EntryPoint ep = ksession.getEntryPoint(entryPoint);
Collection<FactHandle> disconnectedFactHandles = new ArrayList<FactHandle>();
if (filter != null) {
Collection<InternalFactHandle> factHandles = ep.getFactHandles(this.filter);
if (factHandles != null && disconnected) {
for (InternalFactHandle factHandle : factHandles) {
InternalFactHandle handle = factHandle.clone();
handle.disconnect();
disconnectedFactHandles.add(handle);
}
return disconnectedFactHandles;
} else {
return ksession.getFactHandles(this.filter);
}
} else {
Collection<InternalFactHandle> factHandles = ep.getFactHandles();
if (factHandles != null && disconnected) {
for (InternalFactHandle factHandle : factHandles) {
InternalFactHandle handle = factHandle.clone();
handle.disconnect();
disconnectedFactHandles.add(handle);
}
return disconnectedFactHandles;
} else {
return ksession.getFactHandles();
}
}
}
Aggregations