6.10. Memory management for events
In stream mode, the decision engine uses automatic memory management to maintain events that are stored in KIE sessions. The decision engine can retract from a KIE session any events that no longer match any rule due to their temporal constraints and release any resources held by the retracted events.
The decision engine uses either explicit or inferred expiration to retract outdated events:
Explicit expiration: The decision engine removes events that are explicitly set to expire in rules that declare the
@expirestag:DRL rule snippet with explicit expiration
declare StockPoint @expires( 30m ) endThis example rule sets any
StockPointevents to expire after 30 minutes and to be removed from the KIE session if no other rules use the events.Inferred expiration: The decision engine can calculate the expiration offset for a given event implicitly by analyzing the temporal constraints in the rules:
DRL rule with temporal constraints
rule "Correlate orders" when $bo : BuyOrder($id : id) $ae : AckOrder(id == $id, this after[0,10s] $bo) then // Perform an action. endFor this example rule, the decision engine automatically calculates that whenever a
BuyOrderevent occurs, the decision engine needs to store the event for up to 10 seconds and wait for the matchingAckOrderevent. After 10 seconds, the decision engine infers the expiration and removes the event from the KIE session. AnAckOrderevent can only match an existingBuyOrderevent, so the decision engine infers the expiration if no match occurs and removes the event immediately.The decision engine analyzes the entire KIE base to find the offset for every event type and to ensure that no other rules use the events that are pending removal. Whenever an implicit expiration clashes with an explicit expiration value, the decision engine uses the greater time frame of the two to store the event longer.