Hi Mario,
Thank you for the writeup it makes things much clearer.
Other people have already commented and I will try not to repeat too much of what they
have said.
I think the feature looks really promising and will help reduce the need to split Beans up
into tiny pieces to make them work with Drools easier.
My main comments:
1. There needs to be a mechanism to support the feature which isn’t invasive on the
Java objects. While annotations are nicer they are tying the domain model into an
implementation details of the system. Depending on what is being worked on adding these
annotations may therefore be undesirable or impossible as the model is owned by a
different team/used for other things. This could be through a separate mapping file
(orm.xml concept), drl language level support or some programmatic method.
2. Is there a technical reason why you can’t define property specific support by
using @watch even if the model hasn’t been annotated up? I don’t know the specifics of how
Drools compiles the rete tree and whether you need this information up front or not.
3. I don’t find the annotation name “PropSpecific” intuitive or descriptive enough –
particularly when imagining myself as a general java programmer seeing the annotation who
has limited exposure to drools. At the very least it should be PropertySpecific but even
then if someone sees the annotation they will say to themselves “so this class is
PropertySpecific” but have no further clue as to what this means. They will wonder to
themselves in what ways are the properties are specific to this class? If they are lucky
they may realize that annotation is defined in the drools package and so wonder in what
way is this class property specific to drools? The name isn’t really giving any clues as
to what it means unless you know in details about the drools feature already. While being
more verbose something like “ProvidesPropertySpecificUpdates” allows a degree of intuitive
understanding of what affect the annotation may have without having to be fully clued up
in all the specifics of drools. Code completion and the fact it is only written once per
class makes the length relatively immaterial when compared to readability and
comprehension.
4. There should be a property exposed on the knowledgeBuilder/somewhere which allows
the feature to be disabled fully even if the classes have the appropriate annotations –
among other things this will help with migrating a model and the set of rules to the new
support without having to do it all in one go.
Keep up the good work,
Thomas
From: rules-dev-bounces(a)lists.jboss.org [mailto:rules-dev-bounces@lists.jboss.org] On
Behalf Of Mario Fusco
Sent: 17 January 2012 19:20
To: Rules Dev List
Subject: Re: [rules-dev] Fine Grained Property Change Listeners (Slot Specific)
Hi all,
just a quick recap of what I did until now to check if we are all on the same page and
also agree with the naming convention I used.
The property specific feature is off by default in order to make the behavior of the rule
engine backward compatible with the former releases. If you want to activate it on a
specific bean you have to annotate it with @propSpecific. This annotation works both on
drl type declarations:
declare Person
@propSpecific
firstName : String
lastName : String
end
and on Java classes:
@PropSpecific
public static class Person {
private String firstName;
private String lastName;
}
Moreover on Java classes you can also annotate any method to say that its invocation
actually modifies other properties. For instance in the former Person class you could have
a method like:
@Modifies( "firstName, lastName" )
public void setName(String name) {
String[] names = name.split("\\s<file:///\\s>");
this.firstName = names[0];
this.lastName = names[1];
}
That means that if a rule has a RHS like the following:
modify($person) { setName("Mario Fusco") }
it will correctly recognize that both the firstName and lastName have been modified and
act accordingly. Of course the @Modifies annotation on a method has no effect if the
declaring class isn't annotated with @PropSpecific.
The third annotation I have introduced is on patterns and allows you to modify the
inferred set of properties "listened" by it. So, for example, you can annotate a
pattern in the LHS of a rule like:
Person( firstName == $expectedFirstName ) @watch( lastName ) // --> listens for changes
on both firstName (inferred) and lastName
Person( firstName == $expectedFirstName ) @watch( * ) // --> listens for all the
properties of the Person bean
Person( firstName == $expectedFirstName ) @watch( lastName, !firstName ) // --> listens
for changes on lastName and explicitly exclude firstName
Person( firstName == $expectedFirstName ) @watch( *, !age ) // --> listens for changes
on all the properties except the age one
Once again this annotation has no effect if the corresponding pattern's type
hasn't been annotated with @PropSpecific.
I've almost finished with the development of this feature (at the moment I am missing
the compile-time check of the properties named in the @watch annotation together with some
more exhaustive tests), so if you think that I misunderstood something or there is room
for any improvement (or you just don't like the annotation's names I chose) please
let me know as soon as possible.
Mario
________________________________
**************************************************************************************
This message is confidential and intended only for the addressee. If you have received
this message in error, please immediately notify the postmaster(a)nds.com and delete it from
your system as well as any copies. The content of e-mails as well as traffic data may be
monitored by NDS for employment and security purposes. To protect the environment please
do not print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United
Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603
8808 40-00
**************************************************************************************