You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by ka...@apache.org on 2013/05/13 08:57:28 UTC

svn commit: r1481710 - /labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/DuplicateKeyMemoryHolder.java

Author: kayyagari
Date: Mon May 13 06:57:27 2013
New Revision: 1481710

URL: http://svn.apache.org/r1481710
Log:
hold the value container in a soft reference if the parent btree is in managed mode

Modified:
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/DuplicateKeyMemoryHolder.java

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/DuplicateKeyMemoryHolder.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/DuplicateKeyMemoryHolder.java?rev=1481710&r1=1481709&r2=1481710&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/DuplicateKeyMemoryHolder.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/DuplicateKeyMemoryHolder.java Mon May 13 06:57:27 2013
@@ -21,8 +21,11 @@ package org.apache.mavibot.btree;
 
 
 import java.io.IOException;
+import java.lang.ref.SoftReference;
 import java.util.UUID;
 
+import org.apache.mavibot.btree.exception.BTreeAlreadyManagedException;
+
 
 /**
  * A In-Memory holder for values of duplicate keys. The values are always present in memory.
@@ -37,9 +40,14 @@ public class DuplicateKeyMemoryHolder<K,
     /** The BTree */
     private BTree<K, V> btree;
 
-    /** The reference to the Value instance, or null if it's not present */
+    /* the name of the value container btree. This value is set only when the parent BTree is in managed mode */
+    private String name;
+    
+    /* The reference to the Value instance, or null if it's not present. This will be null when the parent BTree is in managed mode */
     private BTree<V, V> valueContainer;
 
+    /* This value is set only when the parent BTree is in managed mode */
+    private SoftReference<BTree<V, V>> reference;
 
     /**
      * Create a new holder storing an offset and a SoftReference containing the value.
@@ -53,9 +61,31 @@ public class DuplicateKeyMemoryHolder<K,
 
         try
         {
-            this.valueContainer = new BTree<V, V>( UUID.randomUUID().toString(), btree.getValueSerializer(),
+            BTree<V, V> valueContainer = new BTree<V, V>( UUID.randomUUID().toString(), btree.getValueSerializer(),
                 btree.getValueSerializer() );
-            valueContainer.init();
+            
+            
+            if( btree.isManaged() )
+            {
+                this.name = valueContainer.getName();
+                
+                try
+                {
+                    btree.getRecordManager().manage( valueContainer );
+                }
+                catch( BTreeAlreadyManagedException e )
+                {
+                    // should never happen
+                    throw new RuntimeException( e );
+                }
+                
+                reference = new SoftReference<BTree<V,V>>( valueContainer );
+            }
+            else
+            {
+                this.valueContainer = valueContainer;
+            }
+            
             valueContainer.insert( value, null, 0 );
         }
         catch ( IOException e )
@@ -64,14 +94,43 @@ public class DuplicateKeyMemoryHolder<K,
         }
     }
 
+    
+    /* No qualifier */ DuplicateKeyMemoryHolder( BTree<K, V> btree, BTree<V,V> valueContainer )
+    {
+        this.btree = btree;
+        
+        if( btree.isManaged() )
+        {
+            this.name = valueContainer.getName();
+            reference = new SoftReference<BTree<V,V>>( valueContainer );
+        }
+        else
+        {
+            this.valueContainer = valueContainer;
+        }
+    }
 
+    
     /**
      * {@inheritDoc}
      */
     @Override
     public V getValue( BTree<K, V> btree )
     {
+        if( !btree.isManaged() )
+        {
+            return ( V ) valueContainer;
+        }
+        
         // wrong cast to please compiler
+        BTree<V,V> valueContainer = reference.get();
+        
+        if( valueContainer == null )
+        {
+            valueContainer = btree.getRecordManager().getManagedTree( name );
+            reference = new SoftReference<BTree<V,V>>( valueContainer );
+        }
+        
         return ( V ) valueContainer;
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org