I think there might be a conceptual problem here. Stateless sessions are supposed to take a snapshot of facts (and/or events) and run all rules for them and dispose the session. Since it is a snapshot, there is no concept of time flow during the execution and so it can only run in the equivalent of CLOUD mode for stateful sessions. That is why no session clock is provided for stateless sessions.

   In order to use the SessionClock, one needs to use a stateful session configured in STREAM mode.

   I believe we can add features in the future like the ability to run a session with a given reference time, even if it does not involve time flow, but that is not there. Also, since date-effective and date-expiration are really old features, from the drools 2-3 versions, and they have quite a number of limitations, you are probably better using "enabled" expressions than using those attributes.


2011/9/29 Mark Proctor <mproctor@codehaus.org>
Look at the interval timer test here from line 254 onwards, and the subsequent cron tests:

On 13/10/2009 00:32, Ben Scott wrote:

Note: This e-mail is subject to the disclaimer contained at the bottom of this message.

I'm wanting to use the date-effective and date-expiry rule metadata to add date specific rule variants within my app. To test these I was planning on using the pseudo clock and setting the expected date prior to executing the rules within a StatelessKnowledgeSession. I can set the clock easily enough, but can't understand why the getSessionClock() method is missing? It's on the StatefulKnowledgeSession, but not on the Stateless.
I'm initialising the session like this:
SessionConfiguration sessionConfiguration = new SessionConfiguration();
sessionConfiguration.setClockType( ClockType.PSEUDO_CLOCK );
StatelessKnowledgeSession session = _testKnowledgeBase.newStatelessKnowledgeSession(sessionConfiguration);
The only thing I could think of to set the pseudo clock was to write a command something like:
private static class SetPseudoClockCommand implements org.drools.process.command.Command<Boolean> {
public Boolean execute(ReteooWorkingMemory session) {
// Set the clock to the current date
pseudoSessionClock.advanceTime(new DateTime().getMillis(), TimeUnit.MILLISECONDS);
// Add a couple of days
pseudoSessionClock.advanceTime(2, TimeUnit.DAYS);
return true;
But this doesn't appear to take any effect whilst rules are running.
Is there another way to get programmatic access to the session clock, or some better way of changing the underlying date prior to rule execution?

The information transmitted in this message and its attachments (if any) is intended only for the person or entity to which it is addressed.

The message may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information, by persons or entities other than the intended recipient is prohibited.

If you have received this in error, please contact the sender and delete this e-mail and associated material from any computer.

The intended recipient of this e-mail may only use, reproduce, disclose or distribute the information contained in this e-mail and any attached files, with the permission of the sender.

This message has been scanned for viruses with Symantec Scan Engine and cleared by MailMarshal.

rules-users mailing list

rules-users mailing list

  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com