Question

I declared the event by .drl syntax:

declare Event
  @role(event)
  @timestamp(time)
time : long 
end

So I can get the "time" field that's set automatically.

In my java rule I want to retrieve "time":

when

  Event($tsmp:time)

then
  System.out.println($tsmp);

end

I always print "0", though I advance the pseudo clock

session.getClock().advanceTime(10, TimeUnit.MILLISECONDS);

(if after the advance I try to retrieve the currentTime from the clock, it returns 10, but the print into rule always returns 0, as if the time stamp was not updated).

Was it helpful?

Solution

If you use

@timestamp(time) // this class member contains the timestamp

in a declare, it informs the compiler that your field called time contains the time. It does not imply that the Engine should set the time - you'll have to do this prior to the insert. You may, of course, use the pseudo-clock to obtain a suitable time.

Only by omitting this from the declare you'll achieve the automatic setting of the timestamp in a field managed entirely by Drools.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top