You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/07/28 16:36:26 UTC

svn commit: r980072 - in /directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor: CursorClosedException.java DefaultClosureMonitor.java

Author: elecharny
Date: Wed Jul 28 14:36:26 2010
New Revision: 980072

URL: http://svn.apache.org/viewvc?rev=980072&view=rev
Log:
Slight speed up if we simply close a cursor in normal cases: no need to create an Exception object in this case.

Modified:
    directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor/CursorClosedException.java
    directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor/DefaultClosureMonitor.java

Modified: directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor/CursorClosedException.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor/CursorClosedException.java?rev=980072&r1=980071&r2=980072&view=diff
==============================================================================
--- directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor/CursorClosedException.java (original)
+++ directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor/CursorClosedException.java Wed Jul 28 14:36:26 2010
@@ -29,6 +29,9 @@ public class CursorClosedException exten
 {
     private static final long serialVersionUID = -5723233489761854394L;
 
+    /** A static exception to be used by the monitor */
+    public static final CursorClosedException INSTANCE = new CursorClosedException();
+
 
     public CursorClosedException()
     {

Modified: directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor/DefaultClosureMonitor.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor/DefaultClosureMonitor.java?rev=980072&r1=980071&r2=980072&view=diff
==============================================================================
--- directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor/DefaultClosureMonitor.java (original)
+++ directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor/DefaultClosureMonitor.java Wed Jul 28 14:36:26 2010
@@ -21,11 +21,11 @@ package org.apache.directory.shared.ldap
 
 
 /**
- * A basic ClosureMonitor that simply uses a boolean for state and a cause 
+ * A basic ClosureMonitor that simply uses a boolean for state and a cause
  * exception.
- * 
+ *
  * Note that we consciously chose not to synchronize close() operations with
- * checks to see if the monitor state is closed because it costs to 
+ * checks to see if the monitor state is closed because it costs to
  * synchronize and it's OK for the Cursor not to stop immediately when close()
  * is called.
  *
@@ -35,24 +35,24 @@ public class DefaultClosureMonitor imple
 {
     /** Tells if the monitor is closed or not */
     private boolean closed;
-    
+
     /** If we get an exception, the cause is stored in this variable */
     private Exception cause;
 
-    
+
     /**
      * {@inheritDoc}
      */
     public final void close()
     {
-        // state check needed to "try" not to overwrite exception (lack of 
+        // state check needed to "try" not to overwrite exception (lack of
         // synchronization may still allow overwriting but who cares that much
         if ( ! closed )
         {
-            // not going to sync because who cares if it takes a little longer 
-            // to stop but we need to set cause before toggling closed state 
-            // or else check for closure can throw null cause 
-            cause = new CursorClosedException();
+            // not going to sync because who cares if it takes a little longer
+            // to stop but we need to set cause before toggling closed state
+            // or else check for closure can throw null cause
+            cause = CursorClosedException.INSTANCE;
             closed = true;
         }
     }
@@ -63,13 +63,13 @@ public class DefaultClosureMonitor imple
      */
     public final void close( final String cause )
     {
-        // state check needed to "try" not to overwrite exception (lack of 
+        // state check needed to "try" not to overwrite exception (lack of
         // synchronization may still allow overwriting but who cares that much
         if ( ! closed )
         {
-            // not going to sync because who cares if it takes a little longer 
-            // to stop but we need to set cause before toggling closed state 
-            // or else check for closure can throw null cause 
+            // not going to sync because who cares if it takes a little longer
+            // to stop but we need to set cause before toggling closed state
+            // or else check for closure can throw null cause
             this.cause = new CursorClosedException( cause );
             closed = true;
         }
@@ -81,13 +81,13 @@ public class DefaultClosureMonitor imple
      */
     public final void close( final Exception cause )
     {
-        // state check needed to "try" not to overwrite exception (lack of 
+        // state check needed to "try" not to overwrite exception (lack of
         // synchronization may still allow overwriting but who cares that much
         if ( ! closed )
         {
-            // not going to sync because who cares if it takes a little longer 
-            // to stop but we need to set cause before toggling closed state 
-            // or else check for closure can throw null cause 
+            // not going to sync because who cares if it takes a little longer
+            // to stop but we need to set cause before toggling closed state
+            // or else check for closure can throw null cause
             this.cause = cause;
             closed = true;
         }