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 162F210229 for ; Tue, 13 Aug 2013 15:44:36 +0000 (UTC) Received: (qmail 66554 invoked by uid 500); 13 Aug 2013 15:44:17 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 66345 invoked by uid 500); 13 Aug 2013 15:44:16 -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 66247 invoked by uid 99); 13 Aug 2013 15:44:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Aug 2013 15:44:15 +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; Tue, 13 Aug 2013 15:43:41 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E0D8F2388C64 for ; Tue, 13 Aug 2013 15:42:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r874484 [27/45] - in /websites/production/directory/content/mavibot/gen-docs: ./ 1.0.0-M1/ 1.0.0-M1/apidocs/ 1.0.0-M1/apidocs/org/ 1.0.0-M1/apidocs/org/apache/ 1.0.0-M1/apidocs/org/apache/directory/ 1.0.0-M1/apidocs/org/apache/directory/mav... Date: Tue, 13 Aug 2013 15:42:17 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130813154229.E0D8F2388C64@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/BTreeBuilder.html ============================================================================== --- websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/BTreeBuilder.html (added) +++ websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/BTreeBuilder.html Tue Aug 13 15:42:13 2013 @@ -0,0 +1,201 @@ + + + + +BTreeBuilder xref + + + +
+
+1   /*
+2    *   Licensed to the Apache Software Foundation (ASF) under one
+3    *   or more contributor license agreements.  See the NOTICE file
+4    *   distributed with this work for additional information
+5    *   regarding copyright ownership.  The ASF licenses this file
+6    *   to you under the Apache License, Version 2.0 (the
+7    *   "License"); you may not use this file except in compliance
+8    *   with the License.  You may obtain a copy of the License at
+9    *
+10   *     http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   *   Unless required by applicable law or agreed to in writing,
+13   *   software distributed under the License is distributed on an
+14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   *   KIND, either express or implied.  See the License for the
+16   *   specific language governing permissions and limitations
+17   *   under the License.
+18   *
+19   */
+20  
+21  package org.apache.directory.mavibot.btree;
+22  
+23  
+24  import static org.apache.directory.mavibot.btree.BTreeFactory.createLeaf;
+25  import static org.apache.directory.mavibot.btree.BTreeFactory.createNode;
+26  import static org.apache.directory.mavibot.btree.BTreeFactory.setKey;
+27  import static org.apache.directory.mavibot.btree.BTreeFactory.setValue;
+28  
+29  import java.io.IOException;
+30  import java.lang.reflect.Array;
+31  import java.util.ArrayList;
+32  import java.util.Iterator;
+33  import java.util.List;
+34  
+35  import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
+36  
+37  
+38  /**
+39   * A BTree builder that builds a tree from the bottom.
+40   *
+41   * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+42   */
+43  public class BTreeBuilder<K, V>
+44  {
+45      private String name;
+46  
+47      private int numKeysInNode;
+48  
+49      private ElementSerializer<K> keySerializer;
+50  
+51      private ElementSerializer<V> valueSerializer;
+52  
+53  
+54      public BTreeBuilder( String name, int numKeysInNode, ElementSerializer<K> keySerializer,
+55          ElementSerializer<V> valueSerializer )
+56      {
+57          this.name = name;
+58          this.numKeysInNode = numKeysInNode;
+59          this.keySerializer = keySerializer;
+60          this.valueSerializer = valueSerializer;
+61      }
+62  
+63  
+64      public BTree<K, V> build( Iterator<Tuple<K, V>> sortedTupleItr ) throws IOException
+65      {
+66          BTree<K, V> btree = new BTree<K, V>( name, keySerializer, valueSerializer );
+67          btree.init();
+68  
+69          List<Page<K, V>> lstLeaves = new ArrayList<Page<K, V>>();
+70  
+71          int totalTupleCount = 0;
+72  
+73          Leaf<K, V> leaf1 = createLeaf( btree, 0, numKeysInNode );
+74          lstLeaves.add( leaf1 );
+75  
+76          int leafIndex = 0;
+77          while ( sortedTupleItr.hasNext() )
+78          {
+79              Tuple<K, V> tuple = sortedTupleItr.next();
+80  
+81              setKey( leaf1, leafIndex, tuple.getKey() );
+82  
+83              MemoryHolder<K, V> eh = new MemoryHolder<K, V>( btree, tuple.getValue() );
+84  
+85              setValue( leaf1, leafIndex, eh );
+86  
+87              leafIndex++;
+88              totalTupleCount++;
+89              if ( ( totalTupleCount % numKeysInNode ) == 0 )
+90              {
+91                  leafIndex = 0;
+92                  leaf1 = createLeaf( btree, 0, numKeysInNode );
+93                  lstLeaves.add( leaf1 );
+94              }
+95          }
+96  
+97          if ( lstLeaves.isEmpty() )
+98          {
+99              return btree;
+100         }
+101 
+102         // remove null keys and values from the last leaf and resize
+103         Leaf<K, V> lastLeaf = ( Leaf<K, V> ) lstLeaves.get( lstLeaves.size() - 1 );
+104         for ( int i = 0; i < lastLeaf.nbElems; i++ )
+105         {
+106             if ( lastLeaf.keys[i] == null )
+107             {
+108                 int n = i;
+109                 lastLeaf.nbElems = n;
+110                 K[] keys = lastLeaf.keys;
+111 
+112                 Class<?> keyType = btree.getKeyType();
+113                 lastLeaf.keys = ( K[] ) Array.newInstance( keyType, n );
+114                 System.arraycopy( keys, 0, lastLeaf.keys, 0, n );
+115 
+116                 ElementHolder<V, K, V>[] values = lastLeaf.values;
+117                 lastLeaf.values = ( MemoryHolder<K, V>[] ) Array.newInstance( MemoryHolder.class, n );
+118                 System.arraycopy( values, 0, lastLeaf.values, 0, n );
+119 
+120                 break;
+121             }
+122         }
+123 
+124         Page<K, V> rootPage = attachNodes( lstLeaves, btree );
+125 
+126         btree.rootPage = rootPage;
+127 
+128         return btree;
+129     }
+130 
+131 
+132     private Page<K, V> attachNodes( List<Page<K, V>> children, BTree btree ) throws IOException
+133     {
+134         if ( children.size() == 1 )
+135         {
+136             return children.get( 0 );
+137         }
+138 
+139         List<Page<K, V>> lstNodes = new ArrayList<Page<K, V>>();
+140 
+141         int numChildren = numKeysInNode + 1;
+142 
+143         Node<K, V> node = createNode( btree, 0, numKeysInNode );
+144         lstNodes.add( node );
+145         int i = 0;
+146         int totalNodes = 0;
+147         for ( Page<K, V> p : children )
+148         {
+149             if ( i != 0 )
+150             {
+151                 setKey( node, i-1, p.getLeftMostKey() );
+152             }
+153 
+154             node.children[i] = btree.createHolder( p );
+155 
+156             i++;
+157             totalNodes++;
+158 
+159             if ( ( totalNodes % numChildren ) == 0 )
+160             {
+161                 i = 0;
+162                 node = createNode( btree, 0, numKeysInNode );
+163                 lstNodes.add( node );
+164             }
+165         }
+166 
+167         // remove null keys and values from the last node and resize
+168         AbstractPage<K, V> lastNode = ( AbstractPage<K, V> ) lstNodes.get( lstNodes.size() - 1 );
+169         for ( int j = 0; j < lastNode.nbElems; j++ )
+170         {
+171             if ( lastNode.keys[j] == null )
+172             {
+173                 int n = j;
+174                 lastNode.nbElems = n;
+175                 K[] keys = lastNode.keys;
+176 
+177                 Class<?> keyType = btree.getKeyType();
+178                 lastNode.keys = ( K[] ) Array.newInstance( keyType, n );
+179                 System.arraycopy( keys, 0, lastNode.keys, 0, n );
+180 
+181                 break;
+182             }
+183         }
+184 
+185         return attachNodes( lstNodes, btree );
+186     }
+187 }
+
+
+ + Added: websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/BTreeConfiguration.html ============================================================================== --- websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/BTreeConfiguration.html (added) +++ websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/BTreeConfiguration.html Tue Aug 13 15:42:13 2013 @@ -0,0 +1,336 @@ + + + + +BTreeConfiguration xref + + + +
+
+1   /*
+2    *  Licensed to the Apache Software Foundation (ASF) under one
+3    *  or more contributor license agreements.  See the NOTICE file
+4    *  distributed with this work for additional information
+5    *  regarding copyright ownership.  The ASF licenses this file
+6    *  to you under the Apache License, Version 2.0 (the
+7    *  "License"); you may not use this file except in compliance
+8    *  with the License.  You may obtain a copy of the License at
+9    *
+10   *    http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   *  Unless required by applicable law or agreed to in writing,
+13   *  software distributed under the License is distributed on an
+14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   *  KIND, either express or implied.  See the License for the
+16   *  specific language governing permissions and limitations
+17   *  under the License.
+18   *
+19   */
+20  package org.apache.directory.mavibot.btree;
+21  
+22  
+23  import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
+24  
+25  
+26  /**
+27   * The B+Tree Configuration. This class can be used to store all the configurable
+28   * parameters used by the BTree class
+29   * 
+30   * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+31   * 
+32   * @param <K> The type for the keys
+33   * @param <V> The type for the stored values
+34   */
+35  public class BTreeConfiguration<K, V>
+36  {
+37      /** Number of entries in each Page. */
+38      private int pageSize = BTree.DEFAULT_PAGE_SIZE;
+39  
+40      /** The size of the buffer used to write data in disk */
+41      private int writeBufferSize = BTree.DEFAULT_WRITE_BUFFER_SIZE;
+42  
+43      /** The Key and Value serializer used for this tree. If none is provided, 
+44       * the BTree will deduce the serializer to use from the generic type, and
+45       * use the default Java serialization  */
+46      private ElementSerializer<K> keySerializer;
+47      private ElementSerializer<V> valueSerializer;
+48  
+49      /** The BTree name */
+50      private String name;
+51  
+52      /** The path where the BTree file will be stored. Default to the local 
+53       * temporary directory.
+54       */
+55      private String filePath;
+56  
+57      /** 
+58       * The maximum delay to wait before a revision is considered as unused.
+59       * This delay is necessary so that a read that does not ends does not 
+60       * hold a revision in memory forever.
+61       * The default value is 10000 (10 seconds). If the value is 0 or below,
+62       * the delay is considered as infinite
+63       */
+64      private long readTimeOut = BTree.DEFAULT_READ_TIMEOUT;
+65  
+66      /** The maximal size of the journal. When this size is reached, the tree is 
+67       * flushed on disk.
+68       * The default size is 10 Mb
+69       */
+70      private long journalSize = 10 * 1024 * 1024L;
+71  
+72      /**
+73       * The journal's name. Default to "mavibot.log".
+74       */
+75      private String journalName = BTree.DEFAULT_JOURNAL;
+76  
+77      /** 
+78       * The delay between two checkpoints. When we reach the maximum delay,
+79       * the BTree is flushed on disk, but only if we have had some modifications.
+80       * The default value is 60 seconds.
+81       */
+82      private long checkPointDelay = 60 * 1000L;
+83  
+84      /** Flag to enable duplicate key support */
+85      private boolean allowDuplicates;
+86  
+87      /** the type of BTree */
+88      private BTreeTypeEnum type;
+89      
+90      /**
+91       * @return the pageSize
+92       */
+93      public int getPageSize()
+94      {
+95          return pageSize;
+96      }
+97  
+98  
+99      /**
+100      * @param pageSize the pageSize to set
+101      */
+102     public void setPageSize( int pageSize )
+103     {
+104         this.pageSize = pageSize;
+105     }
+106 
+107 
+108     /**
+109      * @return the key serializer
+110      */
+111     public ElementSerializer<K> getKeySerializer()
+112     {
+113         return keySerializer;
+114     }
+115 
+116 
+117     /**
+118      * @return the value serializer
+119      */
+120     public ElementSerializer<V> getValueSerializer()
+121     {
+122         return valueSerializer;
+123     }
+124 
+125 
+126     /**
+127      * @param keySerializer the key serializer to set
+128      * @param valueSerializer the value serializer to set
+129      */
+130     public void setSerializers( ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
+131     {
+132         this.keySerializer = keySerializer;
+133         this.valueSerializer = valueSerializer;
+134     }
+135 
+136 
+137     /**
+138      * @param serializer the key serializer to set
+139      */
+140     public void setKeySerializer( ElementSerializer<K> keySerializer )
+141     {
+142         this.keySerializer = keySerializer;
+143     }
+144 
+145 
+146     /**
+147      * @param serializer the key serializer to set
+148      */
+149     public void setValueSerializer( ElementSerializer<V> valueSerializer )
+150     {
+151         this.valueSerializer = valueSerializer;
+152     }
+153 
+154 
+155     /**
+156      * @return the readTimeOut
+157      */
+158     public long getReadTimeOut()
+159     {
+160         return readTimeOut;
+161     }
+162 
+163 
+164     /**
+165      * @param readTimeOut the readTimeOut to set
+166      */
+167     public void setReadTimeOut( long readTimeOut )
+168     {
+169         this.readTimeOut = readTimeOut;
+170     }
+171 
+172 
+173     /**
+174      * @return the journalSize
+175      */
+176     public long getJournalSize()
+177     {
+178         return journalSize;
+179     }
+180 
+181 
+182     /**
+183      * @param journalSize the journalSize to set
+184      */
+185     public void setJournalSize( long journalSize )
+186     {
+187         this.journalSize = journalSize;
+188     }
+189 
+190 
+191     /**
+192      * @return the checkPointDelay
+193      */
+194     public long getCheckPointDelay()
+195     {
+196         return checkPointDelay;
+197     }
+198 
+199 
+200     /**
+201      * @param checkPointDelay the checkPointDelay to set
+202      */
+203     public void setCheckPointDelay( long checkPointDelay )
+204     {
+205         this.checkPointDelay = checkPointDelay;
+206     }
+207 
+208 
+209     /**
+210      * @return the filePath
+211      */
+212     public String getFilePath()
+213     {
+214         return filePath;
+215     }
+216 
+217 
+218     /**
+219      * @param filePath the filePath to set
+220      */
+221     public void setFilePath( String filePath )
+222     {
+223         this.filePath = filePath;
+224     }
+225 
+226 
+227     /**
+228      * @return the journal name
+229      */
+230     public String getJournalName()
+231     {
+232         return journalName;
+233     }
+234 
+235 
+236     /**
+237      * @param journalName the journal name to set
+238      */
+239     public void setJournalName( String journalName )
+240     {
+241         this.journalName = journalName;
+242     }
+243 
+244 
+245     /**
+246      * @return the writeBufferSize
+247      */
+248     public int getWriteBufferSize()
+249     {
+250         return writeBufferSize;
+251     }
+252 
+253 
+254     /**
+255      * @param writeBufferSize the writeBufferSize to set
+256      */
+257     public void setWriteBufferSize( int writeBufferSize )
+258     {
+259         this.writeBufferSize = writeBufferSize;
+260     }
+261 
+262 
+263     /**
+264      * @return the name
+265      */
+266     public String getName()
+267     {
+268         return name;
+269     }
+270 
+271 
+272     /**
+273      * @param name the name to set
+274      */
+275     public void setName( String name )
+276     {
+277         this.name = name.trim();
+278     }
+279 
+280     
+281     /**
+282      * @return true if duplicate key support is enabled
+283      */
+284     public boolean isAllowDuplicates()
+285     {
+286         return allowDuplicates;
+287     }
+288 
+289 
+290     /**
+291      * enable duplicate key support
+292      * 
+293      * @param allowDuplicates
+294      * @throws IllegalStateException if the btree was already initialized or when tried to turn off duplicate suport on
+295      *                               an existing btree containing duplicate keys
+296      */
+297     public void setAllowDuplicates( boolean allowDuplicates )
+298     {
+299         this.allowDuplicates = allowDuplicates;
+300     }
+301 
+302 
+303     /**
+304      * @return the type of BTree
+305      */
+306     public BTreeTypeEnum getType()
+307     {
+308         return type;
+309     }
+310 
+311 
+312     /**
+313      * Sets the type of the BTree
+314      * 
+315      * @param type the type of the tree
+316      */
+317     public void setType( BTreeTypeEnum type )
+318     {
+319         this.type = type;
+320     }
+321 
+322 }
+
+
+ +