{
final Map<String,Object> globals = ruleInfo.getGlobals();
final List<Object> objectList = ruleInfo.getDefaultFacts();
final String sid;
final StatelessKnowledgeSession head = statelessSessions.poll();
final StatelessKnowledgeSession statelessSession;
if (head != null)
{
statelessSession = head;
sid = getId(statelessSession);
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("reusing old stateles session [" + sid + "]");
}
}
else
{
statelessSession = ruleBase.newStatelessKnowledgeSession();
sid = getId(statelessSession);
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("created new stateless session [" + sid + "]");
}
}
RulesContext.clearContext();
try
{
final List<Object> facts = new ArrayList<Object>();
if (LOGGER.isTraceEnabled())
{
LOGGER.trace("adding Message into fact list for stateless session [" + sid + "]");
}
facts.add(message);
if (objectList != null)
{
if (LOGGER.isTraceEnabled())
{
LOGGER.trace("adding default facts into fact list for stateless session [" + sid + "]");
}
facts.addAll(objectList);
}
KnowledgeRuntimeLogger statelessRuntimeLogger = getRuntimeLogger(ruleInfo, statelessSession);
if (statelessRuntimeLogger != null && LOGGER.isDebugEnabled())
{
LOGGER.debug("created new runtime logger [" + getId(statelessRuntimeLogger) + "]");
}
if (LOGGER.isTraceEnabled())
{
LOGGER.trace("setting globals delegate for stateless session [" + sid + "]");
}
statelessSession.getGlobals().setDelegate(new StatelessGlobals(globals));
try
{
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("calling execute(Iterable) on stateless session [" + sid + "]");
}
statelessSession.execute(facts);
}
finally
{
statelessSession.getGlobals().setDelegate(null);
if (statelessRuntimeLogger != null)
{
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("calling close() on runtime logger [" + getId(statelessRuntimeLogger) + "]");