directory-api mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel LŽcharny <elecha...@gmail.com>
Subject Re: [DN] Existing API review
Date Wed, 13 Jan 2010 23:43:34 GMT
Matthew Swift a écrit :
> Hi Emmanuel,
Hi Matthew,

comments inline
>
>
>> 2) In Java, it's pretty natural to create objects through constructor.
>
>
> This may be true for constructors which compose the constructor's 
> parameters (e.g. list of RDNs or RDN+DN) into a new object (DN), but 
> it is definitely not true for constructors which perform parsing or 
> type conversions. There are very many examples in J2SE:
>
>    * String.valueOf(...) -converting objects to Strings
>
>    * Integer.valueOf(int) - converting an int to an Integer
>
>    * Integer.valueOf(String) - parsing a String as an Integer
>
>    * plus other primitive Objects (Boolean, Byte, Char, Float, ...)
>
>
> In fact, the use of static factory methods is a very common design 
> idiom and is strongly recommended in many texts including Joshua 
> Bloch's "Effective Java" (item #1). By using static factories with 
> well known names (e.g. valueOf) we are able to avoid creating 
> duplicate objects (item 4) if this proves useful (i.e. through the use 
> of a cache) and also enforce the singleton property for the root DN 
> (item #2).
In any case, I thinkw e should have the constructors. Even for Integer, 
you can do new Integer(n).

>> 3) I'm not sure that handling a cache for DN is a valuable trick, as it
>> leads to some contention and the need to manage this cache in a
>> muli-threaded environement (this has to be carefully evaluated)
>>
>
> I have done already and it results in a 30-40% parsing performance 
> improvement as well as a significant reduction in garbage. Having said 
> that, I'm not totally convinced that this gain is really worth the 
> extra complexity and old generation memory usage - especially 
> considering large server based applications may have 1000s of threads 
> - e.g using LDAP from within a servlet - all those thread local caches 
> could use a significant amount of memory!
>
> Our implementation uses a small thread/schema local cache mapping 
> String values to DNs. In most applications I think that it's 
> reasonable to assume that 99% (perhaps more) DNs share the same parent 
> or grand parent. When parsing a DN we first check if the string is in 
> the cache and, if not, parse the RDN and recursively repeat for the 
> parent DN (in the SDK a DN is implemented recursively as an RDN+DN).
Well, I don't really think that it's anything but implementation 
dependent, so from the API POV, it's irrelevant. As soon as we add the 
valueof() methods, those who want to add a cache can do it.

I don't know why I raised this point...
>
>> The base constructor we can have are probably something like:
>> DN()
>> DN(String dnStr)
>> DN( RDN... rdns)
>> DN( RDN rdn, DN parent)
>>
>
>
> I like the DN( RDN rdn, DN parent) constructor - we support this via 
> an instance method called DN.child(RDN). I think I prefer the 
> constructor approach since it is not clear from our "child" method 
> whether or not it modifies this DN or creates a new DN.  A constructor 
> is more obvious. You may want to have a concatenation constructor 
> DN(DN child, DN parent) for constructing DNs of entries within a 
> subtree using a relative DN (or "local name").
Why not a DN(DN child, DN parent) constructor two. It does not hurt and 
can help.
>
> One thing that is a bit tricky is whether or not the API should order 
> RDN parameters in little-endian (LDAP World) order or big-endian 
> (everyone else outside of LDAP) order. I think first time users may be 
> surprised by LDAP's unnatural little endian ordering.
I think we should keep the LDAP order when using DN( RDN...) 
constructor. For instance, if we want to create "dc=example, dc=org", 
that would be :
DN( "dc=example", "dc=org") (here, I use the String, but you should read 
RDN)
>
> Also, I strongly believe that DNs and RDNs and AVAs should be 
> immutable objects (as well as any other low level API type). What do 
> you think?
DN and RDN should be immutable, sure. AVA, I have some doubt.
>
> Also, on the subject of AVAs - we have the AVA type as an inner class 
> in RDN. I'm not particularly happy with this this, but less happy with 
> it being a standalone class since AVAs are only used in RDNs and may 
> introduce confusion elsewhere. For example, filters also use attribute 
> value assertions but these are not the same type of object as an AVA 
> even if they have the same name. For example, AVAs (in RDNs) do not 
> allow attribute options or matching rules to be specified.
I don't really like inner classes in this case for two reasons :
- It will be a big class, and the RN class while be hundreds of line 
long. Not cool
- If we just use an Inner class just because we want to hide it from the 
other classes, then I think it's probably better to have it package 
protected (ie, no qualifier for this class).

This can be discussed further, as your pont about its use in other 
context can be figured out.


Thanks !


Mime
View raw message