Return-Path: Delivered-To: apmail-directory-api-archive@minotaur.apache.org Received: (qmail 93621 invoked from network); 14 Jan 2010 21:13:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Jan 2010 21:13:10 -0000 Received: (qmail 7827 invoked by uid 500); 14 Jan 2010 21:13:10 -0000 Delivered-To: apmail-directory-api-archive@directory.apache.org Received: (qmail 7801 invoked by uid 500); 14 Jan 2010 21:13:10 -0000 Mailing-List: contact api-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: api@directory.apache.org Delivered-To: mailing list api@directory.apache.org Received: (qmail 7791 invoked by uid 99); 14 Jan 2010 21:13:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jan 2010 21:13:10 +0000 X-ASF-Spam-Status: No, hits=-4.0 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [192.18.6.21] (HELO gmp-eb-inf-1.sun.com) (192.18.6.21) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jan 2010 21:13:00 +0000 Received: from fe-emea-09.sun.com (gmp-eb-lb-1-fe1.eu.sun.com [192.18.6.7] (may be forged)) by gmp-eb-inf-1.sun.com (8.13.7+Sun/8.12.9) with ESMTP id o0ELCdI3025959 for ; Thu, 14 Jan 2010 21:12:39 GMT MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; format=flowed; charset=UTF-8 Received: from conversion-daemon.fe-emea-09.sun.com by fe-emea-09.sun.com (Sun Java(tm) System Messaging Server 7u2-7.04 64bit (built Jul 2 2009)) id <0KW9009009IBFX00@fe-emea-09.sun.com> for api@directory.apache.org; Thu, 14 Jan 2010 21:12:18 +0000 (GMT) Received: from [192.168.1.10] ([unknown] [82.122.139.29]) by fe-emea-09.sun.com (Sun Java(tm) System Messaging Server 7u2-7.04 64bit (built Jul 2 2009)) with ESMTPSA id <0KW9009GV9KHXBA0@fe-emea-09.sun.com>; Thu, 14 Jan 2010 21:12:17 +0000 (GMT) Date: Thu, 14 Jan 2010 22:12:16 +0100 From: Matthew Swift Subject: Re: [DN] Existing API review In-reply-to: <4B4DB6A7.6080308@gmail.com> Sender: Matthew.Swift@Sun.COM To: api@directory.apache.org Cc: Francois Message-id: <4B4F88B0.50505@sun.com> References: <4B4C7948.3000503@gmail.com> <4B4DAD6E.4040204@sun.com> <4B4DB6A7.6080308@gmail.com> User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8pre) Gecko/20100113 Lightning/1.0b1 Shredder/3.0.2pre X-Virus-Checked: Checked by ClamAV on apache.org On 13/01/10 13:03, Francois wrote: > Le 13/01/2010 12:24, Matthew Swift a écrit : >> Hi Emmanuel, > > I'm just giveng my point of view about the following, I don't think I > can be relevant elsewhere: > >> 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? > > I will go further : DN, RDN and AVA should be immutable, but Attribute > should be immutable too, and Entry should have at least an immutable > DN (and facilities to copy an entry with a new DN or ParentDN at > factory level). > > For attribute, the rationnal is that one replace attribute by a new > one most of the time, and it's much easier to deal with immutable > attribute - that's one of the aspect of UnboundId SDK that I prefer. I understand very well why you think Attribute could be immutable. In fact, I went to great lengths to convert our Attribute API in OpenDS server so that it was immutable in order to be able to optimize for the common case (single valued attributes) and to avoid defensive copies. The result was a 4x performance improvement in the server (!). However, this did introduce some pain - any code in the server which tried to modify an attribute became more complex. For example, I had to implement an AttributeBuilder class to facilitate incremental construction of Attributes. In fact, ironically, I heard on the grape vine that Neil Wilson was pretty impressed with the improvements that we got and this is why UnboundID's Attribute class is immutable (except that Neil, being notoriously bad at API design, has not made it fully immutable - look at all those arrays with Javadoc warnings saying that you are not allowed to modify the content. Very suspect!). I thought about this long and hard for the OpenDS SDK and decided that a client API with an immutable Attribute would not be very easy to use. Many client apps will want to create and modify attributes and we should make it as easy as possible. In addition, I think that it is very likely that some users of the SDK (including the server itself) will need to have different types of Attribute - in other words, they'll need to sub-class Attribute (e.g. in order to create lazy decoded Attributes, virtual Attributes, copy on write, synchronized, etc). By implication any class which is non-final is not immutable since a sub-class could be implemented which breaks the contract (I realized that I had made this mistake in the server since our Attribute class is in fact an interface). Therefore the approach I took in the OpenDS SDK was to copy the Collections API approach. Provide a high-level interface providing read/write operations (side note: an Attribute can be thought of as a Set of values) and then provide an "unmodifiable" adapter as per Collections.unmodifiableSet. Then we get the best of all worlds - including the ability to avoid defensive copies by implementing getters which return "unmodifiable" Attributes (the OpenDS SDK implementation also optimizes for the case where an attribute is single valued even though it is mutable). > > For Entry's DN, it's linked to the fact that DN are almost IDs for > entries. So, the semantic of such an operation is much likely in two > cases: > - create a copy of an entry with another DN (change RDN but perhaps > not parentDN) > - move an entry (only the parent DN change). > These two cases (I hope I don't forget other ones) are easily > fulfilled througth factory-like method support. [Disclaimer: the OpenDS SDK Entry API is not finalized yet in case you're tempted to look at it. IMO it's way to bloated still and contains some strange methods] I agree that Entry DNs should not in general be modified, but I think preventing clients from doing this is a bit of an artificial constraint. There's no hard reason I can think of why you would want to prevent modification. In addition, if Entry is an interface (as it is in the OpenDS SDK) then, like Attribute, adapters can by provided which render some Entry operations unsupported. For example, you could have a Collections-like unmodifiableEntry method or even a unrenamableEntry in order to address the requirement above. Matt