Drools Fusion. Update @timestamp. Why can't I retrieve the correct value from timestamp field?

StackOverflow https://stackoverflow.com/questions/21287605

  •  01-10-2022
  •  | 
  •  

Domanda

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).

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top