You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2010/02/05 18:09:40 UTC

svn commit: r907005 - /incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java

Author: jbellis
Date: Fri Feb  5 17:09:39 2010
New Revision: 907005

URL: http://svn.apache.org/viewvc?rev=907005&view=rev
Log:
make init* methods idempotent.  patch by Stu Hood and jbellis for CASSANDRA-342

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java?rev=907005&r1=907004&r2=907005&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java Fri Feb  5 17:09:39 2010
@@ -143,6 +143,7 @@
     private Multimap<InetAddress, String> bootstrapSet;
     /* when intialized as a client, we shouldn't write to the system table. */
     private boolean isClientMode;
+    private boolean initialized;
 
     public synchronized void addBootstrapSource(InetAddress s, String table)
     {
@@ -257,8 +258,15 @@
         MessagingService.shutdown();
     }
 
-    public void initClient() throws IOException
+    public synchronized void initClient() throws IOException
     {
+        if (initialized)
+        {
+            if (!isClientMode)
+                throw new UnsupportedOperationException("StorageService does not support switching modes.");
+            return;
+        }
+        initialized = true;
         isClientMode = true;
         logger_.info("Starting up client gossip");
         MessagingService.instance.listen(FBUtilities.getLocalAddress());
@@ -266,8 +274,15 @@
         Gossiper.instance.start(FBUtilities.getLocalAddress(), (int)(System.currentTimeMillis() / 1000)); // needed for node-ring gathering.
     }
 
-    public void initServer() throws IOException
+    public synchronized void initServer() throws IOException
     {
+        if (initialized)
+        {
+            if (isClientMode)
+                throw new UnsupportedOperationException("StorageService does not support switching modes.");
+            return;
+        }
+        initialized = true;
         isClientMode = false;
         storageMetadata_ = SystemTable.initMetadata();
         DatabaseDescriptor.createAllDirectories();