In this short post I`ll give you some tips to manage TimeStamps in Drools Fusion. You will probably use for timestamps, Date Objects or Long Types. The recommendation of this post is to use Long Types to represent timestamps.
If you are already using in your Drools Fusion implementation Date Objects, we recommend you to use the getTime() method that returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
Inside your DRL File you should declare the timestamp attribute, If it`s typed as Date in your Event Class, as follows:
Continuing with the tips, you should avoid instantiating the Date Object using the Date Constructor with parameters, except the one that receives a long type parameter representing the milliseconds since January 1, 1970, 00:00:00 GMT.
When you are implementing Drools Fusion and it`s the time to do some testing, the best thing you can do is use the PseudoClock implementation for the Session Clock, by configuring your StatefulKnowledgeSession with the “pseudo” option :
//Pseudo Clock Configuration
KnowledgeSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption( ClockTypeOption.get( “pseudo” ) );
//StatefulKnowledgeSession : Once we have our KnowledgeBase we create a Session to use it.
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(conf,null);
SessionPseudoClock clock = ksession.getSessionClock();