import static me.prettyprint.cassandra.model.HFactory.*;
Once we’ve done that we create the cluster
Cluster c = HFactory.getOrCreateCluster("MyCluster", "154.36.xx.yyy:9160");
And that’s it !
However, note that we are now connected to only the machine in the cluster that we have named. we can get a list of all machines in the cluster like this:
Set <String>hosts= c.getClusterHosts(true); Iterator it =hosts.iterator(); while (it.hasNext()) { System.out.println(it.next()); }
The problem here is that we haven't got the port number of each machine in the cluster, nor do can we find out about the topology. Thanks to the Hector mail list folks for pointing this out.
If we want to know the clusters name:
System.out.println(c.describeClusterName());
Finally should we want to use the cluster with a V1 pool:
CassandraClient client =c.borrowClient();
and release it in a finally clause:
} finally { c.releaseClient(client); }
No comments:
Post a Comment