[rules-users] Marshalling/Unmarshalling of KieSession
Dear all, I've to questions concerning the marshalling and unmarshalling of KieSessions. First, is there any detailed documentation on the ObjectMarshallingStrategy interface? I am quite confused about the purpose of the write and read methods in the interface. In my implementation they are never called. Are they deprecated or under which circumstances are they called by the implementation? My second question is about the relationship of the KieSession, KieBase and the KieContainer in case of marshalling/unmarshalling. Assume that I create a KieSession based on a KieBase that is created from a KieContainer based on a release X. When marshalling this session, is there any information marshalled about which release this session is based upon? I am asking since when I unmarshall the session I want to ensure to initialize the unmarshaller based on a KieBase with the same release X as the marshalled version of the session. Do I have to store this information out of band or what's the recommended way to implement this? Thanks, Ingo ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Semantic of rules with not and coincide
Thanks a lot for clarification. My naive interpretation was that coincide with a is a combination of before and after. Best regards, Ingo On 2013-12-08 19:29, Wolfgang Laun wrote: > The "second" event hasn't happened at the time the first has > happened. > Thus, the negation (no Event coincides) *is* true. > > Perhaps it helps to read "not" as "does not exist" (which is what it > actually stands for) when looking at the rule. Indeed, there *is* no > coinciding event at the time the Event is inserted. > > -W > > > On 06/12/2013, IK81 wrote: >> Yes, this was my assumption and it is also what I want. I don't care >> if >> code C1 is reported before C2 or vice versa. They just have to >> happen >> within 1 minute. >> >> However, the semantic of coincide in combination with not is unclear >> to >> me. Why can the rule fire >> at event insertion time when the engine does not know if the second >> event will not happen without >> waiting for an additional minute? >> >> Ingo >> >> On 2013-12-06 09:22, Wolfgang Laun wrote: >>> Coincides is symmetric in time. You might want to use before or >>> after. >>> -W >>> >>> >>> On 06/12/2013, IK81 wrote: >>>> Dear all, >>>> >>>> I am currently stuck with a problem concerning the use of not and >>>> conincide. I want to analyze a stream of error code events from a >>>> set of >>>> devices and detect the following situations. Every event has a >>>> timestamp >>>> (long), a device id (String) and an error code (String). >>>> >>>> What I want to detect is the following >>>> - If I get two events, one with code C1 and one with C2 from a >>>> single >>>> device within 1 minute, it represents a special event combination. >>>> The >>>> order of their appearence is not relevant. >>>> - If I just get C1 (without the C2 within the time frame), just >>>> report >>>> C1 >>>> - If I just get C2 (without the C1 within the time frame), just >>>> report >>>> C2 >>>> >>>> >>>> I can successfully detect the special event combination with the >>>> following rule >>>> >>>> rule "Detect combination" >>>> when >>>> $e1 : Event ($d: device, code == "C1") >>>> $e2 : Event (device == $d, code == "C2", this coincides [1m] >>>> $e1) >>>> then >>>> ... do some output >>>> end >>>> >>>> >>>> Then I tried to implement the detection of C1 only as follows >>>> >>>> rule "Detect code C1" >>>> when >>>>$e1 : Event ($d: device, code == "C1") >>>>not ( $e2 : Event (device == $d, code == "C2", this coincides >>>> [1m] >>>> $e1)) >>>> then >>>> ... do some other output >>>> end >>>> >>>> My understanding of the rule is that it should fire, if I get the >>>> event >>>> with code C1 and there is no other event with error code C2 for >>>> the >>>> same >>>> device that happens within one minute before and after the C1 >>>> event. >>>> To >>>> my surprise, the rule fires immediately when I insert an event >>>> with >>>> error code C1. Shouldn't the implementation wait at least 1 minute >>>> to be >>>> sure that no C2 error event will be inserted? >>>> >>>> >>>> BTW this is how I insert the events in my test case: >>>> >>>>clock.advanceTime(70, TimeUnit.SECONDS); >>>>FactHandle handle1 = ksession.insert( new Event(65000, "A", "C1") >>>> ); >>>>ksession.fireAllRules(); >>>>clock.advanceTime( 10, TimeUnit.SECONDS ); >>>>FactHandle handle2 = ksession.insert( new Event(75000, "A", "C2") >>>> ); >>>>ksession.fireAllRules(); >>>>clock.advanceTime( 2, TimeUnit.SECONDS ); >>>> >>>> And this is mainly the output I get: >>>> >>>> detected code C1 @ 7 >>>>event id=44b895e5-7287-404b-8204-3de5690b2360 timestamp=65000 >>>> device=A code=C1 >>>> detected combination @ 8 >>>>event id=44b895e5-7287-404b-8204-3de5690b2360 timestamp=65000 >>>> device=A code=C1 >>>>event id=fc89715b-fc30-4b12-ab31-a3884dcd4886 timestamp=75000 >>>> device=A code=C2 >>>> >>>> Any ideas concerning an alternative solution are highly welcomed. >>>> >>>> Thanks, >>>> Ingo >>>> >>>> >>>> ___ >>>> rules-users mailing list >>>> rules-users@lists.jboss.org >>>> https://lists.jboss.org/mailman/listinfo/rules-users >>>> >>> ___ >>> rules-users mailing list >>> rules-users@lists.jboss.org >>> https://lists.jboss.org/mailman/listinfo/rules-users >> >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Semantic of rules with not and coincide
Yes, this was my assumption and it is also what I want. I don't care if code C1 is reported before C2 or vice versa. They just have to happen within 1 minute. However, the semantic of coincide in combination with not is unclear to me. Why can the rule fire at event insertion time when the engine does not know if the second event will not happen without waiting for an additional minute? Ingo On 2013-12-06 09:22, Wolfgang Laun wrote: > Coincides is symmetric in time. You might want to use before or > after. > -W > > > On 06/12/2013, IK81 wrote: >> Dear all, >> >> I am currently stuck with a problem concerning the use of not and >> conincide. I want to analyze a stream of error code events from a >> set of >> devices and detect the following situations. Every event has a >> timestamp >> (long), a device id (String) and an error code (String). >> >> What I want to detect is the following >> - If I get two events, one with code C1 and one with C2 from a >> single >> device within 1 minute, it represents a special event combination. >> The >> order of their appearence is not relevant. >> - If I just get C1 (without the C2 within the time frame), just >> report >> C1 >> - If I just get C2 (without the C1 within the time frame), just >> report >> C2 >> >> >> I can successfully detect the special event combination with the >> following rule >> >> rule "Detect combination" >> when >> $e1 : Event ($d: device, code == "C1") >> $e2 : Event (device == $d, code == "C2", this coincides [1m] >> $e1) >> then >> ... do some output >> end >> >> >> Then I tried to implement the detection of C1 only as follows >> >> rule "Detect code C1" >> when >> $e1 : Event ($d: device, code == "C1") >> not ( $e2 : Event (device == $d, code == "C2", this coincides [1m] >> $e1)) >> then >> ... do some other output >> end >> >> My understanding of the rule is that it should fire, if I get the >> event >> with code C1 and there is no other event with error code C2 for the >> same >> device that happens within one minute before and after the C1 event. >> To >> my surprise, the rule fires immediately when I insert an event with >> error code C1. Shouldn't the implementation wait at least 1 minute >> to be >> sure that no C2 error event will be inserted? >> >> >> BTW this is how I insert the events in my test case: >> >> clock.advanceTime(70, TimeUnit.SECONDS); >> FactHandle handle1 = ksession.insert( new Event(65000, "A", "C1") >> ); >> ksession.fireAllRules(); >> clock.advanceTime( 10, TimeUnit.SECONDS ); >> FactHandle handle2 = ksession.insert( new Event(75000, "A", "C2") >> ); >> ksession.fireAllRules(); >> clock.advanceTime( 2, TimeUnit.SECONDS ); >> >> And this is mainly the output I get: >> >> detected code C1 @ 7 >>event id=44b895e5-7287-404b-8204-3de5690b2360 timestamp=65000 >> device=A code=C1 >> detected combination @ 8 >>event id=44b895e5-7287-404b-8204-3de5690b2360 timestamp=65000 >> device=A code=C1 >>event id=fc89715b-fc30-4b12-ab31-a3884dcd4886 timestamp=75000 >> device=A code=C2 >> >> Any ideas concerning an alternative solution are highly welcomed. >> >> Thanks, >> Ingo >> >> >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Semantic of rules with not and coincide
Dear all, I am currently stuck with a problem concerning the use of not and conincide. I want to analyze a stream of error code events from a set of devices and detect the following situations. Every event has a timestamp (long), a device id (String) and an error code (String). What I want to detect is the following - If I get two events, one with code C1 and one with C2 from a single device within 1 minute, it represents a special event combination. The order of their appearence is not relevant. - If I just get C1 (without the C2 within the time frame), just report C1 - If I just get C2 (without the C1 within the time frame), just report C2 I can successfully detect the special event combination with the following rule rule "Detect combination" when $e1 : Event ($d: device, code == "C1") $e2 : Event (device == $d, code == "C2", this coincides [1m] $e1) then ... do some output end Then I tried to implement the detection of C1 only as follows rule "Detect code C1" when $e1 : Event ($d: device, code == "C1") not ( $e2 : Event (device == $d, code == "C2", this coincides [1m] $e1)) then ... do some other output end My understanding of the rule is that it should fire, if I get the event with code C1 and there is no other event with error code C2 for the same device that happens within one minute before and after the C1 event. To my surprise, the rule fires immediately when I insert an event with error code C1. Shouldn't the implementation wait at least 1 minute to be sure that no C2 error event will be inserted? BTW this is how I insert the events in my test case: clock.advanceTime(70, TimeUnit.SECONDS); FactHandle handle1 = ksession.insert( new Event(65000, "A", "C1") ); ksession.fireAllRules(); clock.advanceTime( 10, TimeUnit.SECONDS ); FactHandle handle2 = ksession.insert( new Event(75000, "A", "C2") ); ksession.fireAllRules(); clock.advanceTime( 2, TimeUnit.SECONDS ); And this is mainly the output I get: detected code C1 @ 7 event id=44b895e5-7287-404b-8204-3de5690b2360 timestamp=65000 device=A code=C1 detected combination @ 8 event id=44b895e5-7287-404b-8204-3de5690b2360 timestamp=65000 device=A code=C1 event id=fc89715b-fc30-4b12-ab31-a3884dcd4886 timestamp=75000 device=A code=C2 Any ideas concerning an alternative solution are highly welcomed. Thanks, Ingo ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Group-by rule without using a fact for grouping purposes
Ahh... nice solution. Perhaps I was simply thinking too complicated. Works fine. There's however one thing that does not work with the accumulate for me. >>>> Number( intValue == 3 ) from accumulate( >>>> Event( $i : id, code == "ABCD") over window:time( 5m ), >>>> count( $i ) ) In all my other rules I retrieve the events that caused my rule to via via the kcontext.getMatch().getObjects(). In this case I just get a number object with value 3. Seems to be appropriate since I am matching against that number. But how can I get the ids of those three events that caused my rule to fire? Thanks, Ingo On 2013-12-05 09:40, Wolfgang Laun wrote: > What about > > rule cleanup > when > $d: Device( $id: id ) > not Event( id == $id ) > then > retract( $d ); > end > > -WL > > On 05/12/2013, IK81 wrote: >> The devices may come and go and there may be several hundreds of >> them. >> They are stored in a database. >> >> Currently, I feed the events into the knowledge session and trigger >> an >> EJB call (instead of the simple System.out.println I used in the >> example >> below) and pass the device id. The EJB does the rest and looks up >> the >> device and related information from the database. If the id is >> unknown, >> this call is just a NOOP. >> >> Currently the knowledge session and the database need no >> synchronization. I just wanted to avoid this in my design, but now >> it >> seems to be necessary just for this group-by issue. I can imagine >> that I >> can also insert the fact using a rule that matches if I get an event >> for >> a currently unknown device (i.e., having no fact for it in the >> session), >> but how to clean up the facts if a device disappears. This @expires >> annotation is only valid for events afaik. >> >> Are there really no alternatives for this group-by instead of having >> the fact? >> >> Ingo >> >> >> On 2013-12-05 06:52, Wolfgang Laun wrote: >>> Why is it "not practical" to add a fact for a device? You don't >>> have >>> to do this up front; they may come and go, dynamically. >>> >>> -W >>> >>> >>> On 05/12/2013, IK81 wrote: >>>> Hi, >>>> >>>> I am trying to figure out a rule for matching an incoming sequence >>>> of >>>> events, but so far I was not really successful. Basically, I want >>>> to >>>> process events from devices. Every event has a timestamp (long), >>>> an >>>> id >>>> (a UUID string), a deviceId and an error code (both are strings). >>>> >>>> What I want to have is a simple rule that fires, if a single >>>> device >>>> reports a certain error code (e.g. ABCD) 3 times within 5 minutes >>>> (i.e., >>>> getting 3 such events within 5 minutes). So far, I suceeded in >>>> counting >>>> the ABCD error codes in the time window as follows: >>>> >>>> >>>> rule "Detect 3 occurrences of code ABCD for a certain device" >>>> when >>>> Number( intValue == 3 ) from accumulate( >>>> Event( $i : id, code == "ABCD") over window:time( 5m ), >>>> count( $i ) ) >>>> then >>>>System.out.println("Raise alarm"); >>>> end >>>> >>>> This first attempt does not distinguish which device sent the >>>> error >>>> code. But how can I express to fire only if the events share the >>>> same >>>> deviceId? I found many solutions that use a fact (e.g., a device >>>> fact) >>>> to group by the device and do the accumulation. I successfully >>>> implemented the group-by using the following when-part of the >>>> rule. >>>> >>>> when >>>> Device($deviceId : id) >>>> Number( intValue == 2 ) from accumulate( >>>> Event( $i : id, deviceId == $deviceId, code == "ABCD") >>>> over >>>> window:time( 5m ), >>>> count( $i ) ) >>>> then >>>> >>>> Adding a device fact is however not practical in my case. Are >>>> there >>>> any >>>> alternatives for expressing this group-by? >>>> >>>> Thanks, >>>> Ingo >>>> ___ >>>> rules-users mailing list >>>> rules-users@lists.jboss.org >>>> https://lists.jboss.org/mailman/listinfo/rules-users >>>> >>> ___ >>> rules-users mailing list >>> rules-users@lists.jboss.org >>> https://lists.jboss.org/mailman/listinfo/rules-users >> >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Group-by rule without using a fact for grouping purposes
The devices may come and go and there may be several hundreds of them. They are stored in a database. Currently, I feed the events into the knowledge session and trigger an EJB call (instead of the simple System.out.println I used in the example below) and pass the device id. The EJB does the rest and looks up the device and related information from the database. If the id is unknown, this call is just a NOOP. Currently the knowledge session and the database need no synchronization. I just wanted to avoid this in my design, but now it seems to be necessary just for this group-by issue. I can imagine that I can also insert the fact using a rule that matches if I get an event for a currently unknown device (i.e., having no fact for it in the session), but how to clean up the facts if a device disappears. This @expires annotation is only valid for events afaik. Are there really no alternatives for this group-by instead of having the fact? Ingo On 2013-12-05 06:52, Wolfgang Laun wrote: > Why is it "not practical" to add a fact for a device? You don't have > to do this up front; they may come and go, dynamically. > > -W > > > On 05/12/2013, IK81 wrote: >> Hi, >> >> I am trying to figure out a rule for matching an incoming sequence >> of >> events, but so far I was not really successful. Basically, I want to >> process events from devices. Every event has a timestamp (long), an >> id >> (a UUID string), a deviceId and an error code (both are strings). >> >> What I want to have is a simple rule that fires, if a single device >> reports a certain error code (e.g. ABCD) 3 times within 5 minutes >> (i.e., >> getting 3 such events within 5 minutes). So far, I suceeded in >> counting >> the ABCD error codes in the time window as follows: >> >> >> rule "Detect 3 occurrences of code ABCD for a certain device" >> when >> Number( intValue == 3 ) from accumulate( >> Event( $i : id, code == "ABCD") over window:time( 5m ), >> count( $i ) ) >> then >> System.out.println("Raise alarm"); >> end >> >> This first attempt does not distinguish which device sent the error >> code. But how can I express to fire only if the events share the >> same >> deviceId? I found many solutions that use a fact (e.g., a device >> fact) >> to group by the device and do the accumulation. I successfully >> implemented the group-by using the following when-part of the rule. >> >> when >> Device($deviceId : id) >> Number( intValue == 2 ) from accumulate( >> Event( $i : id, deviceId == $deviceId, code == "ABCD") over >> window:time( 5m ), >> count( $i ) ) >> then >> >> Adding a device fact is however not practical in my case. Are there >> any >> alternatives for expressing this group-by? >> >> Thanks, >> Ingo >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Group-by rule without using a fact for grouping purposes
Hi, I am trying to figure out a rule for matching an incoming sequence of events, but so far I was not really successful. Basically, I want to process events from devices. Every event has a timestamp (long), an id (a UUID string), a deviceId and an error code (both are strings). What I want to have is a simple rule that fires, if a single device reports a certain error code (e.g. ABCD) 3 times within 5 minutes (i.e., getting 3 such events within 5 minutes). So far, I suceeded in counting the ABCD error codes in the time window as follows: rule "Detect 3 occurrences of code ABCD for a certain device" when Number( intValue == 3 ) from accumulate( Event( $i : id, code == "ABCD") over window:time( 5m ), count( $i ) ) then System.out.println("Raise alarm"); end This first attempt does not distinguish which device sent the error code. But how can I express to fire only if the events share the same deviceId? I found many solutions that use a fact (e.g., a device fact) to group by the device and do the accumulation. I successfully implemented the group-by using the following when-part of the rule. when Device($deviceId : id) Number( intValue == 2 ) from accumulate( Event( $i : id, deviceId == $deviceId, code == "ABCD") over window:time( 5m ), count( $i ) ) then Adding a device fact is however not practical in my case. Are there any alternatives for expressing this group-by? Thanks, Ingo ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Howto obtain collection of all matched events in rule
I already use the accumulate. Perhaps this example of a rule will clarify my issue: when // match a device $d : Device () // if there are more than 5 offline events for that device within the last 15 minutes $x : Number(intValue >= 5) from accumulate ( $e : OfflineEvent (deviceId == $d.id) over window:time(15m), count ($e)) $y : SpecialEvent (deviceId == $d.id, code=10) then ... here I need a collection of all events that caused the rule to fire ... this means all accumulated offline events and the special event I registered an AgendaListener and get this kind of collection via the Match object. But how do I access this object directly in the rule? Best Regards, Ingo On 2013-09-30 16:05, Wolfgang Laun wrote: > Have you considered "accumulate" and "from collect"? Or perhaps I > misinterpreted the question...? > -W > > On 30/09/2013, IK81 wrote: >> Dear all, >> >> I am looking for a convenient way to obtain all events that lead to >> the >> firing of the rule in the then-part of a rule. I know that I can >> build >> this collection by explicitly creating a collection and adding all >> the >> events listed in the when part, but I am looking for something more >> convenient. >> >> I already discovered that one can access this information in the >> beforeMatchFired event through getMatch().getObjects(), but I need >> to >> access this in the then-part of the rule. How do I obtain the match >> object there? >> >> Best regards, >> Ingo >> >> >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Howto obtain collection of all matched events in rule
Dear all, I am looking for a convenient way to obtain all events that lead to the firing of the rule in the then-part of a rule. I know that I can build this collection by explicitly creating a collection and adding all the events listed in the when part, but I am looking for something more convenient. I already discovered that one can access this information in the beforeMatchFired event through getMatch().getObjects(), but I need to access this in the then-part of the rule. How do I obtain the match object there? Best regards, Ingo ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Snapshot of drools engine's state
Ok, if this is the case then I am fine. I thought the engine might be interested not on the event's timestamp but also when the events are inserted into the system as well. But as already mentioned, this was just my naive impression - I haven't digged into the source code that deep now. The recovery is in a first step to keep the state during restarts of the application server. Next step is to allow a migration of the session between different nodes on the AS cluster. If a node fails than another node can use the last persisted state, replay the events and keep on going with the processing. AFAIK there's no special support for Drools to run in a distributed fashion in a cluster. The requirements are not that hard that mission a single beat is essential, but I'll try to avoid any loss of state in my design. Ingo -- View this message in context: http://drools.46999.n3.nabble.com/Snapshot-of-drools-engine-s-state-tp4025457p4025481.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Snapshot of drools engine's state
Thanks for your reply. The way you described this is actually how my proof-of-concept works. However, I implemented it using two timestamps. First I use the @timestamp annotation for the property of the event. This property is set by the event source. Second, I persist a second timestamp that reflects the timestamp of the session's pseudo clock when I inserted the event. From my naive feeling I need both for a reproducible replay starting with the last snapshot of the session. Thanks for the hint concerning the sliding window. This is the drawback of the approach of externally controlling the clock - it limits the time granularity of these not-event-B-after-A rules. But in my case I can live with this restriction that the rule might fire some seconds later. I wished there would exist a possibility to register for a kind of callback when to externally trigger the event engine again - however, I haven't found anything related to that. Thanks & best regards, Ingo -- View this message in context: http://drools.46999.n3.nabble.com/Snapshot-of-drools-engine-s-state-tp4025457p4025474.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Snapshot of drools engine's state
I know that this timer inserts real-time. I plan to persists also the timestamps when I call these external timer-based fireAllRules invocations. The problem is that I have to support rules that reason over the non-occurence of events and not every time I insert a new event. I don't know how I could realize this otherwise. I'd love to have a kind of callback where the engine tells me - wake me up in X seconds so that I can re-evaluate my rules because then my not-after-N-timeunits rules can fire. The reason for this approach is that I'll have to ensure that I process every event but be tolerant against re-starts of my application server. If I have a rule - let's say fire if I have event A but no event B after 3 minute and I insert event A. Let's assume that the application server is rebooted in the meantime and I start with a clean session, then this rule would never fire. Unfortunately, I cannot afford to persist the complete state after every rule insertion due to performance reasons. However, the events have to be persisted anyway. Therefore, I came to this proposal to persist the state only after N seconds or insertions as a kind of snapshot. In case of recovery after a reboot (or transfer of the engine to another cluster node) I use the snapshot, reinsert the events to get to the same state. However, this was just my idea how to solve this problem. If you could provide me a pointer to a better solution I'd also be very thankful. Thanks for the hint about the timestamp. But isn't the clock of the session also relevant when inserting new events (which have their own timestamp provided in the event's POJO?). Therefore, I though that it is necessary to store both the event's timestamp (which is assigned by an external event source) and the timestamp when I put it into the engine. Ingo -- View this message in context: http://drools.46999.n3.nabble.com/Snapshot-of-drools-engine-s-state-tp4025457p4025471.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Snapshot of drools engine's state
I understand. But in my case the state might change even if i do not insert new events because I have rules that fire if I have event A but no event B within X seconds after A. For that purpose I'll use a timer that advances the clock and calls the fireAllRules without any insertion. Is my assumption right that the engine will behave deterministic when I replay the events on my snapshot using an external (pseudo?) clock. I've tested it and from my observations it seemed to be deterministic - but I haven't looked at the engine's internals so far. I plan to persist my events with the timestamps of their occurrence and the timestamp when I insert them into the engine. So will I always end up with the same propagation numbers etc.? Ingo -- View this message in context: http://drools.46999.n3.nabble.com/Snapshot-of-drools-engine-s-state-tp4025457p4025467.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Snapshot of drools engine's state
I don't think that the synchronization is a problem. I don't want to use a dedicated thread that runs the fireUntilHalt method but rather trigger the engine externally. So I can decide if it's time to make a new snapshot or not. So I can avoid to find the engine in an inconsistent state. I also plan to provide the clock from an external source instead of relying on the system time to achieve a deterministic behavior when replaying the events. What do you exactly mean with "Saving every so many, and synced with, insertions might be an alternative,"? Ingo -- View this message in context: http://drools.46999.n3.nabble.com/Snapshot-of-drools-engine-s-state-tp4025457p4025464.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Snapshot of drools engine's state
Hi, I am looking for a solution to make the engine's state persistent in regular intervals. I do not want to persist the engine's state at every event insertion for performance reasons. Instead I am thinking of making a snapshot of the engine's state let's say every X seconds. The events I have are always stored to a database. In case of a crash or reboot I'd like to recover the engine's state from the snapshot + reinserting the events that happened after the timestamp of my snapshot. Are there any hints or caveats regarding this approach? Best regards, Ingo -- View this message in context: http://drools.46999.n3.nabble.com/Snapshot-of-drools-engine-s-state-tp4025457.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Drools Fusion in JEE environment
Hi all, i am planning to use the Drools engine in the stream mode within an JEE application server. I have to process events of different users which can define their own rules. So I plan to instantiate a stateful session for each user and populate them with the user's rules. However, I am concerned how to manage the firing of the rules - which might be delayed by some time because of some rule statements (fire rule after having event A and no event B within 3 minutes). Spawning a thread for each session and calling fireUntilHalt is not an option in my opinion. I've found a solution where somebody uses a scheduler within the container to call fireAllRules at certain domain-specific intervals (e.g., every 10 seconds). I am wondering if there is a more clever approach. I am thinking of providing a callback that can be used by Drools to notify when it has to be "waked-up" again to fire the delayed rule. Best regards, Ingo -- View this message in context: http://drools.46999.n3.nabble.com/Drools-Fusion-in-JEE-environment-tp4025032.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Strange behaviour when adding rules during run-time
aaargh... shame on me. Thank you so much. Ingo -- View this message in context: http://drools.46999.n3.nabble.com/Strange-behaviour-when-adding-rules-during-run-time-tp4024561p4024567.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Strange behaviour when adding rules during run-time
Ok, this is is the Event class This is the main class The drl with the rule one and this is the second one -- View this message in context: http://drools.46999.n3.nabble.com/Strange-behaviour-when-adding-rules-during-run-time-tp4024561p4024565.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Strange behaviour when adding rules during run-time
Hi, thanks for the advice. Still does not work I've isolated the problem. At the beginning the ksession has just a simple rule (see rule one below) and I add the first event. This is the first DRL file i load with rule one This is the second one And this is the final output For any strange reason the first event still fires for the second rule that is newly added at a later point in time. Since the event is never referenced in a temporal statement I assume that the first event with timestamp 0 is already gone when I add the second rule after 100 seconds. Even if a manually annotate the event with @expires(10s) in both DRL files, it results in the same output. Any ideas? Ingo -- View this message in context: http://drools.46999.n3.nabble.com/Strange-behaviour-when-adding-rules-during-run-time-tp4024561p4024563.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Strange behaviour when adding rules during run-time
Dear all, I am encountering a strange issue that rules fire based on events, which I already considered as expired. As far as I learned from the documentation Drools automatically determines the expiration time of an event based on analyzing the rules (e.g. if there's a temporal operator or aggregation using the event). Ok, i do not use anything of that. My scenario is as follows - for testing purposes I use a pseudo session clock and of course the STREAM mode. - At time 0 I insert an Event A and call fireAllRules - Then I advance the time for 100 seconds - Now I add a further rule by parsing a drl file and adding it to the Knowledge base of my current session - Then, still at time 100 I insert another Event B and call fireAllRules again The rule that I've inserted previously fires but unfortunately twice. Once for event A (which I already considered as expired) and for event B (which is that what I wanted). Even if i use the @expires annotation in my drl this does not work correctly. Do I have to call another method to trigger the expiration in the session. Any suggestions? Ingo p.s. I am using Drools 5.5 final -- View this message in context: http://drools.46999.n3.nabble.com/Strange-behaviour-when-adding-rules-during-run-time-tp4024561.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users