directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1550580 [2/3] - in /directory/mavibot/trunk/mavibot/src: main/java/org/apache/directory/mavibot/btree/ main/java/org/apache/directory/mavibot/btree/managed/ main/java/org/apache/directory/mavibot/btree/memory/ test/java/org/apache/director...
Date Thu, 12 Dec 2013 23:08:29 GMT
Copied: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/PersistedBTree.java (from r1550413, directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/BTree.java)
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/PersistedBTree.java?p2=directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/PersistedBTree.java&p1=directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/BTree.java&r1=1550413&r2=1550580&rev=1550580&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/BTree.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/PersistedBTree.java Thu Dec 12 23:08:28 2013
@@ -24,26 +24,24 @@ import java.io.Closeable;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
-import java.util.Comparator;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.locks.ReentrantLock;
 
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.config.CacheConfiguration;
 
+import org.apache.directory.mavibot.btree.AbstractBTree;
+import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.BTreeHeader;
 import org.apache.directory.mavibot.btree.DeleteResult;
 import org.apache.directory.mavibot.btree.InsertResult;
 import org.apache.directory.mavibot.btree.ModifyResult;
 import org.apache.directory.mavibot.btree.NotPresentResult;
 import org.apache.directory.mavibot.btree.Page;
-import org.apache.directory.mavibot.btree.ParentPos;
 import org.apache.directory.mavibot.btree.RemoveResult;
 import org.apache.directory.mavibot.btree.SplitResult;
 import org.apache.directory.mavibot.btree.Transaction;
 import org.apache.directory.mavibot.btree.Tuple;
-import org.apache.directory.mavibot.btree.TupleCursor;
-import org.apache.directory.mavibot.btree.ValueCursor;
 import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
 import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
 import org.slf4j.Logger;
@@ -58,68 +56,14 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class BTree<K, V> implements Closeable
+public class PersistedBTree<K, V> extends AbstractBTree<K, V> implements Closeable
 {
     /** The LoggerFactory used by this class */
-    protected static final Logger LOG = LoggerFactory.getLogger( BTree.class );
-
-    /** The Header for a managed BTree */
-    private BTreeHeader btreeHeader;
-
-    /** Default page size (number of entries per node) */
-    public static final int DEFAULT_PAGE_SIZE = 16;
-
-    /** Default size of the buffer used to write data on disk. Around 1Mb */
-    public static final int DEFAULT_WRITE_BUFFER_SIZE = 4096 * 250;
-
-    /** The default journal name */
-    public static final String DEFAULT_JOURNAL = "mavibot.log";
-
-    /** The default data file suffix */
-    public static final String DATA_SUFFIX = ".db";
-
-    /** The default journal file suffix */
-    public static final String JOURNAL_SUFFIX = ".log";
-
-    /** The current rootPage */
-    protected volatile Page<K, V> rootPage;
-
-    /** The list of read transactions being executed */
-    private ConcurrentLinkedQueue<Transaction<K, V>> readTransactions;
-
-    /** The size of the buffer used to write data in disk */
-    private int writeBufferSize;
-
-    /** The Key serializer used for this tree.*/
-    private ElementSerializer<K> keySerializer;
-
-    /** The Value serializer used for this tree. */
-    private ElementSerializer<V> valueSerializer;
+    protected static final Logger LOG = LoggerFactory.getLogger( PersistedBTree.class );
 
     /** The RecordManager if the BTree is managed */
     private RecordManager recordManager;
 
-    /** A lock used to protect the write operation against concurrent access */
-    private ReentrantLock writeLock;
-
-    /** The thread responsible for the cleanup of timed out reads */
-    private Thread readTransactionsThread;
-
-    /** Define a default delay for a read transaction. This is 10 seconds */
-    public static final long DEFAULT_READ_TIMEOUT = 10 * 1000L;
-
-    /** The read transaction timeout */
-    private long readTimeOut = DEFAULT_READ_TIMEOUT;
-
-    /** The cache associated with this BTree */
-    private Cache cache;
-
-    /** The cache size, default to 1000 elements */
-    private int cacheSize = DEFAULT_CACHE_SIZE;
-
-    /** The default number of pages to keep in memory */
-    private static final int DEFAULT_CACHE_SIZE = 1000;
-    
     /** A flag indicating if this BTree is a Sub BTree */
     private boolean isSubBtree = false;
 
@@ -133,82 +77,11 @@ public class BTree<K, V> implements Clos
     /*No qualifier*/static int valueThresholdUp = DEFAULT_VALUE_THRESHOLD_UP;
     /*No qualifier*/static int valueThresholdLow = DEFAULT_VALUE_THRESHOLD_LOW;
 
-    /**
-     * Create a thread that is responsible of cleaning the transactions when
-     * they hit the timeout
-     */
-    private void createTransactionManager()
-    {
-        Runnable readTransactionTask = new Runnable()
-        {
-            public void run()
-            {
-                try
-                {
-                    Transaction<K, V> transaction = null;
-
-                    while ( !Thread.currentThread().isInterrupted() )
-                    {
-                        long timeoutDate = System.currentTimeMillis() - readTimeOut;
-                        long t0 = System.currentTimeMillis();
-                        int nbTxns = 0;
-
-                        // Loop on all the transactions from the queue
-                        while ( ( transaction = readTransactions.peek() ) != null )
-                        {
-                            nbTxns++;
-
-                            if ( transaction.isClosed() )
-                            {
-                                // The transaction is already closed, remove it from the queue
-                                readTransactions.poll();
-                                continue;
-                            }
-
-                            // Check if the transaction has timed out
-                            if ( transaction.getCreationDate() < timeoutDate )
-                            {
-                                transaction.close();
-                                readTransactions.poll();
-                                continue;
-                            }
-
-                            // We need to stop now
-                            break;
-                        }
-
-                        long t1 = System.currentTimeMillis();
-
-                        if ( nbTxns > 0 )
-                        {
-                            System.out.println( "Processing old txn : " + nbTxns + ", " + ( t1 - t0 ) + "ms" );
-                        }
-
-                        // Wait until we reach the timeout
-                        Thread.sleep( readTimeOut );
-                    }
-                }
-                catch ( InterruptedException ie )
-                {
-                    //System.out.println( "Interrupted" );
-                }
-                catch ( Exception e )
-                {
-                    throw new RuntimeException( e );
-                }
-            }
-        };
-
-        readTransactionsThread = new Thread( readTransactionTask );
-        readTransactionsThread.setDaemon( true );
-        readTransactionsThread.start();
-    }
-
 
     /**
      * Creates a new BTree, with no initialization. 
      */
-    public BTree()
+    public PersistedBTree()
     {
         btreeHeader = new BTreeHeader();
     }
@@ -220,8 +93,9 @@ public class BTree<K, V> implements Clos
      * 
      * @param comparator The comparator to use
      */
-    public BTree( BTreeConfiguration<K, V> configuration ) throws IOException
+    public PersistedBTree( BTreeConfiguration<K, V> configuration )
     {
+        super();
         String name = configuration.getName();
 
         if ( name == null )
@@ -257,8 +131,8 @@ public class BTree<K, V> implements Clos
         if ( isSubBtree )
         {
             // The subBTree inherit its cache from its parent BTree
-            this.cache = configuration.getParentBTree().getCache();
-            this.writeLock = configuration.getParentBTree().getWriteLock();
+            this.cache = ((PersistedBTree<K, V>)configuration.getParentBTree()).getCache();
+            this.writeLock = ((PersistedBTree<K, V>)configuration.getParentBTree()).getWriteLock();
             readTransactions = new ConcurrentLinkedQueue<Transaction<K, V>>();
         }
 
@@ -272,24 +146,21 @@ public class BTree<K, V> implements Clos
      * 
      * @param comparator The comparator to use
      */
-    public BTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
-        throws IOException
+    public PersistedBTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
     {
         this( name, keySerializer, valueSerializer, false );
     }
 
 
-    public BTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer,
+    public PersistedBTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer,
         boolean allowDuplicates )
-        throws IOException
     {
         this( name, null, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE, allowDuplicates, DEFAULT_CACHE_SIZE );
     }
 
 
-    public BTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer,
+    public PersistedBTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer,
         boolean allowDuplicates, int cacheSize )
-        throws IOException
     {
         this( name, null, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE, allowDuplicates, cacheSize );
     }
@@ -300,8 +171,7 @@ public class BTree<K, V> implements Clos
      * 
      * @param comparator The comparator to use
      */
-    public BTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, int pageSize )
-        throws IOException
+    public PersistedBTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, int pageSize )
     {
         this( name, null, keySerializer, valueSerializer, pageSize );
     }
@@ -312,8 +182,7 @@ public class BTree<K, V> implements Clos
      * @param comparator The comparator to use
      * @param serializer The serializer to use
      */
