directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1181716 - in /directory/apacheds/trunk/jdbm/src/main/java/jdbm: btree/BTree.java helper/ActionContext.java helper/ActionVersioning.java helper/ExplicitList.java helper/LRUCache.java recman/SnapshotRecordManager.java
Date Tue, 11 Oct 2011 11:18:15 GMT
Author: saya
Date: Tue Oct 11 11:18:14 2011
New Revision: 1181716

URL: http://svn.apache.org/viewvc?rev=1181716&view=rev
Log:
Modify jdbm files to use IllegalStateException rather than asserts.

Modified:
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ActionContext.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ActionVersioning.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ExplicitList.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/LRUCache.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java?rev=1181716&r1=1181715&r2=1181716&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java Tue Oct 11 11:18:14
2011
@@ -743,7 +743,10 @@ public class BTree<K, V> implements Exte
      */
     BPage<K, V> getRoot( ) throws IOException
     {        
-        assert( this.rootId == metaRoot.rootID) : "Stale root id " + this.rootId + " "+ metaRoot.rootID;
+        if ( rootId != metaRoot.rootID )
+        {
+            throw new IllegalStateException( "Stale root id " + this.rootId + " "+ metaRoot.rootID
);
+        }
         
         if ( this.rootId == 0 )
         {
@@ -864,7 +867,6 @@ public class BTree<K, V> implements Exte
     {
         if ( context != null )
         {
-            assert( isActionCapable == true );
             ( ( ActionRecordManager )recordManager ).setCurrentActionContext( context );
         }
     }
@@ -874,7 +876,6 @@ public class BTree<K, V> implements Exte
     {
         if ( context != null )
         {
-            assert( isActionCapable == true );
             ( ( ActionRecordManager )recordManager ).unsetCurrentActionContext( context );
         }
     }
@@ -897,7 +898,6 @@ public class BTree<K, V> implements Exte
     {
         if ( context != null )
         {
-            assert( isActionCapable );
             ( ( ActionRecordManager )recordManager ).endAction( context );
         }
     }
@@ -907,7 +907,6 @@ public class BTree<K, V> implements Exte
     {
         if ( context != null )
         {
-            assert( isActionCapable );
             ( ( ActionRecordManager )recordManager ).abortAction( context );
         }
 

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ActionContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ActionContext.java?rev=1181716&r1=1181715&r2=1181716&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ActionContext.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ActionContext.java Tue Oct 11
11:18:14 2011
@@ -45,7 +45,11 @@ public class ActionContext
     
     public void endAction()
     {
-        assert( version != null ) : "Unexpected action state during endAction: " + this;
+        if ( version == null )
+        {
+            throw new IllegalStateException( "Unexpected action state during endAction: "
+ this );
+        }
+        
         version = null;
     }
     

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ActionVersioning.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ActionVersioning.java?rev=1181716&r1=1181715&r2=1181716&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ActionVersioning.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ActionVersioning.java Tue Oct
11 11:18:14 2011
@@ -153,7 +153,11 @@ public class ActionVersioning
     {
         long numActions = version.getNumActions().decrementAndGet();
         
-        assert( numActions >= 0 ) : "NumActions zero when read action is ended : " + version;
+        if ( numActions < 0 )
+        {
+            throw new IllegalStateException( "NumActions zero when read action is ended :
" + version );
+        }
+
         
         if ( ( numActions > 0 ) || ( version == readReference.get() ) )
         {

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ExplicitList.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ExplicitList.java?rev=1181716&r1=1181715&r2=1181716&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ExplicitList.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/ExplicitList.java Tue Oct 11 11:18:14
2011
@@ -75,7 +75,11 @@ public class ExplicitList<T>
 
         public void remove()
         {
-            assert( isLinked() ) : "Trying to remove from list an unlinked link";
+            if ( isLinked() == false )
+            {
+                throw new IllegalStateException( "Trying to remove from list an unlinked
link" );
+            }
+ 
             this.getPrev().setNext( this.getNext() );
             this.getNext().setPrev( this.getPrev() );
             this.reset();
@@ -84,7 +88,11 @@ public class ExplicitList<T>
 
         public void addAfter( Link<V> after )
         {
-            assert( this.isUnLinked() ) : "Trying to add to list already linked link: " +
this;
+            if ( this.isUnLinked() == false )
+            {
+                throw new IllegalStateException( "Trying to add to list already linked link:
" + this );
+            }
+            
             after.getNext().setPrev( this );
             this.setNext( after.getNext() );
             after.setNext( this );
@@ -94,7 +102,11 @@ public class ExplicitList<T>
 
         public void addBefore( Link<V> before )
         {
-            assert( this.isUnLinked() ) : "Trying to add to list already linked link: " +
this;
+            if ( this.isUnLinked() == false )
+            {
+                throw new IllegalStateException( "Trying to add to list already linked link:
" + this );
+            }
+  
             before.getPrev().setNext( this );
             this.setPrev( before.getPrev() );
             before.setPrev( this );
@@ -138,7 +150,11 @@ public class ExplicitList<T>
 
         public void uninit()
         {
-            assert ( this.isUnLinked() ) :  " Unitializing a still linked entry" + this;
+            if ( this.isUnLinked() == false )
+            {
+                throw new IllegalStateException( " Unitializing a still linked entry" + this
);
+            }
+   
             element = null;
         }
 
@@ -164,7 +180,11 @@ public class ExplicitList<T>
 
     public void remove( Link<T> link )
     {
-        assert( listSize > 0 ) : "Trying to remove link " + link + " from a list with
no elements";
+        if ( listSize <= 0 )
+        {
+            throw new IllegalStateException( "Trying to remove link " + link + " from a list
with no elements" );
+        }
+
         listSize--;
         link.remove();
     }

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/LRUCache.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/LRUCache.java?rev=1181716&r1=1181715&r2=1181716&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/LRUCache.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/helper/LRUCache.java Tue Oct 11 11:18:14
2011
@@ -238,8 +238,11 @@ public class LRUCache<K, V>
                             
                             if ( !entry.isCurrentVersion() )
                             {
-                                assert( entry.isNeverReplace() == false ) : " Non current
entry should not have neverReplace set " + entry; 
-                                
+                                if ( entry.isNeverReplace() == true )
+                                {
+                                    throw new IllegalStateException( " Non current entry
should not have neverReplace set " + entry );
+                                }
+                                                            
                                 entry.setNeverReplace();
                                 CacheEntry newEntry = null;
                                 
@@ -293,7 +296,7 @@ public class LRUCache<K, V>
                             // FALLTHROUGH
                             
                         default:
-                            assert ( false ): "Unknown cache entry state: " + entry ;
+                            throw new IllegalStateException( "Unknown cache entry state:
" + entry ) ;
                     }
                 }
                 else
@@ -414,7 +417,10 @@ public class LRUCache<K, V>
                             
                             this.cacheMisses++;
                             
-                            assert( entry.isNeverReplace() == false ) : "Non Current Entry
has neverReplace set to true:" + entry;
+                            if ( entry.isNeverReplace() == true )
+                            {
+                                throw new IllegalStateException( "Non Current Entry has neverReplace
set to true:" + entry );
+                            }
                             
                             entry.setNeverReplace();
                             CacheEntry newEntry = null;
@@ -466,7 +472,7 @@ public class LRUCache<K, V>
                         break;
 
                     default:
-                        assert ( false ) : "Unknown cache entry state: " + entry;
+                        throw new IllegalStateException( "Unknown cache entry state: " +
entry );
                 }
             }
             else
@@ -569,7 +575,10 @@ public class LRUCache<K, V>
         }
         else
         {
-            assert( entry.isCurrentVersion() ) : "Entry not at expected version: " + entry
;
+            if  ( entry.isCurrentVersion() == false )
+            {
+                throw new IllegalStateException( "Entry not at expected version: " + entry
);
+            }
             
             // Entry already at current version. Just update the value
             entry.setAsCurrentVersion( value, newVersion );
@@ -650,15 +659,19 @@ public class LRUCache<K, V>
             
             if ( curEntry.getState() != EntryState.ENTRY_READY )
             {
-                assert( curEntry == head ) : "Unexpected state for entry: " + curEntry;
+                if ( curEntry != head )
+                {
+                    throw new IllegalStateException( "Unexpected state for entry: " + curEntry
);
+                }
+    
                 curLink = curLink.getNext();
                 continue;
             }
         
             if ( curStartVersion != 0 && ( curEntry.getEndVersion() > curStartVersion
) )
             {
-                assert( false ) : "Unexpected version number for entry. curStartVersion:
" 
-                        + curStartVersion + " entry: " + curEntry;
+                throw new IllegalStateException( "Unexpected version number for entry. curStartVersion:
" 
+                        + curStartVersion + " entry: " + curEntry );
             }
             
             curStartVersion = curEntry.getStartVersion();
@@ -686,7 +699,7 @@ public class LRUCache<K, V>
         
         if ( value == null && mustFind == true )
         {
-            assert( false ) : "Traversed all versions and could not find cache entry";
+            throw new IllegalStateException( "Traversed all versions and could not find cache
entry" );
         }
         
         return value;
@@ -937,14 +950,26 @@ public class LRUCache<K, V>
             endVersion = Long.MAX_VALUE;
 
             stateCondition = null;
-            assert ( numWaiters == 0 ) : "Numwaiters is not zero when entry is newly initialized:
" + this;
+            
+            if ( numWaiters != 0 )
+            {
+                throw new IllegalStateException( "Numwaiters is not zero when entry is newly
initialized: " + this );
+            }
+   
             state = EntryState.ENTRY_INITIAL;
 
-            assert ( versionsLink.isUnLinked() == true );
+            if ( versionsLink.isUnLinked() == false )
+            {
+                throw new IllegalStateException( "Versions link is still linked when entry
is initialized" );
+            }
+           
             
             hashIndex = hash( key ) & ( numBuckets - 1 );
             
-            assert( neverReplace == false ) : "Neverreplace is true when entry is newly intialized:"
+ this;
+            if ( neverReplace == true )
+            {
+                throw new IllegalStateException( "Neverreplace is true when entry is newly
intialized:" + this );
+            }
         }
 
         public void setNeverReplace()
@@ -1006,7 +1031,11 @@ public class LRUCache<K, V>
 
         public void decrementWaiters()
         {
-            assert ( numWaiters > 0 ) : "Unexpected num waiters for entry:" + this;
+            if ( numWaiters <= 0 )
+            {
+                throw new IllegalStateException( "Unexpected num waiters for entry:" + this
);
+            }
+            
             numWaiters--;
         }
 
@@ -1223,9 +1252,11 @@ public class LRUCache<K, V>
                 {
                     break;
                 }
-                               
-                assert( victimEntry.getKey() != null ) : 
-                    "Snapshot victimEntry doesnt have key set:" + victimEntry ;
+                      
+                if ( victimEntry.getKey() == null )
+                {
+                    throw new IllegalStateException( "Snapshot victimEntry doesnt have key
set:" + victimEntry );
+                }
                 
                 if ( victimEntry.isNeverReplace() )
                 {
@@ -1242,8 +1273,10 @@ public class LRUCache<K, V>
                     continue;
                 }
                 
-                assert( victimEntry.isEntryFreeable() == true ) : 
-                    "Snapshot victimEntry is not freeable:" + victimEntry ;
+                if ( victimEntry.isEntryFreeable() == false )
+                {
+                    throw new IllegalStateException( "Snapshot victimEntry is not freeable:"
+ victimEntry );
+                }
                 
                 int hashChainIndex = buckets[victimEntry.getHashIndex()].indexOf( victimEntry
);
                 

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java?rev=1181716&r1=1181715&r2=1181716&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java Tue
Oct 11 11:18:14 2011
@@ -118,7 +118,12 @@ public class SnapshotRecordManager imple
      public void setCurrentActionContext( ActionContext context )
      {
          ActionContext actionContext = actionContextVar.get();
-         assert( actionContext == null ) : "Action Context Not Null: " + actionContext.getWhoStarted();
+         
+         if ( actionContext != null )
+         {
+             throw new IllegalStateException( "Action Context Not Null: " + actionContext.getWhoStarted()
);
+         }
+
          actionContextVar.set( context );
      }
      
@@ -129,7 +134,13 @@ public class SnapshotRecordManager imple
      public void unsetCurrentActionContext( ActionContext context )
      {
          ActionContext actionContext = actionContextVar.get();
-         assert( actionContext == context );
+         
+         if ( actionContext != context )
+         {
+             throw new IllegalStateException( "Trying to end action context not set in the
thread context variable" + context + 
+                     " " + actionContext );
+         }
+
          actionContextVar.set( null );
      }
      
@@ -155,7 +166,7 @@ public class SnapshotRecordManager imple
          }
          else
          {
-             assert( false );
+             throw new IllegalStateException( " Wrong action type " + actionContext );
          }
          
          unsetCurrentActionContext( actionContext );
@@ -196,7 +207,7 @@ public class SnapshotRecordManager imple
          }
          else
          {
-             assert( false );
+             throw new IllegalStateException( "Wrong action context type " + actionContext
);
          }
          
          unsetCurrentActionContext( actionContext );



Mime
View raw message