Author: [email protected]
Date: Wed Feb 15 17:07:17 2012
New Revision: 2094

Log:
[AMDATUCASSANDRA-163] Fixed in the Cassandra client by keeping local map of 
created cluster instances. This means that only the Cassandra client uses the 
special configuration with the SchemaModificationsLoadBalancer. All other 
bundles using hector (ie invoking HFactory.getOrCreateCluster()) will 
automatically use the configuration of the Hector PM

Modified:
   
trunk/amdatu-cassandra/cassandra-client/src/main/java/org/amdatu/cassandra/client/service/CassandraClientServiceImpl.java

Modified: 
trunk/amdatu-cassandra/cassandra-client/src/main/java/org/amdatu/cassandra/client/service/CassandraClientServiceImpl.java
==============================================================================
--- 
trunk/amdatu-cassandra/cassandra-client/src/main/java/org/amdatu/cassandra/client/service/CassandraClientServiceImpl.java
   (original)
+++ 
trunk/amdatu-cassandra/cassandra-client/src/main/java/org/amdatu/cassandra/client/service/CassandraClientServiceImpl.java
   Wed Feb 15 17:07:17 2012
@@ -19,13 +19,14 @@
 import static 
org.amdatu.cassandra.client.service.CassandraClientConfigurationService.DEFAULT_REPLICATION_FACTOR;
 import static 
org.amdatu.cassandra.client.service.CassandraClientConfigurationService.SCHEMA_AGREEMENT_TIMEOUT;
 import me.prettyprint.cassandra.model.BasicKeyspaceDefinition;
+import me.prettyprint.cassandra.service.CassandraHostConfigurator;
 import me.prettyprint.cassandra.service.ThriftCfDef;
+import me.prettyprint.cassandra.service.ThriftCluster;
 import me.prettyprint.cassandra.service.ThriftKsDef;
 import me.prettyprint.hector.api.Cluster;
 import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
 import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
 import me.prettyprint.hector.api.exceptions.HectorException;
-import me.prettyprint.hector.api.factory.HFactory;
 
 import org.amdatu.cassandra.client.CassandraClientService;
 import org.amdatu.cassandra.client.ThriftException;
@@ -51,6 +52,9 @@
     private static final String SYSTEM_TABLE = "system";
     private static final String UNREACHABLE = "UNREACHABLE";
 
+    // Map of clusters for this client service
+    private static final Map<String, Cluster> m_clusters = new HashMap<String, 
Cluster>();
+    
     // Service dependencies, injected by the framework
     private volatile LogService m_logService;
     private volatile EventAdmin m_eventAdmin;
@@ -59,6 +63,7 @@
     // Local cache of ColumnTypes of all ColumnFamilies for each keyspace
     private Map<String, Map<String, String>> m_keyspaceColumnFamilyTypes = new 
HashMap<String, Map<String, String>>();
 
+    
     /**
      * The init() method is invoked by the Felix dependency manager.
      */
@@ -98,12 +103,23 @@
             // instead of the bundle classloader.
             
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
             String clusterName = m_configuration.get(CLUSTER_NAME, 
String.class);
-            return HFactory.getOrCreateCluster(clusterName, 
m_configuration.getCassandraHostConfigurator());
+            return getOrCreateCluster(clusterName, 
m_configuration.getCassandraHostConfigurator());
         }
         finally {
             Thread.currentThread().setContextClassLoader(oldClassLoader);
         }
     }
+    
+    private static Cluster getOrCreateCluster(String clusterName, 
CassandraHostConfigurator cassandraHostConfigurator) {
+        synchronized (m_clusters) {
+            Cluster cluster = m_clusters.get(clusterName);
+            if (cluster == null) {
+                cluster = new ThriftCluster(clusterName, 
cassandraHostConfigurator);
+                m_clusters.put(clusterName, cluster);
+            }
+            return cluster;
+        }
+    }
 
     public synchronized boolean keyspaceExists(final String keyspaceName) {
         List<String> ksNames = getKeyspaces();
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to