StatelessKnowledgeSession provides a convenience API, wrapping StatefulKnowledgeSession. It avoids the need to
call dispose(). Stateless sessions do not support
iterative invocations, the act of calling execute(...) is a single
shot method that will internally instantiate a StatefulKnowledgeSession, add all the user data and execute user commands, call fireAllRules, and then
call dispose(). While the main way to work with this class is via the BatchExecution Command as supported by the CommandExecutor interface,
two convenience methods are provided for when simple object insertion is all that's required.

Simple example showing a stateless session executing for a given collection of java objects using the convenience api. It will iterate the collection inserting
each element in turn

Note if you wanted to insert the collection itself, and not the iterate and insert the elements, then CommandFactory.newInsert( collection ) would do the job.

The CommandFactory details the supported commands, all of which can be marshalled using XStream and the BatchExecutionHelper. BatchExecutionHelper provides details
on the XML format as well as how to use Drools Pipeline to automate the marshalling of BatchExecution and ExecutionResults.

StatelessKnowledgeSessions support globals, scoped in a number of ways. I'll cover the non-command way first,
as commands are scoped to a specific execution call. Globals can be resolved in three ways. The StatelessKnowledgeSession
supports getGlobals(), which returns a Globals instance. These globals are shared for ALL execution calls, so be especially careful of mutable
globals in these cases - as often execution calls can be executing simultaneously in different threads. Globals also supports a delegate, which
adds a second way of resolving globals. Calling of setGlobal(String, Object) will actually be set on an internal Collection, identifiers in this internal
Collection will have priority over supplied delegate, if one is added. If an identifier cannot be found in
the internal Collection, it will then check the delegate Globals, if one has been set.

Code snippet for setting a session scoped global:

StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();
ksession.setGlobal( "hbnSession", hibernateSession ); // sets a global hibernate session, that can be used for DB interactions in the rules.
ksession.execute( collection ); // this will now execute and will be able to resolve the "hbnSession" identifier.

The third way is execution scopped globals using the CommandExecutor and SetGlobal Commands: