[rules-users] Complex pattern
Wolfgang Laun
wolfgang.laun at gmail.com
Wed May 9 02:09:48 EDT 2012
Things would be simpler if the SubscriptionMatchers were facts, but
collecting facts into lists isn't trivial anyway. It can be done by a
set of cooperating rules (create Collector, add another fact to
Collector, use results in Collector) but that's not as compact as this
technique using a query to get all Subscriptions that should go into
the resulting collection:
query LockMatchSubs ( Subscription $s )
Subscription( this == $s )
Lock( object == $s )
TriviaResponseArrived( $matchers: matchers )
$sm: SubscriptionMatcher() from $matchers
eval( $sm.matches($s) )
end
rule "Complex pattern"
when
$subscriptions : Collection()
from accumulate( LockMatchSubs( $s; ), collectList( $s ) )
then
for( Object obj: $subscriptions ){
System.out.println( "Subscription: " + (Subscription)obj );
}
end
-W
On 09/05/2012, rcano <rcano at netlabs.com.uy> wrote:
> Hi there,
>
> I've been struggling for almost a day now, trying to create a pattern that
> goes something as follows (notice it doesn't compile):
>
> rule "Complex pattern"
> when
> $triviaResponse : TriviaResponseArrived($matchers: matchers)
> $subscriptions : ArrayList() from collect (
> $s: Subscription()
> $lock: Lock(object == $s)
> exists SubscriptionMatcher(matches($s)) from $matchers
> )
> then
> logger.info("NO TRANSACTION", "Selected subscriptions " +
> $subscriptions);
> end
>
> where TriviaResponseArrived, contains a List of SubscriptionMatchers (a
> simple object which just returns true or false when its matches method is
> called).
> Upon receiving this TriviaResponseArrived fact, I'm trying to select all
> subscriptions from the working memory, for which there is also a Lock, and
> that there exists a matcher within the matchers
> list that validates it. To sum up, all subscriptions in the list
> subscription, should be locked, and matched by a matcher in the
> triviaResponseArrived fact.
>
> The closes I've managed to come is:
>
> rule "Complex pattern"
> when
> $triviaResponse : TriviaResponseArrived($matchers: matchers)
> $subscription : Subscription()
> $lock: Lock(object == $subscription)
> exists SubscriptionMatcher(matches($subscription)) from $matchers
> then
> logger.info("NO TRANSACTION", "Subscription " + $subscription);
> end
>
> Which is not quite right, since I need to process all the subscription that
> match the above logic at once.
>
> As always, all help is really appreciated. Thanks.
>
> Cheers.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
More information about the rules-users
mailing list