Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9AB0BB245 for ; Sun, 22 Jan 2012 12:02:36 +0000 (UTC) Received: (qmail 14531 invoked by uid 500); 22 Jan 2012 12:02:36 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 14469 invoked by uid 500); 22 Jan 2012 12:02:35 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 14462 invoked by uid 99); 22 Jan 2012 12:02:35 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 22 Jan 2012 12:02:35 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 22 Jan 2012 12:02:34 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F018B2388900 for ; Sun, 22 Jan 2012 12:02:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1234497 - /directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/BTree.java Date: Sun, 22 Jan 2012 12:02:13 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120122120213.F018B2388900@eris.apache.org> Author: elecharny Date: Sun Jan 22 12:02:13 2012 New Revision: 1234497 URL: http://svn.apache.org/viewvc?rev=1234497&view=rev Log: Added some Javadoc Modified: directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/BTree.java Modified: directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/BTree.java URL: http://svn.apache.org/viewvc/directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/BTree.java?rev=1234497&r1=1234496&r2=1234497&view=diff ============================================================================== --- directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/BTree.java (original) +++ directory/sandbox/elecharny/shared-mvbt/src/main/java/org/apache/directory/btree/BTree.java Sun Jan 22 12:02:13 2012 @@ -43,13 +43,19 @@ public class BTree /** This BTree's record ID in the PageManager. */ private transient long recordId; + /** A field used to generate new revisions in a thread safe way */ + private AtomicLong revision = new AtomicLong(0); + + /** A field used to generate new recordId in a thread safe way */ private transient AtomicLong pageRecordIdGenerator; /** Comparator used to index entries. */ Comparator comparator; + /** The current rootPage */ protected Page rootPage; + /** A map containing all the existing revisions */ private Map> roots = new HashMap>(); /** @@ -58,15 +64,14 @@ public class BTree */ int bTreeHeight; - /** Revision */ - private AtomicLong revision = new AtomicLong(0); - /** Number of entries in each Page. */ protected int pageSize; /** + * Creates a new BTree with a default page size and a comparator. * + * @param comparator The comparator to use */ public BTree( Comparator comparator ) throws IOException { @@ -75,7 +80,10 @@ public class BTree /** + * Creates a new BTree with a specific page size and a comparator. * + * @param comparator The comparator to use + * @param pageSize The number of elements we can store in a page */ public BTree( Comparator comparator, int pageSize ) throws IOException { @@ -93,14 +101,25 @@ public class BTree } - public void setPageSize( int pageSize ) + /** + * Find the value associated with the given key. + * + * @param key Lookup key. + * @return Value associated with the key, or null if not found. + */ + public V find( K key ) throws IOException { - this.pageSize = pageSize; + if ( key == null ) + { + throw new IllegalArgumentException( "Key must not be null" ); + } - if ( pageSize <= 0 ) + if ( rootPage == null ) { - this.pageSize = DEFAULT_PAGE_SIZE; + return null; } + + return rootPage.find( key ); } @@ -169,29 +188,33 @@ public class BTree /** - * Find the value associated with the given key. - * - * @param key Lookup key. - * @return Value associated with the key, or null if not found. + * @return The number of element we can stoe in a page */ - public V find( K key ) throws IOException + public int getPageSize() { - if ( key == null ) - { - throw new IllegalArgumentException( "Key must not be null" ); - } + return pageSize; + } + + + /** + * Set the maximum number of elements we can store in a page. This must be a + * number greater than 1. The default page size is 16. + * + * @param pageSize The requested page size + */ + public void setPageSize( int pageSize ) + { + this.pageSize = pageSize; - if ( rootPage == null ) + if ( pageSize <= 2 ) { - return null; + this.pageSize = DEFAULT_PAGE_SIZE; } - - return rootPage.find( key ); } /** - * Return the persistent record identifier of the BTree. + * @return the persistent record identifier of the BTree. */ public long getRecordId() { @@ -208,18 +231,31 @@ public class BTree } + /** + * Generates a new RecordId. + * + * @return a new incremental recordId + */ /** No qualifier */ long generateRecordId() { return pageRecordIdGenerator.getAndIncrement(); } + /** + * Generates a new revision number. + * + * @return a new incremental revision number + */ /** No qualifier */ long generateRevision() { return revision.getAndIncrement(); } + /** + * @see Object#toString() + */ public String toString() { StringBuilder sb = new StringBuilder();