[rules-users] Drools 5 PseudoClock with StatelessKnowledgeSession

Mark Proctor mproctor at codehaus.org
Thu Sep 29 20:52:27 EDT 2011


Look at the interval timer test here from line 254 onwards, and the 
subsequent cron tests:
https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/integrationtests/TimerAndCalendarTest.java#L254


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?
> Ben.
> ------------------------------------------------------------------------
>
> 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 at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110930/1e6d06b0/attachment.html 


More information about the rules-users mailing list