I'm really pretty new to Drools, so bear with me here: I'm trying to
develop some rules for classifying domains as belonging to spammers or
not, based on various test scenarios. Whether to even start these
test scenarios is also controlled by various rules, like occurrences
within a timeframe, so a rule engine seems a natural fit.
So how I might write some rules, off the top of my head:
rule "Lookup A Records"
when
d : Domain( name : n, arecs == null )
not Verdict(domain == d)
then
# lookup_a_records is potentially quite slow
modify( d ) { arecs = lookup_a_records(n) }
end
rule "Spammy host"
when
# isAnyBlacklisted just looks up each record in a DNS zone, very quick
d : Domain( eval( isAnyBlacklisted( d.arecs ) )
not Verdict(domain == d)
then
insert( new Verdict(d, SPAM) )
end
First off, I wouldn't mind being able to refactor those "not
Verdict(domain == d)" conditions out somehow ... agenda groups,
perhaps?
My main problem however is: I want lookup_a_records() to be
asynchronous. It's potentially very slow, and I have hundreds of
other domains to check (I have other scenarios that are slower than
mere DNS lookups, this is just an example). Just to add to the fun,
there can only be so many queries outstanding at any one time, so I'm
looking at using a queue somewhere. I'm thinking I could lose the
modify in the first rule, and make lookup_a_records schedule some
asynchronous call through a ThreadPoolExecutor that modifies the fact
-- hopefully directly, but is a session threadsafe?
Are there any examples I can look at where the RHS modifies and
inserts facts asynchronously?
Chuck