me.prettyprint.cassandra.service
Class AbstractCluster

java.lang.Object
  extended by me.prettyprint.cassandra.service.AbstractCluster
All Implemented Interfaces:
Cluster
Direct Known Subclasses:
ThriftCluster

public abstract class AbstractCluster
extends Object
implements Cluster

A cluster instance the client side representation of a cassandra server cluster. The cluster is usually the main entry point for programs using hector. To start operating on cassandra cluster you first get or create a cluster, then a keyspace operator for the keyspace you're interested in and then create mutations of queries //get a cluster: Cluster cluster = getOrCreateCluster("MyCluster", new CassandraHostConfigurator("127.0.0.1:9170")); //get a keyspace from this cluster: Keyspace ko = createKeyspace("Keyspace1", cluster); //Create a mutator: Mutator m = createMutator(ko); // Make a mutation: MutationResult mr = m.insert("key", cf, createColumn("name", "value", serializer, serializer)); THREAD SAFETY: This class is thread safe.

Author:
Ran Tavory, zznate

Field Summary
protected  HConnectionManager connectionManager
           
protected  ExceptionsTranslator xtrans
           
 
Constructor Summary
AbstractCluster(String clusterName, CassandraHostConfigurator cassandraHostConfigurator)
           
AbstractCluster(String clusterName, CassandraHostConfigurator cassandraHostConfigurator, Map<String,String> credentials)
           
 
Method Summary
 void addHost(CassandraHost cassandraHost, boolean skipApplyConfig)
          Adds the host to this Cluster.
 String describeClusterName()
           
 KeyspaceDefinition describeKeyspace(String keyspace)
           
 List<KeyspaceDefinition> describeKeyspaces()
           
 String describePartitioner()
           
 String describeThriftVersion()
           
 String dropColumnFamily(String keyspaceName, String columnFamily)
          Drops a column family and does not wait for schema agreement.
 String dropColumnFamily(String keyspaceName, String columnFamily, boolean blockUntilComplete)
          Drops a column family and wait for schema cluster agreement if blockUntilComplete is set to true.
 String dropKeyspace(String keyspace)
          Drops the Keyspace from the cluster.
 String dropKeyspace(String keyspace, boolean blockUntilComplete)
          Drops a Keyspace and wait for schema cluster agreement if blockUntilComplete is set to true.
 String getClusterName()
           
 HConnectionManager getConnectionManager()
           
 Map<String,String> getCredentials()
           
 Set<CassandraHost> getKnownPoolHosts(boolean refresh)
           
 String getName()
          Descriptive name of the cluster.
 void truncate(String keyspaceName, String columnFamily)
           
protected static void waitForSchemaAgreement(org.apache.cassandra.thrift.Cassandra.Client cassandra)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface me.prettyprint.hector.api.Cluster
addColumnFamily, addColumnFamily, addKeyspace, addKeyspace, describeRing, describeSchemaVersions, updateColumnFamily, updateColumnFamily, updateKeyspace, updateKeyspace
 

Field Detail

connectionManager

protected final HConnectionManager connectionManager

xtrans

protected final ExceptionsTranslator xtrans
Constructor Detail

AbstractCluster

public AbstractCluster(String clusterName,
                       CassandraHostConfigurator cassandraHostConfigurator)

AbstractCluster

public AbstractCluster(String clusterName,
                       CassandraHostConfigurator cassandraHostConfigurator,
                       Map<String,String> credentials)
Method Detail

getConnectionManager

public HConnectionManager getConnectionManager()
Specified by:
getConnectionManager in interface Cluster

getKnownPoolHosts

public Set<CassandraHost> getKnownPoolHosts(boolean refresh)
Specified by:
getKnownPoolHosts in interface Cluster

addHost

public void addHost(CassandraHost cassandraHost,
                    boolean skipApplyConfig)
Description copied from interface: Cluster
Adds the host to this Cluster. Unless skipApplyConfig is set to true, the settings in the CassandraHostConfigurator will be applied to the provided CassandraHost

Specified by:
addHost in interface Cluster

getName

public String getName()
Description copied from interface: Cluster
Descriptive name of the cluster. This name is used to identify the cluster.

Specified by:
getName in interface Cluster
Returns:

describeKeyspaces

public List<KeyspaceDefinition> describeKeyspaces()
                                           throws HectorException
Specified by:
describeKeyspaces in interface Cluster
Throws:
HectorException

describeClusterName

public String describeClusterName()
                           throws HectorException
Specified by:
describeClusterName in interface Cluster
Throws:
HectorException

describeThriftVersion

public String describeThriftVersion()
                             throws HectorException
Specified by:
describeThriftVersion in interface Cluster
Throws:
HectorException

describeKeyspace

public KeyspaceDefinition describeKeyspace(String keyspace)
                                    throws HectorException
Specified by:
describeKeyspace in interface Cluster
Throws:
HectorException

getClusterName

public String getClusterName()
                      throws HectorException
Specified by:
getClusterName in interface Cluster
Throws:
HectorException

dropKeyspace

public String dropKeyspace(String keyspace)
                    throws HectorException
Description copied from interface: Cluster
Drops the Keyspace from the cluster. Equivalent of 'drop database' in SQL terms. Does not wait for schema agreement.

Specified by:
dropKeyspace in interface Cluster
Throws:
HectorException

dropKeyspace

public String dropKeyspace(String keyspace,
                           boolean blockUntilComplete)
                    throws HectorException
Description copied from interface: Cluster
Drops a Keyspace and wait for schema cluster agreement if blockUntilComplete is set to true. Otherwise it behaves exactly like: Cluster.dropKeyspace(String)

Specified by:
dropKeyspace in interface Cluster
Throws:
HectorException

describePartitioner

public String describePartitioner()
                           throws HectorException
Specified by:
describePartitioner in interface Cluster
Throws:
HectorException

dropColumnFamily

public String dropColumnFamily(String keyspaceName,
                               String columnFamily)
                        throws HectorException
Description copied from interface: Cluster
Drops a column family and does not wait for schema agreement.

Specified by:
dropColumnFamily in interface Cluster
Throws:
HectorException

dropColumnFamily

public String dropColumnFamily(String keyspaceName,
                               String columnFamily,
                               boolean blockUntilComplete)
                        throws HectorException
Description copied from interface: Cluster
Drops a column family and wait for schema cluster agreement if blockUntilComplete is set to true. Otherwise it behaves exactly like: Cluster.dropColumnFamily(String, String)

Specified by:
dropColumnFamily in interface Cluster
Throws:
HectorException

getCredentials

public Map<String,String> getCredentials()
Specified by:
getCredentials in interface Cluster

truncate

public void truncate(String keyspaceName,
                     String columnFamily)
              throws HectorException
Specified by:
truncate in interface Cluster
Throws:
HectorException

waitForSchemaAgreement

protected static void waitForSchemaAgreement(org.apache.cassandra.thrift.Cassandra.Client cassandra)
                                      throws org.apache.cassandra.thrift.InvalidRequestException,
                                             org.apache.thrift.TException,
                                             InterruptedException
Throws:
org.apache.cassandra.thrift.InvalidRequestException
org.apache.thrift.TException
InterruptedException


Copyright © 2011. All Rights Reserved.