[rules-users] On demand events

Wolfgang Laun wolfgang.laun at gmail.com
Sun Feb 6 03:56:19 EST 2011


Objects resulting from "from"+expression are not facts in Working Memory,
and thus they aren't events either.

You might investigate a similar approach where you have, for each rule
according to

rule "example"
  when
    Event1(..) from entry-point Event1Store
    Event2(..) from entry-point Event2Store
  then //...
end

an additional rule

rule "example sentinel"
  when
    Event1(..) from entry-point Event1Store
    $es: Event2Sentinel( evRef != null ) //  from entry-point Event2Store
  then
    Event2 ev2 = $event2Provider.evaluate();
    insert( new Event2() );
    modify( $es ){ setEvRef( ev2 ) }
end

You will have to update the sentinel when the Event2 is retracted.
This depends how you want this done, but the following rule should
work in any case_

rule "clear sentinel"
when
    $es: Event2Sentinel( $er: evRef != null )
    not Event2( this == $er )
then
   modify( $es ){ setEvRef( null ) }
end

I'm not sure why you need events in the first place, but you can use
explicit retract for events as well.

I'm not sure whether you need the "from"+entry-point at all.

-W


On 6 February 2011 00:07, James Willans <james.willans at ceteva.com> wrote:

> Hello,
>
> I'm a new user of Drools and have experimented with the basics.  I am
> interested in processing events and have had success when defining rules
> of the type:
>
> rule "example"
>   when
>     Event1(..) from entry-point Event1Store
>     Event2(..) from entry-point Event2Store
>   then
>     System.out.println("Fired!");
> end
>
> Where events of type Event1 and Event2 are continually injected into
> entry-points within the working memory.
>
> The events I have in mind are formed from data that sit in data stores
> that are expensive to access and I would like to explore strategies for
> minimising access to these.  In the above example, I assume that if
> Drools does not match the pattern Event1(..) then it will not try and
> match the pattern Event2(..), in which case it would not be necessary to
> construct facts/events which may match the Event2(..) pattern.
>
> I understand that the 'from' statement can be used to evaluate facts
> that are not in working memory, on this basis I have defined proxy
> objects that are inserted into working memory which are then evaluated
> for the actual data from the database on demand:
>
> 1 rule "example"
> 2  when
> 3    $event1Provider : Event1Provider()
> 4    Event1(..) from $event1Provider.evaluate()
> 5    $event2Provider : Event2Provider()
> 6    Event2(..) from $event2Provider.evaluate()
> 7  then
> 8    System.out.println("Fired!");
> 9 end
>
> On the basis that if line 4 fails to match, then line 5 and 6 will not
> get evaluated therefore avoiding accessing the database describing the
> Event2 fact/event.  I think that this works - but only once, since it
> looks like the system is treating these as facts, that don't expire,
> rather than events.  Is it the case that the 'from' statement cannot be
> used for events in this way?  If not, what approach should be taken to
> addressing the problem I am trying to solve?
>
> Any direction would be much appreciated.
>
> James
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110206/97961767/attachment.html 


More information about the rules-users mailing list