directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r947217 - /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/csn/CsnFactory.java
Date Sat, 22 May 2010 00:23:15 GMT
Author: elecharny
Date: Sat May 22 00:23:14 2010
New Revision: 947217

URL: http://svn.apache.org/viewvc?rev=947217&view=rev
Log:
o The changeCount does not need to be an AtomicInteger, it's already protected by a synchronization
o Get the changeCount value from inside the synchronized block before using it to create a
new CSN

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/csn/CsnFactory.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/csn/CsnFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/csn/CsnFactory.java?rev=947217&r1=947216&r2=947217&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/csn/CsnFactory.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/csn/CsnFactory.java
Sat May 22 00:23:14 2010
@@ -19,8 +19,6 @@
  */
 package org.apache.directory.shared.ldap.csn;
 
-import java.util.concurrent.atomic.AtomicInteger;
-
 
 /**
  * Generates a new {@link Csn}.
@@ -33,18 +31,21 @@ public class CsnFactory
     private static volatile long lastTimestamp;
     
     /** The integer used to disambiguate CSN generated at the same time */
-    private AtomicInteger changeCount;
+    private int changeCount;
     
     /** The replicaId to use for every CSN created by this factory */
     private int replicaId;
 
     /** A special instance ID for a purge CSN */
     private static final int PURGE_INSTANCEID = 0x0FFF;
+    
+    /** A lock used during the instance creation */
+    private Object lock = new Object();
 
 
     public CsnFactory( int replicaId )
     {
-        changeCount = new AtomicInteger( 0 );
+        changeCount = 0;
         this.replicaId = replicaId;
     }
 
@@ -56,23 +57,27 @@ public class CsnFactory
      */
     public Csn newInstance()
     {
-        synchronized ( changeCount )
+        int changeCount = 0;
+        
+        synchronized ( lock )
         {
             long newTimestamp = System.currentTimeMillis();
             
             // We will be able to generate 2 147 483 647 CSNs each 10 ms max
             if ( lastTimestamp == newTimestamp )
             {
-                changeCount.incrementAndGet();
+                this.changeCount++;
             }
             else
             {
                 lastTimestamp = newTimestamp;
-                changeCount.set( 0 );
+                this.changeCount = 0;
             }
+            
+            changeCount = this.changeCount;
         }
 
-        return new Csn( lastTimestamp, changeCount.get(), replicaId, 0 );
+        return new Csn( lastTimestamp, changeCount, replicaId, 0 );
     }
 
 



Mime
View raw message