cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject svn commit: r1151495 - in /cassandra/branches/cassandra-0.8: CHANGES.txt src/java/org/apache/cassandra/utils/NodeId.java
Date Wed, 27 Jul 2011 15:22:47 GMT
Author: slebresne
Date: Wed Jul 27 15:22:46 2011
New Revision: 1151495

URL: http://svn.apache.org/viewvc?rev=1151495&view=rev
Log:
Use lazy initialization instead of class initialization in NodeId
patch by slebresne; reviewed by jbellis for CASSANDRA-2953

Modified:
    cassandra/branches/cassandra-0.8/CHANGES.txt
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/utils/NodeId.java

Modified: cassandra/branches/cassandra-0.8/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/CHANGES.txt?rev=1151495&r1=1151494&r2=1151495&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.8/CHANGES.txt Wed Jul 27 15:22:46 2011
@@ -9,6 +9,8 @@
  * log Java classpath on startup (CASSANDRA-2895)
  * keep gossipped version in sync with actual on migration coordinator 
    (CASSANDRA-2946)
+ * use lazy initialization instead of class initialization in NodeId
+   (CASSANDRA-2953)
 
 
 0.8.2

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/utils/NodeId.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/utils/NodeId.java?rev=1151495&r1=1151494&r2=1151495&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/utils/NodeId.java (original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/utils/NodeId.java Wed Jul
27 15:22:46 2011
@@ -35,13 +35,23 @@ public class NodeId implements Comparabl
 
     public static final int LENGTH = 16; // we assume a fixed length size for all NodeIds
 
-    private static final LocalNodeIdHistory localIds = new LocalNodeIdHistory();
+    // Lazy holder because this opens the system table and we want to avoid
+    // having this triggered during class initialization
+    private static class LocalIds
+    {
+        static final LocalNodeIdHistory instance = new LocalNodeIdHistory();
+    }
 
     private ByteBuffer id;
 
+    private static LocalNodeIdHistory localIds()
+    {
+        return LocalIds.instance;
+    }
+
     public static NodeId getLocalId()
     {
-        return localIds.current.get();
+        return localIds().current.get();
     }
 
     /**
@@ -51,7 +61,7 @@ public class NodeId implements Comparabl
      */
     public static synchronized void renewLocalId()
     {
-        localIds.renewCurrent();
+        localIds().renewCurrent();
     }
 
     /**
@@ -61,7 +71,7 @@ public class NodeId implements Comparabl
      */
     public static List<NodeIdRecord> getOldLocalNodeIds()
     {
-        return localIds.olds;
+        return localIds().olds;
     }
 
     /**



Mime
View raw message