0

Hope you can help me on this since I’m new on drools. Currently I’m working with a stateful session deployed in Kie server, my problem here is that I don’t want to store all the responses from facts and just keep the value of the global variables, that’s the reason I want to use stateful session, to store the global variables but not the responses because leak of memory

Thank you!

Edit

I'm adding the validation that i'm implementing in drools

Guided Decision table

I need to keep the value of that global variable as stateful session because is a big variable, so I can't send the value of that global in every request.

Jairo
  • 1
  • 1
  • Globals are like static variables. You set them from outside of the rules, so you'll have the value there already. – Roddy of the Frozen Peas Nov 11 '21 at 16:11
  • not to have memory leak you need to agree on fact lifecycle and either delete them manually or declare as `@Event`. Facts are objects in memory, what do you mean by 'responses from facts'? – Mike Nov 11 '21 at 17:18
  • Sounds like you might actually want to be using stateless sessions, if the only thing you care about is preserving globals (which you really shouldn't be relying on, generally speaking.) But it's rather unclear what you actually want -- can you post an example of a rule that shows the sort of stuff you're working with and which values you actually want to preserve (or don't want to preserve)? – Roddy of the Frozen Peas Nov 11 '21 at 17:50
  • @RoddyoftheFrozenPeas I added the image, and I also checked the stateless sessions, but the problem in that case is that i have to send the value of the global variable in every request, because is not stored between requests – Jairo Nov 11 '21 at 19:00
  • @Mike When i say 'responses from facts' i mean that when i send a request to drools, and the fact (object) is inserted, i get a response with an object like 'execution-results' and it has values that are being stored – Jairo Nov 11 '21 at 19:05
  • 'values that are being stored' in the drools working memory and you want to cleanup it? If so you can add results to you global collection and delete/retract the fact from drools knowledge base. Will it work for you? – Mike Nov 11 '21 at 19:09
  • @Mike Yes! that would work for me, how can i do that? – Jairo Nov 11 '21 at 19:47

1 Answers1

0

Example of the rule which collect heartbeats that are not followed by another heartbeat on time

declare Heartbeat @role (event) end

global java.io.PrintStream stdout
global java.util.List heartbeats

rule "Sound the Alarm"
when
    $h: Heartbeat() from entry-point "MonitoringStream"
    not(Heartbeat(this != $h, this after[0s,10s] $h) from entry-point "MonitoringStream")
then
    stdout.println('No heartbeat after ' + $h)
    heartbeats.add($h) // collect your results
    // heartbeats will be automatically retracted from drools knowledge session because they are declared as events
end
Mike
  • 20,010
  • 25
  • 97
  • 140