Nicozan-Blog

Knowledge Seeking

Drools Fusion – TimeStamp Tips October 28, 2010

Filed under: Drools — nicozan @ 8:11 pm

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:


declare Event
@role(event)
@timestamp(timestamp.getTime())
end


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.

TESTING TIME…
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();
….

Advertisements
 

3 Responses to “Drools Fusion – TimeStamp Tips”

  1. MORGE Says:

    Hi,

    Your Drools fusion examples are very nice. That’s a pity you provide only screenshot. I have recode them. If you are interested in, I can provide the source code.

    It should be nice if you add more examples, in particular on interval. May be promotional periods could be nice example.

    Best,

    Maxime.

    • nicozan Says:

      Hi

      Thanks for your interest in drools and my blog, I promise that I’ll be posting new examples for particular cases related to intervals of time.

      Regards,

      Nicolas

  2. 郭溶質 Says:

    I saw your article about Drools fusion examples are very great!!

    I have some questions, in your TimeStamp example maybe need to modify the Sale class in your fusion example1 , I try it for many days, but I fails..

    Would you give me some ideas about how to execute your TimeStamp example? Thank you very much!!

    Best Regards,

    Tony


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s