-    public BTree( String name, String path, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
-        throws IOException
+    public PersistedBTree( String name, String path, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
     {
         this( name, path, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE );
     }
@@ -330,29 +199,25 @@ public class BTree<K, V> implements Clos
      * @param pageSize size of the page
      * @throws IOException
      */
-    public BTree( String name, String dataDir, ElementSerializer<K> keySerializer,
-        ElementSerializer<V> valueSerializer,
-        int pageSize )
-        throws IOException
+    public PersistedBTree( String name, String dataDir, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer, int pageSize )
     {
         this( name, dataDir, keySerializer, valueSerializer, pageSize, false, DEFAULT_CACHE_SIZE );
     }
 
 
-    public BTree( String name, String dataDir, ElementSerializer<K> keySerializer,
-        ElementSerializer<V> valueSerializer,
-        int pageSize, boolean allowDuplicates )
-        throws IOException
+    public PersistedBTree( String name, String dataDir, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer, int pageSize, boolean allowDuplicates )
     {
         this( name, dataDir, keySerializer, valueSerializer, pageSize, allowDuplicates, DEFAULT_CACHE_SIZE );
     }
 
 
-    public BTree( String name, String dataDir, ElementSerializer<K> keySerializer,
-        ElementSerializer<V> valueSerializer,
-        int pageSize, boolean allowDuplicates, int cacheSize )
-        throws IOException
+    public PersistedBTree( String name, String dataDir, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer, int pageSize, boolean allowDuplicates, int cacheSize )
     {
+        super();
+
         btreeHeader = new BTreeHeader();
         btreeHeader.setName( name );
 
@@ -385,7 +250,7 @@ public class BTree<K, V> implements Clos
      * 
      * @throws IOException If we get some exception while initializing the BTree
      */
-    public void init() throws IOException
+    public void init()
     {
         if ( !isSubBtree )
         {
@@ -510,58 +375,6 @@ public class BTree<K, V> implements Clos
 
 
     /**
-     * Gets the number which is a power of 2 immediately above the given positive number.
-     */
-    private int getPowerOf2( int size )
-    {
-        int newSize = --size;
-        newSize |= newSize >> 1;
-        newSize |= newSize >> 2;
-        newSize |= newSize >> 4;
-        newSize |= newSize >> 8;
-        newSize |= newSize >> 16;
-        newSize++;
-
-        return newSize;
-    }
-
-
-    /**
-     * Set the maximum number of elements we can store in a page. This must be a
-     * number greater than 1, and a power of 2. The default page size is 16.
-     * <br/>
-     * If the provided size is below 2, we will default to DEFAULT_PAGE_SIZE.<br/>
-     * If the provided size is not a power of 2, we will select the closest power of 2
-     * higher than the given number<br/>
-     * 
-     * @param pageSize The requested page size
-     */
-    public void setPageSize( int pageSize )
-    {
-        if ( pageSize <= 2 )
-        {
-            btreeHeader.setPageSize( DEFAULT_PAGE_SIZE );
-        }
-        else
-        {
-            btreeHeader.setPageSize( getPowerOf2( pageSize ) );
-        }
-    }
-
-
-    /**
-     * Set the new root page for this tree. Used for debug purpose only. The revision
-     * will always be 0;
-     * 
-     * @param root the new root page.
-     */
-    /* No qualifier */void setRoot( Page<K, V> root )
-    {
-        rootPage = root;
-    }
-
-
-    /**
      * Gets the RecordManager for a managed BTree
      * 
      * @return The recordManager if the BTree is managed
@@ -584,131 +397,6 @@ public class BTree<K, V> implements Clos
 
 
     /**
-     * @return the pageSize
-     */
-    public int getPageSize()
-    {
-        return btreeHeader.getPageSize();
-    }
-
-
-    /**
-     * Generates a new revision number. It's only used by the Page instances.
-     * 
-     * @return a new incremental revision number
-     */
-    /** No qualifier */
-    long generateRevision()
-    {
-        return btreeHeader.incrementRevision();
-    }
-
-
-    /**
-     * Insert an entry in the BTree.
-     * <p>
-     * We will replace the value if the provided key already exists in the
-     * btree.
-     *
-     * @param key Inserted key
-     * @param value Inserted value
-     * @return Existing value, if any.
-     * @throws IOException TODO
-     */
-    public V insert( K key, V value ) throws IOException
-    {
-        long revision = generateRevision();
-
-        V existingValue = null;
-
-        try
-        {
-            // Commented atm, we will have to play around the idea of transactions later
-            writeLock.lock();
-
-            InsertResult<K, V> result = insert( key, value, revision );
-
-            if ( result instanceof ModifyResult )
-            {
-                existingValue = ( ( ModifyResult<K, V> ) result ).getModifiedValue();
-            }
-        }
-        finally
-        {
-            // See above
-            writeLock.unlock();
-        }
-
-        return existingValue;
-    }
-
-
-    /**
-     * Delete the entry which key is given as a parameter. If the entry exists, it will
-     * be removed from the tree, the old tuple will be returned. Otherwise, null is returned.
-     * 
-     * @param key The key for the entry we try to remove
-     * @return A Tuple<K, V> containing the removed entry, or null if it's not found.
-     */
-    public Tuple<K, V> delete( K key ) throws IOException
-    {
-        if ( key == null )
-        {
-            throw new IllegalArgumentException( "Key must not be null" );
-        }
-
-        long revision = generateRevision();
-
-        Tuple<K, V> deleted = delete( key, revision );
-
-        return deleted;
-    }
-
-
-    /**
-     * Delete the value from an entry associated with the given key. If the value
-     * If the value is present, it will be deleted first, later if there are no other 
-     * values associated with this key(which can happen when duplicates are enabled), 
-     * we will remove the key from the tree.
-     * 
-     * @param key The key for the entry we try to remove
-     * @param value The value to delete (can be null)
-     * @return A Tuple<K, V> containing the removed entry, or null if it's not found.
-     */
-    public Tuple<K, V> delete( K key, V value ) throws IOException
-    {
-        if ( key == null )
-        {
-            throw new IllegalArgumentException( "Key must not be null" );
-        }
-
-        if ( value == null )
-        {
-            throw new IllegalArgumentException( "Value must not be null" );
-        }
-
-        long revision = generateRevision();
-
-        Tuple<K, V> deleted = delete( key, value, revision );
-
-        return deleted;
-    }
-
-
-    /**
-     * Delete the entry which key is given as a parameter. If the entry exists, it will
-     * be removed from the tree, the old tuple will be returned. Otherwise, null is returned.
-     * 
-     * @param key The key for the entry we try to remove
-     * @return A Tuple<K, V> containing the removed entry, or null if it's not found.
-     */
-    private Tuple<K, V> delete( K key, long revision ) throws IOException
-    {
-        return delete( key, null, revision );
-    }
-
-
-    /**
      * 
      * Deletes the given <key,value> pair if both key and value match. If the given value is null
      * and there is no null value associated with the given key then the entry with the given key
@@ -720,7 +408,7 @@ public class BTree<K, V> implements Clos
      * @return
      * @throws IOException
      */
-    private Tuple<K, V> delete( K key, V value, long revision ) throws IOException
+    protected Tuple<K, V> delete( K key, V value, long revision ) throws IOException
     {
         writeLock.lock();
 
@@ -800,211 +488,6 @@ public class BTree<K, V> implements Clos
 
 
     /**
-     * Find a value in the tree, given its key. If the key is not found,
-     * it will throw a KeyNotFoundException. <br/>
-     * Note that we can get a null value stored, or many values.
-     * 
-     * @param key The key we are looking at
-     * @return The found value, or null if the key is not present in the tree
-     * @throws KeyNotFoundException If the key is not found in the BTree
-     * @throws IOException TODO
-     */
-    public V get( K key ) throws IOException, KeyNotFoundException
-    {
-        return rootPage.get( key );
-    }
-
-
-    /**
-     * @see Page#getValues(Object)
-     */
-    public ValueCursor<V> getValues( K key ) throws IOException, KeyNotFoundException
-    {
-        return rootPage.getValues( key );
-    }
-
-
-    /**
-     * Find a value in the tree, given its key, at a specific revision. If the key is not found,
-     * it will throw a KeyNotFoundException. <br/>
-     * Note that we can get a null value stored, or many values.
-     * 
-     * @param revision The revision for which we want to find a key
-     * @param key The key we are looking at
-     * @return The found value, or null if the key is not present in the tree
-     * @throws KeyNotFoundException If the key is not found in the BTree
-     * @throws IOException If there was an issue while fetching data from the disk
-     */
-    public V get( long revision, K key ) throws IOException, KeyNotFoundException
-    {
-        // Fetch the root page for this revision
-        Page<K, V> revisionRootPage = getRootPage( revision );
-
-        return revisionRootPage.get( key );
-    }
-
-
-    /**
-     * Checks if the given key exists.
-     *  
-     * @param key The key we are looking at
-     * @return true if the key is present, false otherwise
-     * @throws IOException If we have an error while trying to access the page
-     */
-    public boolean hasKey( K key ) throws IOException
-    {
-        if ( key == null )
-        {
-            return false;
-        }
-
-        return rootPage.hasKey( key );
-    }
-
-
-    /**
-     * Checks if the given key exists for a given revision.
-     *  
-     * @param revision The revision for which we want to find a key
-     * @param key The key we are looking at
-     * @return true if the key is present, false otherwise
-     * @throws IOException If we have an error while trying to access the page
-     * @throws KeyNotFoundException If the key is not found in the BTree
-     */
-    public boolean hasKey( long revision, K key ) throws IOException, KeyNotFoundException
-    {
-        if ( key == null )
-        {
-            return false;
-        }
-
-        // Fetch the root page for this revision
-        Page<K, V> revisionRootPage = getRootPage( revision );
-
-        return revisionRootPage.hasKey( key );
-    }
-
-
-    /**
-     * Checks if the BTree contains the given key with the given value.
-     * 
-     * @param key The key we are looking for
-     * @param value The value associated with the given key
-     * @return true if the key and value are associated with each other, false otherwise
-     */
-    public boolean contains( K key, V value ) throws IOException
-    {
-        return rootPage.contains( key, value );
-    }
-
-
-    /**
-     * Checks if the BTree contains the given key with the given value for a given revision
-     * 
-     * @param revision The revision we would like to browse
-     * @param key The key we are looking for
-     * @param value The value associated with the given key
-     * @return true if the key and value are associated with each other, false otherwise
-     * @throws KeyNotFoundException If the key is not found in the BTree
-     */
-    public boolean contains( long revision, K key, V value ) throws IOException, KeyNotFoundException
-    {
-        // Fetch the root page for this revision
-        Page<K, V> revisionRootPage = getRootPage( revision );
-
-        return revisionRootPage.contains( key, value );
-    }
-
-
-    /**
-     * Creates a cursor starting at the beginning of the tree
-     * 
-     * @return A cursor on the btree
-     * @throws IOException
-     */
-    public TupleCursor<K, V> browse() throws IOException
-    {
-        Transaction<K, V> transaction = beginReadTransaction();
-
-        // Fetch the root page for this revision
-        ParentPos<K, V>[] stack = new ParentPos[32];
-        TupleCursor<K, V> cursor = rootPage.browse( transaction, stack, 0 );
-        
-        // Set the position before the first element
-        cursor.beforeFirst();
-
-        return cursor;
-    }
-
-
-    /**
-     * Creates a cursor starting at the beginning of the tree, for a given revision
-     * 
-     * @param revision The revision we would like to browse
-     * @return A cursor on the btree
-     * @throws IOException If we had an issue while fetching data from the disk
-     * @throws KeyNotFoundException If the key is not found in the BTree
-     */
-    public TupleCursor<K, V> browse( long revision ) throws IOException, KeyNotFoundException
-    {
-        Transaction<K, V> transaction = beginReadTransaction();
-
-        // Fetch the root page for this revision
-        Page<K, V> revisionRootPage = getRootPage( revision );
-
-        // And get the cursor
-        TupleCursor<K, V> cursor = revisionRootPage.browse( transaction, new ParentPos[32], 0 );
-
-        return cursor;
-    }
-
-
-    /**
-     * Creates a cursor starting on the given key
-     * 
-     * @param key The key which is the starting point. If the key is not found,
-     * then the cursor will always return null.
-     * @return A cursor on the btree
-     * @throws IOException
-     */
-    public TupleCursor<K, V> browseFrom( K key ) throws IOException
-    {
-        Transaction<K, V> transaction = beginReadTransaction();
-
-        // Fetch the root page for this revision
-        @SuppressWarnings("unchecked")
-        ParentPos<K, V>[] stack = new ParentPos[32];
-        TupleCursor<K, V> cursor = rootPage.browse( key, transaction, stack, 0 );
-
-        return cursor;
-    }
-
-
-    /**
-     * Creates a cursor starting on the given key at the given revision
-     * 
-     * @param The revision we are looking for
-     * @param key The key which is the starting point. If the key is not found,
-     * then the cursor will always return null.
-     * @return A cursor on the btree
-     * @throws IOException If wxe had an issue reading the BTree from disk
-     * @throws KeyNotFoundException  If we can't find a rootPage for this revision
-     */
-    public TupleCursor<K, V> browseFrom( long revision, K key ) throws IOException, KeyNotFoundException
-    {
-        Transaction<K, V> transaction = beginReadTransaction();
-
-        // Fetch the rootPage for this revision
-        Page<K, V> revisionRootPage = getRootPage( revision );
-
-        // And get the cursor
-        TupleCursor<K, V> cursor = revisionRootPage.browse( key, transaction, new ParentPos[32], 0 );
-
-        return cursor;
-    }
-
-
-    /**
      * Insert an entry in the BTree.
      * <p>
      * We will replace the value if the provided key already exists in the
@@ -1017,7 +500,7 @@ public class BTree<K, V> implements Clos
      * @param revision The revision to use
      * @return an instance of the InsertResult.
      */
-    /*No qualifier*/InsertResult<K, V> insert( K key, V value, long revision ) throws IOException
+    public InsertResult<K, V> insert( K key, V value, long revision ) throws IOException
     {
         if ( key == null )
         {
@@ -1107,51 +590,6 @@ public class BTree<K, V> implements Clos
 
 
     /**
-     * Starts a Read Only transaction. If the transaction is not closed, it will be 
-     * automatically closed after the timeout
-     * @return The created transaction
-     */
-    private Transaction<K, V> beginReadTransaction()
-    {
-        Transaction<K, V> readTransaction = new Transaction<K, V>( rootPage, btreeHeader.getRevision() - 1,
-            System.currentTimeMillis() );
-
-        readTransactions.add( readTransaction );
-
-        return readTransaction;
-    }
-
-
-    /**
-     * @return the comparator
-     */
-    public Comparator<K> getComparator()
-    {
-        return keySerializer.getComparator();
-    }
-
-
-    /**
-     * @param keySerializer the Key serializer to set
-     */
-    public void setKeySerializer( ElementSerializer<K> keySerializer )
-    {
-        this.keySerializer = keySerializer;
-        btreeHeader.setKeySerializerFQCN( keySerializer.getClass().getName() );
-    }
-
-
-    /**
-     * @param valueSerializer the Value serializer to set
-     */
-    public void setValueSerializer( ElementSerializer<V> valueSerializer )
-    {
-        this.valueSerializer = valueSerializer;
-        btreeHeader.setValueSerializerFQCN( valueSerializer.getClass().getName() );
-    }
-
-
-    /**
      * Write the data in the ByteBuffer, and eventually on disk if needed.
      * 
      * @param channel The channel we want to write to
@@ -1200,7 +638,7 @@ public class BTree<K, V> implements Clos
      * @throws IOException If we had an issue while accessing the underlying file
      * @throws KeyNotFoundException If the revision does not exist for this Btree
      */
-    private Page<K, V> getRootPage( long revision ) throws IOException, KeyNotFoundException
+    public Page<K, V> getRootPage( long revision ) throws IOException, KeyNotFoundException
     {
         return recordManager.getRootPage( this, revision );
     }
@@ -1216,169 +654,11 @@ public class BTree<K, V> implements Clos
 
 
     /**
-     * @return the readTimeOut
-     */
-    public long getReadTimeOut()
-    {
-        return readTimeOut;
-    }
-
-
-    /**
-     * @param readTimeOut the readTimeOut to set
-     */
-    public void setReadTimeOut( long readTimeOut )
-    {
-        this.readTimeOut = readTimeOut;
-    }
-
-
-    /**
-     * @return the name
+     * @return the type for the keys
      */
-    public String getName()
+    public Class<?> getKeyType()
     {
-        return btreeHeader.getName();
-    }
-
-
-    /**
-     * @param name the name to set
-     */
-    public void setName( String name )
-    {
-        btreeHeader.setName( name );
-    }
-
-
-    /**
-     * @return the writeBufferSize
-     */
-    public int getWriteBufferSize()
-    {
-        return writeBufferSize;
-    }
-
-
-    /**
-     * @param writeBufferSize the writeBufferSize to set
-     */
-    public void setWriteBufferSize( int writeBufferSize )
-    {
-        this.writeBufferSize = writeBufferSize;
-    }
-
-
-    /**
-     * Create a ValueHolder depending on the kind of holder we want.
-     * 
-     * @param value The value to store
-     * @return The value holder
-     */
-    @SuppressWarnings("unchecked")
-    /* no qualifier */ValueHolder<V> createValueHolder( V value )
-    {
-        return new ValueHolder<V>( this, value );
-    }
-
-
-    /**
-     * Create a ValueHolder depending on the kind of holder we want.
-     * 
-     * @param value The value to store
-     * @return The value holder
-     */
-    /* no qualifier */PageHolder<K, V> createPageHolder( Page<K, V> value )
-    {
-        return new PageHolder<K, V>( this, value,
-            value.getOffset(), value.getLastOffset() );
-    }
-
-
-    /**
-     * @return the keySerializer
-     */
-    public ElementSerializer<K> getKeySerializer()
-    {
-        return keySerializer;
-    }
-
-
-    /**
-     * @return the keySerializer FQCN
-     */
-    public String getKeySerializerFQCN()
-    {
-        return btreeHeader.getKeySerializerFQCN();
-    }
-
-
-    /**
-     * @return the valueSerializer
-     */
-    public ElementSerializer<V> getValueSerializer()
-    {
-        return valueSerializer;
-    }
-
-
-    /**
-     * @return the valueSerializer FQCN
-     */
-    public String getValueSerializerFQCN()
-    {
-        return btreeHeader.getValueSerializerFQCN();
-    }
-
-
-    /** 
-     * @return The current BTree revision
-     */
-    public long getRevision()
-    {
-        return btreeHeader.getRevision();
-    }
-
-
-    /**
-     * @param revision the revision to set
-     */
-    /* No qualifier */void setRevision( long revision )
-    {
-        btreeHeader.setRevision( revision );
-    }
-
-
-    /** 
-     * @return The current number of elements in the BTree
-     */
-    public long getNbElems()
-    {
-        return btreeHeader.getNbElems();
-    }
-
-
-    /**
-     * @param nbElems the nbElems to set
-     */
-    /* No qualifier */void setNbElems( long nbElems )
-    {
-        btreeHeader.setNbElems( nbElems );
-    }
-
-
-    /**
-     * @return true if this BTree allow duplicate values
-     */
-    public boolean isAllowDuplicates()
-    {
-        return btreeHeader.isAllowDuplicates();
-    }
-
-
-    /* No qualifier */void setAllowDuplicates( boolean allowDuplicates )
-    {
-        btreeHeader.setAllowDuplicates( allowDuplicates );
+        return KeyHolder.class;
     }
 
 

Copied: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/PersistedBTreeBuilder.java (from r1550046, directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ManagedBTreeBuilder.java)
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/PersistedBTreeBuilder.java?p2=directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/PersistedBTreeBuilder.java&p1=directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ManagedBTreeBuilder.java&r1=1550046&r2=1550580&rev=1550580&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ManagedBTreeBuilder.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/PersistedBTreeBuilder.java Thu Dec 12 23:08:28 2013
@@ -33,6 +33,7 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.Page;
 import org.apache.directory.mavibot.btree.Tuple;
 import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
@@ -43,7 +44,7 @@ import org.apache.directory.mavibot.btre
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class ManagedBTreeBuilder<K, V>
+public class PersistedBTreeBuilder<K, V>
 {
     private String name;
 
@@ -55,7 +56,7 @@ public class ManagedBTreeBuilder<K, V>
 
     private RecordManager rm;
 
-    public ManagedBTreeBuilder( RecordManager rm, String name, int numKeysInNode, ElementSerializer<K> keySerializer,
+    public PersistedBTreeBuilder( RecordManager rm, String name, int numKeysInNode, ElementSerializer<K> keySerializer,
         ElementSerializer<V> valueSerializer )
     {
         this.rm = rm;
@@ -69,7 +70,7 @@ public class ManagedBTreeBuilder<K, V>
     @SuppressWarnings("unchecked")
     public BTree<K, V> build( Iterator<Tuple<K, V>> sortedTupleItr ) throws Exception
     {
-        BTree<K, V> btree = new BTree<K, V>( name, keySerializer, valueSerializer );
+        BTree<K, V> btree = new PersistedBTree<K, V>( name, keySerializer, valueSerializer );
         btree.init();
 
         rm.manage( btree );
@@ -141,13 +142,13 @@ public class ManagedBTreeBuilder<K, V>
         Page<K, V> rootPage = attachNodes( lstLeaves, btree );
 
         //System.out.println("built rootpage : " + rootPage);
-        btree.setNbElems( totalTupleCount );
+        ((PersistedBTree<K, V>)btree).setNbElems( totalTupleCount );
         
         rm.updateBtreeHeader( btree, ( ( AbstractPage<K, V> ) rootPage ).getOffset() );
         
-        rm.addFreePages( btree, Arrays.asList( btree.rootPage ) );
+        rm.addFreePages( btree, Arrays.asList( btree.getRootPage() ) );
         
-        btree.rootPage = rootPage;
+        btree.setRootPage( rootPage );
         
         return btree;
     }
@@ -170,14 +171,14 @@ public class ManagedBTreeBuilder<K, V>
         int i = 0;
         int totalNodes = 0;
 
-        for ( Page<K, V> p : children )
+        for ( Page<K, V> page : children )
         {
             if ( i != 0 )
             {
-                setKey( node, i - 1, p.getLeftMostKey() );
+                setKey( node, i - 1, page.getLeftMostKey() );
             }
 
-            node.children[i] = btree.createPageHolder( p );
+            node.children[i] = new PageHolder<K, V>( btree, page );
 
             i++;
             totalNodes++;

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/RecordManager.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/RecordManager.java?rev=1550580&r1=1550579&r2=1550580&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/RecordManager.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/RecordManager.java Thu Dec 12 23:08:28 2013
@@ -33,6 +33,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
 
+import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.Page;
 import org.apache.directory.mavibot.btree.exception.BTreeAlreadyManagedException;
 import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
@@ -306,11 +307,11 @@ public class RecordManager
         endOfFileOffset = fileChannel.size();
 
         // Now, initialize the Copied Page BTree
-        copiedPageBTree = new BTree<RevisionName, long[]>( COPIED_PAGE_BTREE_NAME, new RevisionNameSerializer(),
+        copiedPageBTree = new PersistedBTree<RevisionName, long[]>( COPIED_PAGE_BTREE_NAME, new RevisionNameSerializer(),
             new LongArraySerializer() );
 
         // and initialize the Revision BTree
-        revisionBTree = new BTree<RevisionName, Long>( REVISION_BTREE_NAME, new RevisionNameSerializer(),
+        revisionBTree = new PersistedBTree<RevisionName, Long>( REVISION_BTREE_NAME, new RevisionNameSerializer(),
             new LongSerializer() );
 
         // Inject these BTrees into the RecordManager
@@ -367,26 +368,26 @@ public class RecordManager
 
             // Create the BTree
             copiedPageBTree = BTreeFactory.<RevisionName, long[]> createBTree();
-            copiedPageBTree.setBtreeOffset( btreeOffset );
+            ((PersistedBTree<RevisionName, long[]>)copiedPageBTree).setBtreeOffset( btreeOffset );
 
             loadBTree( pageIos, copiedPageBTree );
-            long nextBtreeOffset = copiedPageBTree.getNextBTreeOffset();
+            long nextBtreeOffset = ((PersistedBTree<RevisionName, long[]>)copiedPageBTree).getNextBTreeOffset();
 
             // And the Revision BTree
             pageIos = readPageIOs( nextBtreeOffset, Long.MAX_VALUE );
 
             revisionBTree = BTreeFactory.<RevisionName, Long> createBTree();
-            revisionBTree.setBtreeOffset( nextBtreeOffset );
+            ((PersistedBTree<RevisionName, Long>)revisionBTree).setBtreeOffset( nextBtreeOffset );
 
             loadBTree( pageIos, revisionBTree );
-            nextBtreeOffset = revisionBTree.getNextBTreeOffset();
+            nextBtreeOffset = ((PersistedBTree<RevisionName, Long>)revisionBTree).getNextBTreeOffset();
 
             // Then process the next ones
             for ( int i = 2; i < nbBtree; i++ )
             {
                 // Create the BTree
                 BTree<Object, Object> btree = BTreeFactory.createBTree();
-                btree.setBtreeOffset( nextBtreeOffset );
+                ((PersistedBTree<Object, Object>)btree).setBtreeOffset( nextBtreeOffset );
                 lastAddedBTreeOffset = nextBtreeOffset;
 
                 // Read the associated pages
@@ -394,7 +395,7 @@ public class RecordManager
 
                 // Load the BTree
                 loadBTree( pageIos, btree );
-                nextBtreeOffset = btree.getNextBTreeOffset();
+                nextBtreeOffset = ((PersistedBTree<Object, Object>)btree).getNextBTreeOffset();
 
                 // Store it into the managedBtrees map
                 managedBTrees.put( btree.getName(), btree );
@@ -529,7 +530,7 @@ public class RecordManager
 
         // The BTree allowDuplicates flag
         int allowDuplicates = readInt( pageIos, dataPos );
-        btree.setAllowDuplicates( allowDuplicates != 0 );
+        ((PersistedBTree<K, V>)btree).setAllowDuplicates( allowDuplicates != 0 );
         dataPos += INT_SIZE;
 
         // Now, init the BTree
@@ -545,7 +546,7 @@ public class RecordManager
         Page<K, V> btreeRoot = readPage( btree, rootPageIos );
         BTreeFactory.setRecordManager( btree, this );
 
-        BTreeFactory.setRoot( btree, btreeRoot );
+        BTreeFactory.setRootPage( btree, btreeRoot );
     }
 
 
@@ -1038,7 +1039,7 @@ public class RecordManager
 
         // Store the BTree Offset into the BTree
         long btreeOffset = pageIos[0].getOffset();
-        btree.setBtreeOffset( btreeOffset );
+        ((PersistedBTree<K, V>)btree).setBtreeOffset( btreeOffset );
 
         // Now store the BTree data in the pages :
         // - the BTree revision
@@ -1069,7 +1070,7 @@ public class RecordManager
 
         // Now, we can inject the BTree rootPage offset into the BTree header
         position = store( position, rootPageIo.getOffset(), pageIos );
-        btree.setRootPageOffset( rootPageIo.getOffset() );
+        ((PersistedBTree<K, V>)btree).setRootPageOffset( rootPageIo.getOffset() );
         ( ( Leaf<K, V> ) rootPage ).setOffset( rootPageIo.getOffset() );
 
         // The next BTree Header offset (-1L, as it's a new BTree)
@@ -1482,7 +1483,7 @@ public class RecordManager
         IOException
     {
         // Read the pageIOs associated with this BTree
-        long offset = btree.getBtreeOffset();
+        long offset = ((PersistedBTree<K, V>)btree).getBtreeOffset();
         long headerSize = LONG_SIZE + LONG_SIZE + LONG_SIZE;
 
         PageIO[] pageIos = readPageIOs( offset, headerSize );
@@ -2336,7 +2337,7 @@ public class RecordManager
         if ( btree.getRevision() == revision )
         {
             // We are asking for the current revision
-            return btree.rootPage;
+            return btree.getRootPage();
         }
 
         RevisionName revisionName = new RevisionName( revision, btree.getName() );
@@ -2533,7 +2534,7 @@ public class RecordManager
         config.setValueSerializer( valueSerializer );
         config.setAllowDuplicates( allowDuplicates );
 
-        BTree btree = new BTree( config );
+        BTree btree = new PersistedBTree( config );
         manage( btree );
 
         if ( LOG_CHECK.isDebugEnabled() )
@@ -3007,12 +3008,12 @@ public class RecordManager
         {
             PageIO[] pageIos = readPageIOs( offset, Long.MAX_VALUE );
 
-            BTree<K, V> dupValueContainer = BTreeFactory.createBTree();
-            dupValueContainer.setBtreeOffset( offset );
+            BTree<K, V> subBtree = BTreeFactory.createBTree();
+            ((PersistedBTree<K, V>)subBtree).setBtreeOffset( offset );
 
-            loadBTree( pageIos, dupValueContainer );
+            loadBTree( pageIos, subBtree );
 
-            return dupValueContainer;
+            return subBtree;
         }
         catch ( Exception e )
         {

Copied: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/TupleCursorImpl.java (from r1550046, directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/TupleCursorImpl.java)
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/TupleCursorImpl.java?p2=directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/TupleCursorImpl.java&p1=directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/TupleCursorImpl.java&r1=1550046&r2=1550580&rev=1550580&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/TupleCursorImpl.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/TupleCursorImpl.java Thu Dec 12 23:08:28 2013
@@ -23,6 +23,7 @@ package org.apache.directory.mavibot.btr
 import java.io.IOException;
 import java.util.NoSuchElementException;
 
+import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.Page;
 import org.apache.directory.mavibot.btree.ParentPos;
 import org.apache.directory.mavibot.btree.Transaction;

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ValueHolder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ValueHolder.java?rev=1550580&r1=1550579&r2=1550580&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ValueHolder.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/ValueHolder.java Thu Dec 12 23:08:28 2013
@@ -25,8 +25,10 @@ import java.lang.reflect.Array;
 import java.util.Comparator;
 import java.util.UUID;
 
+import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.Tuple;
 import org.apache.directory.mavibot.btree.TupleCursor;
+import org.apache.directory.mavibot.btree.ValueBTreeCursor;
 import org.apache.directory.mavibot.btree.ValueCursor;
 import org.apache.directory.mavibot.btree.exception.BTreeAlreadyManagedException;
 import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
@@ -82,7 +84,7 @@ public class ValueHolder<V> implements C
 
         // We create the array of values if they fit in an array. If they are stored in a 
         // BTree, we do nothing atm.
-        if ( nbValues <= BTree.valueThresholdUp )
+        if ( nbValues <= PersistedBTree.valueThresholdUp )
         {
             // The values are contained into an array
             valueArray = ( V[] ) Array.newInstance( valueSerializer.getType(), nbValues );
@@ -106,7 +108,7 @@ public class ValueHolder<V> implements C
         {
             int nbValues = values.length;
 
-            if ( nbValues < BTree.valueThresholdUp )
+            if ( nbValues < PersistedBTree.valueThresholdUp )
             {
                 // Keep an array
                 valueArray = ( V[] ) Array.newInstance( valueSerializer.getType(), nbValues );
@@ -162,7 +164,7 @@ public class ValueHolder<V> implements C
 
         if ( valueArray == null )
         {
-            cursor = new ValueBtreeCursor();
+            cursor = new ValueBTreeCursor<V>( valueBtree );
         }
         else
         {
@@ -316,191 +318,6 @@ public class ValueHolder<V> implements C
     }
 
     /**
-     * A class that encapsulate the values into an sub-btree
-     */
-    private class ValueBtreeCursor implements ValueCursor<V>
-    {
-        /** Store the current position in the array or in the BTree */
-        private TupleCursor<V, V> cursor;
-
-
-        /**
-         * Create an instance
-         */
-        private ValueBtreeCursor()
-        {
-            // Start at -1 to be positioned before the first element
-            try
-            {
-                if ( valueBtree != null )
-                {
-                    cursor = valueBtree.browse();
-                }
-            }
-            catch ( IOException e )
-            {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
-            }
-        }
-
-
-        /**
-         * {@inheritDoc}}
-         */
-        @Override
-        public boolean hasNext()
-        {
-            if ( cursor == null )
-            {
-                return false;
-            }
-            else
-            {
-                try
-                {
-                    return cursor.hasNext();
-                }
-                catch ( EndOfFileExceededException e )
-                {
-                    e.printStackTrace();
-                    return false;
-                }
-                catch ( IOException e )
-                {
-                    e.printStackTrace();
-                    return false;
-                }
-            }
-        }
-
-
-        /**
-         * {@inheritDoc}}
-         */
-        public V next()
-        {
-            try
-            {
-                return cursor.next().getKey();
-            }
-            catch ( EndOfFileExceededException e )
-            {
-                e.printStackTrace();
-                return null;
-            }
-            catch ( IOException e )
-            {
-                e.printStackTrace();
-                return null;
-            }
-        }
-
-
-        /**
-         * {@inheritDoc}}
-         */
-        @Override
-        public boolean hasPrev() throws EndOfFileExceededException, IOException
-        {
-            if ( cursor == null )
-            {
-                return false;
-            }
-            else
-            {
-                try
-                {
-                    return cursor.hasPrev();
-                }
-                catch ( EndOfFileExceededException e )
-                {
-                    e.printStackTrace();
-                    return false;
-                }
-                catch ( IOException e )
-                {
-                    e.printStackTrace();
-                    return false;
-                }
-            }
-        }
-
-
-        /**
-         * {@inheritDoc}}
-         */
-        @Override
-        public void close()
-        {
-            if ( cursor != null )
-            {
-                cursor.close();
-            }
-        }
-
-
-        /**
-         * {@inheritDoc}}
-         */
-        @Override
-        public void beforeFirst() throws IOException
-        {
-            if ( cursor != null )
-            {
-                cursor.beforeFirst();
-            }
-        }
-
-
-        /**
-         * {@inheritDoc}}
-         */
-        @Override
-        public void afterLast() throws IOException
-        {
-            if ( cursor != null )
-            {
-                cursor.afterLast();
-            }
-        }
-
-
-        /**
-         * {@inheritDoc}}
-         */
-        @Override
-        public V prev() throws EndOfFileExceededException, IOException
-        {
-            try
-            {
-                return cursor.prev().getKey();
-            }
-            catch ( EndOfFileExceededException e )
-            {
-                e.printStackTrace();
-                return null;
-            }
-            catch ( IOException e )
-            {
-                e.printStackTrace();
-                return null;
-            }
-        }
-
-
-        /**
-         * {@inheritDoc}
-         */
-        @Override
-        public int size()
-        {
-            return ( int ) valueBtree.getNbElems();
-        }
-    }
-
-
-    /**
      * @return the raw representation of the value holder. The serialized value will not be the same
      * if the values are stored in an array or in a btree. <br/>
      * If they are stored in a BTree, the raw value will contain the offset of the btree, otherwise
@@ -518,7 +335,7 @@ public class ValueHolder<V> implements C
         if ( isSubBtree() )
         {
             // The values are stored into a subBtree, return the offset of this subBtree
-            long btreeOffset = valueBtree.getBtreeOffset();
+            long btreeOffset = ((PersistedBTree<V, V>)valueBtree).getBtreeOffset();
             raw = LongSerializer.serialize( btreeOffset );
         }
         else
@@ -605,11 +422,11 @@ public class ValueHolder<V> implements C
             configuration.setParentBTree( btree );
             configuration.setSubBtree( true );
             
-            valueBtree = new BTree<V, V>( configuration );
+            valueBtree = BTreeFactory.createBTree( configuration );
 
             try
             {
-                btree.getRecordManager().manage( valueBtree, RecordManager.INTERNAL_BTREE );
+                ((PersistedBTree<V, V>)btree).getRecordManager().manage( valueBtree, RecordManager.INTERNAL_BTREE );
                 raw = null;
             }
             catch ( BTreeAlreadyManagedException e )
@@ -669,7 +486,7 @@ public class ValueHolder<V> implements C
         checkAndDeserialize();
 
         // We have to check that we have reached the threshold or not
-        if ( valueArray.length >= BTree.valueThresholdUp )
+        if ( valueArray.length >= PersistedBTree.valueThresholdUp )
         {
             // Ok, transform the array into a btree
             createSubTree();
@@ -809,7 +626,7 @@ public class ValueHolder<V> implements C
         {
             try
             {
-                if ( valueBtree.getNbElems() - 1 < BTree.valueThresholdLow )
+                if ( valueBtree.getNbElems() - 1 < PersistedBTree.valueThresholdLow )
                 {
                     int nbValues = (int)(valueBtree.getNbElems() - 1);
                         
@@ -1142,8 +959,9 @@ public class ValueHolder<V> implements C
         long offset = LongSerializer.deserialize( raw );
         
         // and reload the sub btree
-        valueBtree = btree.getRecordManager().loadDupsBTree( offset );
+        valueBtree = ((PersistedBTree<V, V>)btree).getRecordManager().loadDupsBTree( offset );
     }
+    
 
     /**
      * @return The sub-btree offset
@@ -1152,7 +970,7 @@ public class ValueHolder<V> implements C
     {
         if ( valueArray == null )
         {
-            return valueBtree.getBtreeOffset();
+            return ((PersistedBTree<V, V>)valueBtree).getBtreeOffset();
         }
         else
         {

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/AbstractPage.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/AbstractPage.java?rev=1550580&r1=1550579&r2=1550580&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/AbstractPage.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/AbstractPage.java Thu Dec 12 23:08:28 2013
@@ -23,6 +23,7 @@ package org.apache.directory.mavibot.btr
 import java.io.IOException;
 import java.lang.reflect.Array;
 
+import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.Page;
 import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
 

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTreeConfiguration.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTreeConfiguration.java?rev=1550580&r1=1550579&r2=1550580&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTreeConfiguration.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTreeConfiguration.java Thu Dec 12 23:08:28 2013
@@ -20,6 +20,7 @@
 package org.apache.directory.mavibot.btree.memory;
 
 
+import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
 
 
@@ -35,10 +36,10 @@ import org.apache.directory.mavibot.btre
 public class BTreeConfiguration<K, V>
 {
     /** Number of entries in each Page. */
-    private int pageSize = BTree.DEFAULT_PAGE_SIZE;
+    private int pageSize = InMemoryBTree.DEFAULT_PAGE_SIZE;
 
     /** The size of the buffer used to write data in disk */
-    private int writeBufferSize = BTree.DEFAULT_WRITE_BUFFER_SIZE;
+    private int writeBufferSize = InMemoryBTree.DEFAULT_WRITE_BUFFER_SIZE;
 
     /** The Key and Value serializer used for this tree. If none is provided, 
      * the BTree will deduce the serializer to use from the generic type, and
@@ -61,7 +62,7 @@ public class BTreeConfiguration<K, V>
      * The default value is 10000 (10 seconds). If the value is 0 or below,
      * the delay is considered as infinite
      */
-    private long readTimeOut = BTree.DEFAULT_READ_TIMEOUT;
+    private long readTimeOut = InMemoryBTree.DEFAULT_READ_TIMEOUT;
 
     /** The maximal size of the journal. When this size is reached, the tree is 
      * flushed on disk.
@@ -72,7 +73,7 @@ public class BTreeConfiguration<K, V>
     /**
      * The journal's name. Default to "mavibot.log".
      */
-    private String journalName = BTree.DEFAULT_JOURNAL;
+    private String journalName = InMemoryBTree.DEFAULT_JOURNAL;
 
     /** 
      * The delay between two checkpoints. When we reach the maximum delay,

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTreeFactory.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTreeFactory.java?rev=1550580&r1=1550579&r2=1550580&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTreeFactory.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTreeFactory.java Thu Dec 12 23:08:28 2013
@@ -23,6 +23,7 @@ package org.apache.directory.mavibot.btr
 import java.io.IOException;
 import java.util.LinkedList;
 
+import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.Page;
 import org.apache.directory.mavibot.btree.ParentPos;
 import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
@@ -45,7 +46,7 @@ public class BTreeFactory
      */
     public static <K, V> BTree<K, V> createBTree()
     {
-        BTree<K, V> btree = new BTree<K, V>();
+        BTree<K, V> btree = new InMemoryBTree<K, V>();
 
         return btree;
     }
@@ -91,7 +92,7 @@ public class BTreeFactory
      */
     public static <K, V> void setRoot( BTree<K, V> btree, Page<K, V> root )
     {
-        btree.setRoot( root );
+        btree.setRootPage( root );
     }
 
 
@@ -103,7 +104,7 @@ public class BTreeFactory
      */
     public static <K, V> Page<K, V> getRoot( BTree<K, V> btree )
     {
-        return btree.rootPage;
+        return btree.getRootPage();
     }
 
 
@@ -227,18 +228,18 @@ public class BTreeFactory
     {
         LinkedList<ParentPos<K, V>> stack = new LinkedList<ParentPos<K, V>>();
 
-        ParentPos<K, V> last = new ParentPos<K, V>( btree.rootPage, btree.rootPage.getNbElems() );
+        ParentPos<K, V> last = new ParentPos<K, V>( btree.getRootPage(), btree.getRootPage().getNbElems() );
         stack.push( last );
 
-        if ( btree.rootPage instanceof Leaf )
+        if ( btree.getRootPage() instanceof Leaf )
         {
-            Leaf<K, V> leaf = ( Leaf<K, V> ) ( btree.rootPage );
+            Leaf<K, V> leaf = ( Leaf<K, V> ) ( btree.getRootPage() );
             ValueHolder<V> valueHolder = leaf.values[last.pos];
             last.valueCursor = valueHolder.getCursor();
         }
         else
         {
-            Node<K, V> node = ( Node<K, V> ) btree.rootPage;
+            Node<K, V> node = ( Node<K, V> ) btree.getRootPage();
 
             while ( true )
             {

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BulkDataSorter.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BulkDataSorter.java?rev=1550580&r1=1550579&r2=1550580&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BulkDataSorter.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BulkDataSorter.java Thu Dec 12 23:08:28 2013
@@ -39,7 +39,7 @@ import org.apache.directory.mavibot.btre
 
 
 /**
- * A utility class for sorting a large number of keys before building a BTree using {@link BTreeBuilder}.
+ * A utility class for sorting a large number of keys before building a BTree using {@link InMemoryBTreeBuilder}.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */

Copied: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryBTree.java (from r1550209, directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTree.java)
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryBTree.java?p2=directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryBTree.java&p1=directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTree.java&r1=1550209&r2=1550580&rev=1550580&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTree.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryBTree.java Thu Dec 12 23:08:28 2013
@@ -37,6 +37,7 @@ import java.util.concurrent.locks.Reentr
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.config.CacheConfiguration;
 
+import org.apache.directory.mavibot.btree.AbstractBTree;
 import org.apache.directory.mavibot.btree.Addition;
 import org.apache.directory.mavibot.btree.BTreeHeader;
 import org.apache.directory.mavibot.btree.DeleteResult;
@@ -69,19 +70,10 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class BTree<K, V> implements Closeable
+public class InMemoryBTree<K, V> extends AbstractBTree<K, V> implements Closeable
 {
     /** The LoggerFactory used by this class */
-    protected static final Logger LOG = LoggerFactory.getLogger( BTree.class );
-
-    /** The Header for a managed BTree */
-    private BTreeHeader btreeHeader;
-
-    /** Default page size (number of entries per node) */
-    public static final int DEFAULT_PAGE_SIZE = 16;
-
-    /** Default size of the buffer used to write data on disk. Around 1Mb */
-    public static final int DEFAULT_WRITE_BUFFER_SIZE = 4096 * 250;
+    protected static final Logger LOG = LoggerFactory.getLogger( InMemoryBTree.class );
 
     /** The default journal name */
     public static final String DEFAULT_JOURNAL = "mavibot.log";
@@ -92,24 +84,9 @@ public class BTree<K, V> implements Clos
     /** The default journal file suffix */
     public static final String JOURNAL_SUFFIX = ".log";
 
-    /** The current rootPage */
-    protected volatile Page<K, V> rootPage;
-
-    /** The list of read transactions being executed */
-    private ConcurrentLinkedQueue<Transaction<K, V>> readTransactions;
-
-    /** The size of the buffer used to write data in disk */
-    private int writeBufferSize;
-
     /** The type to use to create the keys */
     protected Class<?> keyType;
 
-    /** The Key serializer used for this tree.*/
-    private ElementSerializer<K> keySerializer;
-
-    /** The Value serializer used for this tree. */
-    private ElementSerializer<V> valueSerializer;
-
     /** The associated file. If null, this is an in-memory btree  */
     private File file;
 
@@ -122,109 +99,17 @@ public class BTree<K, V> implements Clos
     /** The associated journal. If null, this is an in-memory btree  */
     private File journal;
 
-    /** A lock used to protect the write operation against concurrent access */
-    private ReentrantLock writeLock;
-
-    /** The thread responsible for the cleanup of timed out reads */
-    private Thread readTransactionsThread;
-
-    /** Define a default delay for a read transaction. This is 10 seconds */
-    public static final long DEFAULT_READ_TIMEOUT = 10 * 1000L;
-
-    /** The read transaction timeout */
-    private long readTimeOut = DEFAULT_READ_TIMEOUT;
-
     private File envDir;
 
     private FileChannel journalChannel = null;
 
-    /** The cache associated with this BTree */
-    private Cache cache;
-
-    /** The cache size, default to 1000 elements */
-    private int cacheSize = DEFAULT_CACHE_SIZE;
-
-    /** The default number of pages to keep in memory */
-    private static final int DEFAULT_CACHE_SIZE = 1000;
-
-
-    /**
-     * Create a thread that is responsible of cleaning the transactions when
-     * they hit the timeout
-     */
-    private void createTransactionManager()
-    {
-        Runnable readTransactionTask = new Runnable()
-        {
-            public void run()
-            {
-                try
-                {
-                    Transaction<K, V> transaction = null;
-
-                    while ( !Thread.currentThread().isInterrupted() )
-                    {
-                        long timeoutDate = System.currentTimeMillis() - readTimeOut;
-                        long t0 = System.currentTimeMillis();
-                        int nbTxns = 0;
-
-                        // Loop on all the transactions from the queue
-                        while ( ( transaction = readTransactions.peek() ) != null )
-                        {
-                            nbTxns++;
-
-                            if ( transaction.isClosed() )
-                            {
-                                // The transaction is already closed, remove it from the queue
-                                readTransactions.poll();
-                                continue;
-                            }
-
-                            // Check if the transaction has timed out
-                            if ( transaction.getCreationDate() < timeoutDate )
-                            {
-                                transaction.close();
-                                readTransactions.poll();
-                                continue;
-                            }
-
-                            // We need to stop now
-                            break;
-                        }
-
-                        long t1 = System.currentTimeMillis();
-
-                        if ( nbTxns > 0 )
-                        {
-                            System.out.println( "Processing old txn : " + nbTxns + ", " + ( t1 - t0 ) + "ms" );
-                        }
-
-                        // Wait until we reach the timeout
-                        Thread.sleep( readTimeOut );
-                    }
-                }
-                catch ( InterruptedException ie )
-                {
-                    //System.out.println( "Interrupted" );
-                }
-                catch ( Exception e )
-                {
-                    throw new RuntimeException( e );
-                }
-            }
-        };
-
-        readTransactionsThread = new Thread( readTransactionTask );
-        readTransactionsThread.setDaemon( true );
-        readTransactionsThread.start();
-    }
-
 
     /**
      * Creates a new BTree, with no initialization. 
      */
-    public BTree()
+    public InMemoryBTree()
     {
+        super();
         btreeHeader = new BTreeHeader();
         type = BTreeTypeEnum.IN_MEMORY;
     }
@@ -236,8 +121,9 @@ public class BTree<K, V> implements Clos
      * 
      * @param comparator The comparator to use
      */
-    public BTree( BTreeConfiguration<K, V> configuration ) throws IOException
+    public InMemoryBTree( BTreeConfiguration<K, V> configuration ) throws IOException
     {
+        super();
         String name = configuration.getName();
 
         if ( name == null )
@@ -287,14 +173,14 @@ public class BTree<K, V> implements Clos
      * 
      * @param comparator The comparator to use
      */
-    public BTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
+    public InMemoryBTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
         throws IOException
     {
         this( name, keySerializer, valueSerializer, false );
     }
 
 
-    public BTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer,
+    public InMemoryBTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer,
         boolean allowDuplicates )
         throws IOException
     {
@@ -307,7 +193,7 @@ public class BTree<K, V> implements Clos
      * 
      * @param comparator The comparator to use
      */
-    public BTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, int pageSize )
+    public InMemoryBTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, int pageSize )
         throws IOException
     {
         this( name, null, keySerializer, valueSerializer, pageSize );
@@ -319,7 +205,7 @@ public class BTree<K, V> implements Clos
      * @param comparator The comparator to use
      * @param serializer The serializer to use
      */
-    public BTree( String name, String path, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
+    public InMemoryBTree( String name, String path, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
         throws IOException
     {
         this( name, path, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE );
@@ -337,7 +223,7 @@ public class BTree<K, V> implements Clos
      * @param pageSize size of the page
      * @throws IOException
      */
-    public BTree( String name, String dataDir, ElementSerializer<K> keySerializer,
+    public InMemoryBTree( String name, String dataDir, ElementSerializer<K> keySerializer,
         ElementSerializer<V> valueSerializer,
         int pageSize )
         throws IOException
@@ -346,7 +232,7 @@ public class BTree<K, V> implements Clos
     }
 
 
-    public BTree( String name, String dataDir, ElementSerializer<K> keySerializer,
+    public InMemoryBTree( String name, String dataDir, ElementSerializer<K> keySerializer,
         ElementSerializer<V> valueSerializer,
         int pageSize, boolean allowDuplicates )
         throws IOException
@@ -355,11 +241,12 @@ public class BTree<K, V> implements Clos
     }
 
 
-    public BTree( String name, String dataDir, ElementSerializer<K> keySerializer,
+    public InMemoryBTree( String name, String dataDir, ElementSerializer<K> keySerializer,
         ElementSerializer<V> valueSerializer,
         int pageSize, boolean allowDuplicates, int cacheSize )
         throws IOException
     {
+        super();
         btreeHeader = new BTreeHeader();
         btreeHeader.setName( name );
 
@@ -515,183 +402,6 @@ public class BTree<K, V> implements Clos
 
 
     /**
-     * Gets the number which is a power of 2 immediately above the given positive number.
-     */
-    private int getPowerOf2( int size )
-    {
-        int newSize = --size;
-        newSize |= newSize >> 1;
-        newSize |= newSize >> 2;
-        newSize |= newSize >> 4;
-        newSize |= newSize >> 8;
-        newSize |= newSize >> 16;
-        newSize++;
-
-        return newSize;
-    }
-
-
-    /**
-     * Set the maximum number of elements we can store in a page. This must be a
-     * number greater than 1, and a power of 2. The default page size is 16.
-     * <br/>
-     * If the provided size is below 2, we will default to DEFAULT_PAGE_SIZE.<br/>
-     * If the provided size is not a power of 2, we will select the closest power of 2
-     * higher than the given number<br/>
-     * 
-     * @param pageSize The requested page size
-     */
-    public void setPageSize( int pageSize )
-    {
-        if ( pageSize <= 2 )
-        {
-            btreeHeader.setPageSize( DEFAULT_PAGE_SIZE );
-        }
-        else
-        {
-            btreeHeader.setPageSize( getPowerOf2( pageSize ) );
-        }
-    }
-
-
-    /**
-     * Set the new root page for this tree. Used for debug purpose only. The revision
-     * will always be 0;
-     * 
-     * @param root the new root page.
-     */
-    /* No qualifier */void setRoot( Page<K, V> root )
-    {
-        rootPage = root;
-    }
-
-
-    /**
-     * @return the pageSize
-     */
-    public int getPageSize()
-    {
-        return btreeHeader.getPageSize();
-    }
-
-
-    /**
-     * Generates a new revision number. It's only used by the Page instances.
-     * 
-     * @return a new incremental revision number
-     */
-    /** No qualifier */
-    long generateRevision()
-    {
-        return btreeHeader.incrementRevision();
-    }
-
-
-    /**
-     * Insert an entry in the BTree.
-     * <p>
-     * We will replace the value if the provided key already exists in the
-     * btree.
-     *
-     * @param key Inserted key
-     * @param value Inserted value
-     * @return Existing value, if any.
-     * @throws IOException TODO
-     */
-    public V insert( K key, V value ) throws IOException
-    {
-        long revision = generateRevision();
-
-        V existingValue = null;
-
-        try
-        {
-            // Commented atm, we will have to play around the idea of transactions later
-            writeLock.lock();
-
-            InsertResult<K, V> result = insert( key, value, revision );
-
-            if ( result instanceof ModifyResult )
-            {
-                existingValue = ( (org.apache.directory.mavibot.btree.ModifyResult<K, V> ) result ).getModifiedValue();
-            }
-        }
-        finally
-        {
-            // See above
-            writeLock.unlock();
-        }
-
-        return existingValue;
-    }
-
-
-    /**
-     * Delete the entry which key is given as a parameter. If the entry exists, it will
-     * be removed from the tree, the old tuple will be returned. Otherwise, null is returned.
-     * 
-     * @param key The key for the entry we try to remove
-     * @return A Tuple<K, V> containing the removed entry, or null if it's not found.
-     */
-    public Tuple<K, V> delete( K key ) throws IOException
-    {
-        if ( key == null )
-        {
-            throw new IllegalArgumentException( "Key must not be null" );
-        }
-
-        long revision = generateRevision();
-
-        Tuple<K, V> deleted = delete( key, revision );
-
-        return deleted;
-    }
-
-
-    /**
-     * Delete the value from an entry associated with the given key. If the value
-     * If the value is present, it will be deleted first, later if there are no other 
-     * values associated with this key(which can happen when duplicates are enabled), 
-     * we will remove the key from the tree.
-     * 
-     * @param key The key for the entry we try to remove
-     * @param value The value to delete (can be null)
-     * @return A Tuple<K, V> containing the removed entry, or null if it's not found.
-     */
-    public Tuple<K, V> delete( K key, V value ) throws IOException
-    {
-        if ( key == null )
-        {
-            throw new IllegalArgumentException( "Key must not be null" );
-        }
-
-        if ( value == null )
-        {
-            throw new IllegalArgumentException( "Value must not be null" );
-        }
-
-        long revision = generateRevision();
-
-        Tuple<K, V> deleted = delete( key, value, revision );
-
-        return deleted;
-    }
-
-
-    /**
-     * Delete the entry which key is given as a parameter. If the entry exists, it will
-     * be removed from the tree, the old tuple will be returned. Otherwise, null is returned.
-     * 
-     * @param key The key for the entry we try to remove
-     * @return A Tuple<K, V> containing the removed entry, or null if it's not found.
-     */
-    private Tuple<K, V> delete( K key, long revision ) throws IOException
-    {
-        return delete( key, null, revision );
-    }
-
-
-    /**
      * 
      * Deletes the given <key,value> pair if both key and value match. If the given value is null
      * and there is no null value associated with the given key then the entry with the given key
@@ -703,7 +413,7 @@ public class BTree<K, V> implements Clos
      * @return
      * @throws IOException
      */
-    private Tuple<K, V> delete( K key, V value, long revision ) throws IOException
+    protected Tuple<K, V> delete( K key, V value, long revision ) throws IOException
     {
         writeLock.lock();
 
@@ -762,208 +472,6 @@ public class BTree<K, V> implements Clos
 
 
     /**
-     * Find a value in the tree, given its key. If the key is not found,
-     * it will throw a KeyNotFoundException. <br/>
-     * Note that we can get a null value stored, or many values.
-     * 
-     * @param key The key we are looking at
-     * @return The found value, or null if the key is not present in the tree
-     * @throws KeyNotFoundException If the key is not found in the BTree
-     * @throws IOException TODO
-     */
-    public V get( K key ) throws IOException, KeyNotFoundException
-    {
-        return rootPage.get( key );
-    }
-
-
-    /**
-     * @see Page#getValues(Object)
-     */
-    public ValueCursor<V> getValues( K key ) throws IOException, KeyNotFoundException
-    {
-        return rootPage.getValues( key );
-    }
-
-
-    /**
-     * Find a value in the tree, given its key, at a specific revision. If the key is not found,
-     * it will throw a KeyNotFoundException. <br/>
-     * Note that we can get a null value stored, or many values.
-     * 
-     * @param revision The revision for which we want to find a key
-     * @param key The key we are looking at
-     * @return The found value, or null if the key is not present in the tree
-     * @throws KeyNotFoundException If the key is not found in the BTree
-     * @throws IOException If there was an issue while fetching data from the disk
-     */
-    public V get( long revision, K key ) throws IOException, KeyNotFoundException
-    {
-        // Fetch the root page for this revision
-        Page<K, V> revisionRootPage = getRootPage( revision );
-
-        return revisionRootPage.get( key );
-    }
-
-
-    /**
-     * Checks if the given key exists.
-     *  
-     * @param key The key we are looking at
-     * @return true if the key is present, false otherwise
-     * @throws IOException If we have an error while trying to access the page
-     */
-    public boolean hasKey( K key ) throws IOException
-    {
-        if ( key == null )
-        {
-            return false;
-        }
-
-        return rootPage.hasKey( key );
-    }
-
-
-    /**
-     * Checks if the given key exists for a given revision.
-     *  
-     * @param revision The revision for which we want to find a key
-     * @param key The key we are looking at
-     * @return true if the key is present, false otherwise
-     * @throws IOException If we have an error while trying to access the page
-     * @throws KeyNotFoundException If the key is not found in the BTree
-     */
-    public boolean hasKey( long revision, K key ) throws IOException, KeyNotFoundException
-    {
-        if ( key == null )
-        {
-            return false;
-        }
-
-        // Fetch the root page for this revision
-        Page<K, V> revisionRootPage = getRootPage( revision );
-
-        return revisionRootPage.hasKey( key );
-    }
-
-
-    /**
-     * Checks if the BTree contains the given key with the given value.
-     * 
-     * @param key The key we are looking for
-     * @param value The value associated with the given key
-     * @return true if the key and value are associated with each other, false otherwise
-     */
-    public boolean contains( K key, V value ) throws IOException
-    {
-        return rootPage.contains( key, value );
-    }
-
-
-    /**
-     * Checks if the BTree contains the given key with the given value for a given revision
-     * 
-     * @param revision The revision we would like to browse
-     * @param key The key we are looking for
-     * @param value The value associated with the given key
-     * @return true if the key and value are associated with each other, false otherwise
-     * @throws KeyNotFoundException If the key is not found in the BTree
-     */
-    public boolean contains( long revision, K key, V value ) throws IOException, KeyNotFoundException
-    {
-        // Fetch the root page for this revision
-        Page<K, V> revisionRootPage = getRootPage( revision );
-
-        return revisionRootPage.contains( key, value );
-    }
-
-
-    /**
-     * Creates a cursor starting at the beginning of the tree
-     * 
-     * @return A cursor on the btree
-     * @throws IOException
-     */
-    public TupleCursor<K, V> browse() throws IOException
-    {
-        Transaction<K, V> transaction = beginReadTransaction();
-
-        // Fetch the root page for this revision
-        TupleCursor<K, V> cursor = rootPage.browse( transaction, new ParentPos[32], 0 );
-        
-        // Set the position before the first element
-        cursor.beforeFirst();
-
-        return cursor;
-    }
-
-
-    /**
-     * Creates a cursor starting at the beginning of the tree, for a given revision
-     * 
-     * @param revision The revision we would like to browse
-     * @return A cursor on the btree
-     * @throws IOException If we had an issue while fetching data from the disk
-     * @throws KeyNotFoundException If the key is not found in the BTree
-     */
-    public TupleCursor<K, V> browse( long revision ) throws IOException, KeyNotFoundException
-    {
-        Transaction<K, V> transaction = beginReadTransaction();
-
-        // Fetch the root page for this revision
-        Page<K, V> revisionRootPage = getRootPage( revision );
-
-        // And get the cursor
-        TupleCursor<K, V> cursor = revisionRootPage.browse( transaction, new ParentPos[32], 0 );
-
-        return cursor;
-    }
-
-
-    /**
-     * Creates a cursor starting on the given key
-     * 
-     * @param key The key which is the starting point. If the key is not found,
-     * then the cursor will always return null.
-     * @return A cursor on the btree
-     * @throws IOException
-     */
-    public TupleCursor<K, V> browseFrom( K key ) throws IOException
-    {
-        Transaction<K, V> transaction = beginReadTransaction();
-
-        // Fetch the root page for this revision
-        TupleCursor<K, V> cursor = rootPage.browse( key, transaction, new ParentPos[32], 0 );
-
-        return cursor;
-    }
-
-
-    /**
-     * Creates a cursor starting on the given key at the given revision
-     * 
-     * @param The revision we are looking for
-     * @param key The key which is the starting point. If the key is not found,
-     * then the cursor will always return null.
-     * @return A cursor on the btree
-     * @throws IOException If wxe had an issue reading the BTree from disk
-     * @throws KeyNotFoundException  If we can't find a rootPage for this revision
-     */
-    public TupleCursor<K, V> browseFrom( long revision, K key ) throws IOException, KeyNotFoundException
-    {
-        Transaction<K, V> transaction = beginReadTransaction();
-
-        // Fetch the rootPage for this revision
-        Page<K, V> revisionRootPage = getRootPage( revision );
-
-        // And get the cursor
-        TupleCursor<K, V> cursor = revisionRootPage.browse( key, transaction, new ParentPos[32], 0 );
-
-        return cursor;
-    }
-
-
-    /**
      * Insert an entry in the BTree.
      * <p>
      * We will replace the value if the provided key already exists in the
@@ -976,7 +484,7 @@ public class BTree<K, V> implements Clos
      * @param revision The revision to use
      * @return an instance of the InsertResult.
      */
-    /*No qualifier*/InsertResult<K, V> insert( K key, V value, long revision ) throws IOException
+    public InsertResult<K, V> insert( K key, V value, long revision ) throws IOException
     {
         if ( key == null )
         {
@@ -1040,60 +548,15 @@ public class BTree<K, V> implements Clos
 
 
     /**
-     * Starts a Read Only transaction. If the transaction is not closed, it will be 
-     * automatically closed after the timeout
-     * @return The created transaction
-     */
-    private Transaction<K, V> beginReadTransaction()
-    {
-        Transaction<K, V> readTransaction = new Transaction<K, V>( rootPage, btreeHeader.getRevision() - 1,
-            System.currentTimeMillis() );
-
-        readTransactions.add( readTransaction );
-
-        return readTransaction;
-    }
-
-
-    /**
      * @return the type for the keys
      */
-    /* No qualifier*/Class<?> getKeyType()
+    public Class<?> getKeyType()
     {
         return keyType;
     }
 
 
     /**
-     * @return the comparator
-     */
-    public Comparator<K> getComparator()
-    {
-        return keySerializer.getComparator();
-    }
-
-
-    /**
-     * @param keySerializer the Key serializer to set
-     */
-    public void setKeySerializer( ElementSerializer<K> keySerializer )
-    {
-        this.keySerializer = keySerializer;
-        btreeHeader.setKeySerializerFQCN( keySerializer.getClass().getName() );
-    }
-
-
-    /**
-     * @param valueSerializer the Value serializer to set
-     */
-    public void setValueSerializer( ElementSerializer<V> valueSerializer )
-    {
-        this.valueSerializer = valueSerializer;
-        btreeHeader.setValueSerializerFQCN( valueSerializer.getClass().getName() );
-    }
-
-
-    /**
      * Write the data in the ByteBuffer, and eventually on disk if needed.
      * 
      * @param channel The channel we want to write to
@@ -1340,7 +803,7 @@ public class BTree<K, V> implements Clos
      * @throws IOException If we had an issue while accessing the underlying file
      * @throws KeyNotFoundException If the revision does not exist for this Btree
      */
-    private Page<K, V> getRootPage( long revision ) throws IOException, KeyNotFoundException
+    public Page<K, V> getRootPage( long revision ) throws IOException, KeyNotFoundException
     {
         // Atm, the in-memory BTree does not support searches in many revisions
         return rootPage;
@@ -1363,42 +826,6 @@ public class BTree<K, V> implements Clos
 
 
     /**
-     * @return the readTimeOut
-     */
-    public long getReadTimeOut()
-    {
-        return readTimeOut;
-    }
-
-
-    /**
-     * @param readTimeOut the readTimeOut to set
-     */
-    public void setReadTimeOut( long readTimeOut )
-    {
-        this.readTimeOut = readTimeOut;
-    }
-
-
-    /**
-     * @return the name
-     */
-    public String getName()
-    {
-        return btreeHeader.getName();
-    }
-
-
-    /**
-     * @param name the name to set
-     */
-    public void setName( String name )
-    {
-        btreeHeader.setName( name );
-    }
-
-
-    /**
      * @return the file
      */
     public File getFile()
@@ -1417,24 +844,6 @@ public class BTree<K, V> implements Clos
 
 
     /**
-     * @return the writeBufferSize
-     */
-    public int getWriteBufferSize()
-    {
-        return writeBufferSize;
-    }
-
-
-    /**
-     * @param writeBufferSize the writeBufferSize to set
-     */
-    public void setWriteBufferSize( int writeBufferSize )
-    {
-        this.writeBufferSize = writeBufferSize;
-    }
-
-
-    /**
      * @return true if the BTree is fully in memory
      */
     public boolean isInMemory()
@@ -1452,105 +861,6 @@ public class BTree<K, V> implements Clos
     }
 
 
-    /**
-     * Create a ValueHolder depending on the kind of holder we want.
-     * 
-     * @param value The value to store
-     * @return The value holder
-     */
-    /* no qualifier */ValueHolder<V> createValueHolder( V value )
-    {
-        return new ValueHolder<V>( this, value );
-    }
-
-
-    /**
-     * @return the keySerializer
-     */
-    public ElementSerializer<K> getKeySerializer()
-    {
-        return keySerializer;
-    }
-
-
-    /**
-     * @return the keySerializer FQCN
-     */
-    public String getKeySerializerFQCN()
-    {
-        return btreeHeader.getKeySerializerFQCN();
-    }
-
-
-    /**
-     * @return the valueSerializer
-     */
-    public ElementSerializer<V> getValueSerializer()
-    {
-        return valueSerializer;
-    }
-
-
-    /**
-     * @return the valueSerializer FQCN
-     */
-    public String getValueSerializerFQCN()
-    {
-        return btreeHeader.getValueSerializerFQCN();
-    }
-
-
-    /** 
-     * @return The current BTree revision
-     */
-    public long getRevision()
-    {
-        return btreeHeader.getRevision();
-    }
-
-
-    /**
-     * @param revision the revision to set
-     */
-    /* No qualifier */void setRevision( long revision )
-    {
-        btreeHeader.setRevision( revision );
-    }
-
-
-    /** 
-     * @return The current number of elements in the BTree
-     */
-    public long getNbElems()
-    {
-        return btreeHeader.getNbElems();
-    }
-
-
-    /**
-     * @param nbElems the nbElems to set
-     */
-    /* No qualifier */void setNbElems( long nbElems )
-    {
-        btreeHeader.setNbElems( nbElems );
-    }
-
-
-    /**
-     * @return true if this BTree allow duplicate values
-     */
-    public boolean isAllowDuplicates()
-    {
-        return btreeHeader.isAllowDuplicates();
-    }
-
-
-    /* No qualifier */void setAllowDuplicates( boolean allowDuplicates )
-    {
-        btreeHeader.setAllowDuplicates( allowDuplicates );
-    }
-
-
     private void writeToJournal( Modification<K, V> modification )
         throws IOException
     {



Mime
View raw message