droolsjbpm-knowledge/kie-api/src/main/java/org/kie/api$ vi runtime/rule/StatelessRuleSession.java
public interface StatelessRuleSession {
/**
* Execute a StatelessKieSession inserting just a single object. If a collection (or any other Iterable) or an array is used here, it will be inserted as-is,
* It will not be iterated and its internal elements inserted.
*
* @param object
*/
void execute(Object object);
/**
* Execute a StatelessKieSession, iterate the Iterable inserting each of its elements. If you have an array, use the Arrays.asList(...) method
* to make that array Iterable.
* @param objects
*/
void execute(Iterable objects);
}
droolsjbpm-knowledge/kie-api/src/main/java/org/kie/api$ vi runtime/StatelessKieSession.java
public interface StatelessKieSession
extends
StatelessRuleSession,
StatelessProcessSession,
CommandExecutor,
KieRuntimeEventManager
drools/drools-core/src/main/java/org/drools/core$ vi impl/StatelessKnowledgeSessionImpl.java
public class StatelessKnowledgeSessionImpl extends AbstractRuntime
implements
StatelessKnowledgeSession,
StatelessKieSession {
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);
}
}
public void execute(Object object) {
StatefulKnowledgeSession ksession = newWorkingMemory();
try {
ksession.insert( object );
ksession.fireAllRules();
} finally {
dispose(ksession);
}
}
public void execute(Iterable objects) {
StatefulKnowledgeSession ksession = newWorkingMemory();
try {
for ( Object object : objects ) {
ksession.insert( object );
}
ksession.fireAllRules();
} finally {
dispose(ksession);
}
}
protected void dispose(StatefulKnowledgeSession ksession) {
ksession.dispose();
}
drools/drools-core/src/main/java/org/drools/core$ vi impl/StatefulKnowledgeSessionImpl.java
public class StatefulKnowledgeSessionImpl extends AbstractRuntime
implements
StatefulKnowledgeSession,
WorkingMemoryEntryPoint,
InternalKnowledgeRuntime,
KieSession,
KieRuntimeEventManager,
InternalWorkingMemoryActions,
EventSupport,
RuleEventManager,
ProcessEventManager,
CorrelationAwareProcessRuntime,
Externalizable {
public void dispose() {
if (!agenda.dispose(this)) {
return;
}
if (logger != null) {
try {
logger.close();
} catch (Exception e) { /* the logger was already closed, swallow */ }
}
for (WorkingMemoryEntryPoint ep : this.entryPoints.values()) {
ep.dispose();
}
this.ruleRuntimeEventSupport.clear();
this.ruleEventListenerSupport.clear();
this.agendaEventSupport.clear();
for (KieBaseEventListener listener : kieBaseEventListeners) {
this.kBase.removeEventListener(listener);
}
if (processRuntime != null) {
this.processRuntime.dispose();
}
if (timerService != null) {
this.timerService.shutdown();
}
if (this.workItemManager != null) {
((org.drools.core.process.instance.WorkItemManager)this.workItemManager).dispose();
}
this.kBase.disposeStatefulSession( this );
if (this.mbeanRegistered.get()) {
DroolsManagementAgent.getInstance().unregisterKnowledgeSessionUnderName(mbeanRegisteredCBSKey, this);
}
}
drools/drools-core/src/main/java/org/drools/core$ vi WorkingMemoryEntryPoint.java
public interface WorkingMemoryEntryPoint extends EntryPoint {
common/InternalWorkingMemoryEntryPoint.java:
public interface InternalWorkingMemoryEntryPoint extends WorkingMemoryEntryPoint
WorkingMemory.java:
public interface WorkingMemory extends WorkingMemoryEventManager, WorkingMemoryEntryPoint
drools/drools-core/src/main/java/org/drools/core$ vi common/InternalWorkingMemory.java
public interface InternalWorkingMemory
extends WorkingMemory, WorkingMemoryEntryPoint, EventSupport {
drools/drools-core/src/main/java/org/drools/core$ vi common/NamedEntryPoint.java
public class NamedEntryPoint
implements
InternalWorkingMemoryEntryPoint,
WorkingMemoryEntryPoint,
PropertyChangeListener {
public void dispose() {
if( dynamicFacts != null ) {
// first we check for facts that were inserted into the working memory
// using the old API and setting a per instance dynamic flag and remove the
// session from the listeners list in the bean
for( InternalFactHandle handle : dynamicFacts ) {
removePropertyChangeListener( handle, false );
}
dynamicFacts = null;
}
for( ObjectTypeConf conf : this.typeConfReg.values() ) {
// then, we check if any of the object types were configured using the
// @propertyChangeSupport annotation, and clean them up
if( conf.isDynamic() && conf.isSupportsPropertyChangeListeners() ) {
// it is enough to iterate the facts on the concrete object type nodes
// only, as the facts will always be in their concrete object type nodes
// even if they were also asserted into higher level OTNs as well
ObjectTypeNode otn = conf.getConcreteObjectTypeNode();
if (otn != null) {
Iterator<InternalFactHandle> it = this.getInternalWorkingMemory().getNodeMemory(otn).iterator();
while (it.hasNext()) {
removePropertyChangeListener(it.next(), false);
}
}
}
}
}
drools/drools-core/src/main/java/org/drools/core$ vi command/impl/CommandBasedStatefulKnowledgeSession.java
public class CommandBasedStatefulKnowledgeSession extends AbstractRuntime
implements
StatefulKnowledgeSession, CorrelationAwareProcessRuntime {
private ExecutableRunner runner;
private transient WorkItemManager workItemManager;
private transient Agenda agenda;
public CommandBasedStatefulKnowledgeSession(ExecutableRunner runner ) {
this.runner = runner;
}
public void dispose() {
runner.execute( new DisposeCommand() );
}
runtime/InternalLocalRunner.java:
public interface InternalLocalRunner extends ExecutableRunner<RequestContext>
runtime/ChainableRunner.java:
public interface ChainableRunner extends InternalLocalRunner
command/SingleSessionCommandService.java:
public interface SingleSessionCommandService extends InternalLocalRunner