Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package me.prettyprint.cassandra.service;
  
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
 
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(s):
Ran Tavory
zznate
 
 public abstract class AbstractCluster implements Cluster {
   private static final Map<StringStringEMPTY_CREDENTIALS = Collections.emptyMap();
 
   private final Logger log = LoggerFactory.getLogger(AbstractCluster.class);
 
   protected final HConnectionManager connectionManager;
   private final String name;
   private final ClockResolution clockResolution;
   private final FailoverPolicy failoverPolicy;
   private Set<StringknownClusterHosts;
   protected final ExceptionsTranslator xtrans;
   private final Map<StringStringcredentials;
 
   public AbstractCluster(String clusterNameCassandraHostConfigurator cassandraHostConfigurator) {
     this(clusterNamecassandraHostConfigurator);
   }
 
   public AbstractCluster(String clusterNameCassandraHostConfigurator cassandraHostConfiguratorMap<StringStringcredentials) {
      = new HConnectionManager(cassandraHostConfigurator);
      = clusterName;
      = cassandraHostConfigurator;
      = new ExceptionsTranslatorImpl();
      = cassandraHostConfigurator.getClockResolution();
     this. = Collections.unmodifiableMap(credentials);
   }
 
   @Override
     return ;
   }
 
   /* (non-Javadoc)
    * @see me.prettyprint.cassandra.service.Cluster#getKnownPoolHosts(boolean)
    */
   @Override
   public Set<CassandraHostgetKnownPoolHosts(boolean refresh) {
     if (refresh ||  == null) {
       if ( .isInfoEnabled() ) {
         .info("found knownPoolHosts: {}");
       }
     }
     return ;
   }
 
 
   /* (non-Javadoc)
    * @see me.prettyprint.cassandra.service.Cluster#addHost(me.prettyprint.cassandra.service.CassandraHost, boolean)
    */
   @Override
   public void addHost(CassandraHost cassandraHostboolean skipApplyConfig) {
     if (!skipApplyConfig &&  != null) {
       .applyConfig(cassandraHost);
     }
    .addCassandraHost(cassandraHost);
  }
  /* (non-Javadoc)
   * @see me.prettyprint.cassandra.service.Cluster#getName()
   */
  public String getName() {
    return ;
  }
  /* (non-Javadoc)
   * @see me.prettyprint.cassandra.service.Cluster#describeKeyspaces()
   */
      @Override
      public List<KeyspaceDefinitionexecute(Cassandra.Client cassandrathrows HectorException {
        try {
          return ThriftKsDef.fromThriftList(cassandra.describe_keyspaces());
        } catch (Exception e) {
          throw .translate(e);
        }
      }
    };
    return op.getResult();
  }
  /* (non-Javadoc)
   * @see me.prettyprint.cassandra.service.Cluster#describeClusterName()
   */
  public String describeClusterName() throws HectorException {
      @Override
      public String execute(Cassandra.Client cassandrathrows HectorException {
        try {
          return cassandra.describe_cluster_name();
        } catch (Exception e) {
          throw .translate(e);
        }
      }
    };
    return op.getResult();
  }
  /* (non-Javadoc)
   * @see me.prettyprint.cassandra.service.Cluster#describeThriftVersion()
   */
      @Override
      public String execute(Cassandra.Client cassandrathrows HectorException {
        try {
          return cassandra.describe_version();
        } catch (Exception e) {
          throw .translate(e);
        }
      }
    };
    return op.getResult();
  }
  /* (non-Javadoc)
   * @see me.prettyprint.cassandra.service.Cluster#describeKeyspace(java.lang.String)
   */
  public KeyspaceDefinition describeKeyspace(final String keyspace)
  throws HectorException {
        .getCredentials()) {
      @Override
      public KeyspaceDefinition execute(Cassandra.Client cassandra)
      throws HectorException {
        try {
          return new ThriftKsDef(cassandra.describe_keyspace(keyspace));
        } catch (org.apache.cassandra.thrift.NotFoundException nfe) {
          setException(.translate(nfe));
          return null;
        } catch (Exception e) {
          throw .translate(e);
        }
      }
    };
    return op.getResult();
  }
  /* (non-Javadoc)
   * @see me.prettyprint.cassandra.service.Cluster#getClusterName()
   */
  public String getClusterName() throws HectorException {
    .info("in execute with client");
      @Override
      public String execute(Cassandra.Client cassandrathrows HectorException {
        try {
          .info("in execute with client {}"cassandra);
          return cassandra.describe_cluster_name();
        } catch (Exception e) {
          throw .translate(e);
        }
      }
    };
    return op.getResult();
  }
  public String dropKeyspace(final String keyspacethrows HectorException {
      @Override
      public String execute(Cassandra.Client cassandrathrows HectorException {
        try {
          return cassandra.system_drop_keyspace(keyspace);
        } catch (Exception e) {
          throw .translate(e);
        }
      }
    };
    return op.getResult();
  }
  public String describePartitioner() throws HectorException {
      @Override
      public String execute(Cassandra.Client cassandrathrows HectorException {
        try {
          if ( .isInfoEnabled() ) {
            .info("in execute with client {}"cassandra);
          }
          return cassandra.describe_partitioner();
        } catch (Exception e) {
          throw .translate(e);
        }
      }
    };
    return op.getResult();
  }
  public String dropColumnFamily(final String keyspaceNamefinal String columnFamilythrows HectorException {
      @Override
      public String execute(Cassandra.Client cassandrathrows HectorException {
        try {
          return cassandra.system_drop_column_family(columnFamily);
        } catch (Exception e) {
          throw .translate(e);
        }
      }
    };
    return op.getResult();
  }
  public Map<StringStringgetCredentials() {
    return ;
  }
    
New to GrepCode? Check out our FAQ X