Package com.netflix.astyanax.AstyanaxContext

Examples of com.netflix.astyanax.AstyanaxContext.Builder


        .withConnectionPoolMonitor(new CountingConnectionPoolMonitor());
    }


    public static AstyanaxContext<Keyspace> newContext(String hostString, String keyspace) {
        Builder builder = newBuilder(hostString);
        AstyanaxContext<Keyspace> context = builder.forKeyspace(keyspace).buildKeyspace(ThriftFamilyFactory.getInstance());
        context.start();
        return context;
    }
View Full Code Here


        context.start();
        return context;
    }
   
    public static AstyanaxContext<Cluster> newClusterContext(String hostString){
        Builder builder = newBuilder(hostString);
        AstyanaxContext<Cluster> context = builder.buildCluster(ThriftFamilyFactory.getInstance());
        context.start();
        return context;
    }
View Full Code Here

                logger.info("ConnectionPoolConfiguration: " + poolConfig.toString());

                ConnectionPoolMonitor connectionPoolMonitor = new CountingConnectionPoolMonitor();
                // set this as field for logging purpose only.
                Builder builder = new AstyanaxContext.Builder();
                builder.forCluster(getClusterName());
                builder.forKeyspace(getKeyspaceName());
                builder.withAstyanaxConfiguration(configuration);
                builder.withConnectionPoolConfiguration(poolConfig);
                builder.withConnectionPoolMonitor(connectionPoolMonitor);
                builder.withConnectionPoolMonitor(new CountingConnectionPoolMonitor());

                context = builder.buildKeyspace(ThriftFamilyFactory.getInstance());
                context.start();
                keyspace = context.getEntity();
                return keyspace;
            }
            catch (Exception e)
View Full Code Here

//    else if(clusterNameObj == null || !(clusterNameObj instanceof String))
//      throw new IllegalArgumentException("The property Bootstrap.CLUSTER_NAME was not in the Map or was in the Map but not as a String");
    if(builderObj == null || !(builderObj instanceof Builder))
      throw new IllegalArgumentException("The property Bootstrap.CASSANDRA_BUILDER was not in the Map or was in Map but was not of type Builder and must be supplied when using Cassandra plugin");

    Builder builder = (Builder) builderObj;
    clusterContext = builder.buildCluster(ThriftFamilyFactory.getInstance());
    keyspaceName = clusterContext.getKeyspaceName();
    if(keyspaceName == null)
      throw new IllegalArgumentException("You did not call Builder.forKeyspace on the astyanax Builder api.  We need to know the keyspace to continue");
   
    clusterContext.start();
   
    cluster = clusterContext.getEntity();
    List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces();
    boolean exists = false;
    for(KeyspaceDefinition kDef : keyspaces) {
      if(keyspaceName.equalsIgnoreCase(kDef.getName())) {
        exists = true;
        break;
      }
    }

    if(!exists) {
      KeyspaceDefinition def = cluster.makeKeyspaceDefinition();
      def.setName(keyspaceName);
      def.setStrategyClass("org.apache.cassandra.locator.SimpleStrategy");
      Map<String, String> map = new HashMap<String, String>();
      map.put("replication_factor", "3");
      def.setStrategyOptions(map);
      cluster.addKeyspace(def);
    }
   
    context = builder.buildKeyspace(ThriftFamilyFactory.getInstance());
    context.start();
   
    keyspace = context.getEntity();

    KeyspaceDefinition keySpaceMeta = keyspace.describeKeyspace();
View Full Code Here

  }
 
  @Override
  protected void createBestCassandraConfig(Map<String, Object> properties,
      String clusterName, String keyspace2, String seeds2) {
    Builder builder = new AstyanaxContext.Builder()
      .forCluster(clusterName)
      .forKeyspace(keyspace2)
      .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()     
          .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
          .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
      )
      .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
          .setMaxConnsPerHost(20)
          .setInitConnsPerHost(2)
          .setSeeds(seeds2)
          .setConnectTimeout(10000)
      )
      .withConnectionPoolMonitor(new CountingConnectionPoolMonitor());
   
   
  if(seeds2.contains(",")) {
    //for a multi-node cluster, we want the test suite using quorum on writes and
    //reads so we have no issues...
    AstyanaxConfigurationImpl config = new AstyanaxConfigurationImpl();
    config.setDefaultWriteConsistencyLevel(ConsistencyLevel.CL_QUORUM);
    config.setDefaultReadConsistencyLevel(ConsistencyLevel.CL_QUORUM);
    builder = builder.withAstyanaxConfiguration(config);
  }
  properties.put(Bootstrap.CASSANDRA_BUILDER, builder);
  }
View Full Code Here

      else
        throw new RuntimeException(Bootstrap.CASSANDRA_THRIFT_PORT+" key in map has a value of type="+port.getClass()+" but that must be a String or Integer");
      poolConfig.setPort(portVal);
    }
   
    Builder builder = new AstyanaxContext.Builder()
      .forCluster(clusterName)
      .forKeyspace(keyspace2)
      .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()     
          .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
          .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
    .setClock(new MicrosecondsAsyncClock())
      )
      .withConnectionPoolConfiguration(poolConfig)
      .withConnectionPoolMonitor(new CountingConnectionPoolMonitor());

    String clStr = (String) properties.get(Bootstrap.CASSANDRA_DEFAULT_CONSISTENCY_LEVEL);
    if(clStr != null) {
      ConsistencyLevel cl = null;
      for(ConsistencyLevel l : ConsistencyLevel.values()) {
        if(l.toString().equals(clStr)) {
          cl = l;
          break;
        }
      }
      if(cl == null)
        throw new IllegalArgumentException("Consistency level must be one of the strings mathcin astyanax ConsistencyLevel.XXXX");

      AstyanaxConfigurationImpl config = new AstyanaxConfigurationImpl();
      config.setDefaultWriteConsistencyLevel(cl);
      config.setDefaultReadConsistencyLevel(cl);
      builder = builder.withAstyanaxConfiguration(config);
    } else if(seeds2.contains(",")) {
      //for a multi-node cluster, we want the test suite using quorum on writes and
      //reads so we have no issues...
      AstyanaxConfigurationImpl config = new AstyanaxConfigurationImpl();
      config.setDefaultWriteConsistencyLevel(ConsistencyLevel.CL_QUORUM);
      config.setDefaultReadConsistencyLevel(ConsistencyLevel.CL_QUORUM);
      builder = builder.withAstyanaxConfiguration(config);
    }
    properties.put(Bootstrap.CASSANDRA_BUILDER, builder);
  }
View Full Code Here

    return impl;
  }
  @Override
  protected void createBestCassandraConfig(Map<String, Object> properties,
      String clusterName, String keyspace2, String seeds2) {
    Builder builder = new AstyanaxContext.Builder()
      .forCluster(clusterName)
      .forKeyspace(keyspace2)
      .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()     
          .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
      )
      .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
          .setMaxConnsPerHost(2)
          .setInitConnsPerHost(2)
          .setSeeds(seeds2)
      )
      .withConnectionPoolMonitor(new CountingConnectionPoolMonitor());
   
   
  if(seeds2.contains(",")) {
    //for a multi-node cluster, we want the test suite using quorum on writes and
    //reads so we have no issues...
    AstyanaxConfigurationImpl config = new AstyanaxConfigurationImpl();
    config.setDefaultWriteConsistencyLevel(ConsistencyLevel.CL_QUORUM);
    config.setDefaultReadConsistencyLevel(ConsistencyLevel.CL_QUORUM);
    builder = builder.withAstyanaxConfiguration(config);
  }
  properties.put(Bootstrap.CASSANDRA_BUILDER, builder);
  }
View Full Code Here

//    else if(clusterNameObj == null || !(clusterNameObj instanceof String))
//      throw new IllegalArgumentException("The property Bootstrap.CLUSTER_NAME was not in the Map or was in the Map but not as a String");
    if(builderObj == null || !(builderObj instanceof Builder))
      throw new IllegalArgumentException("The property Bootstrap.CASSANDRA_BUILDER was not in the Map or was in Map but was not of type Builder and must be supplied when using Cassandra plugin");

    Builder builder = (Builder) builderObj;
    clusterContext = builder.buildCluster(ThriftFamilyFactory.getInstance());
    keyspaceName = clusterContext.getKeyspaceName();
    if(keyspaceName == null)
      throw new IllegalArgumentException("You did not call Builder.forKeyspace on the astyanax Builder api.  We need to know the keyspace to continue");
   
    clusterContext.start();
   
    cluster = clusterContext.getEntity();
    List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces();
    boolean exists = false;
    for(KeyspaceDefinition kDef : keyspaces) {
      if(keyspaceName.equalsIgnoreCase(kDef.getName())) {
        exists = true;
        break;
      }
    }

    if(!exists) {
      KeyspaceDefinition def = cluster.makeKeyspaceDefinition();
      def.setName(keyspaceName);
      def.setStrategyClass("org.apache.cassandra.locator.SimpleStrategy");
      Map<String, String> map = new HashMap<String, String>();
      map.put("replication_factor", "3");
      def.setStrategyOptions(map);
      cluster.addKeyspace(def);
    }
   
    context = builder.buildKeyspace(ThriftFamilyFactory.getInstance());
    context.start();
   
    keyspace = context.getEntity();

    KeyspaceDefinition keySpaceMeta = keyspace.describeKeyspace();
View Full Code Here

    return impl;
  }
  @Override
  protected void createBestCassandraConfig(Map<String, Object> properties,
      String clusterName, String keyspace2, String seeds2) {
    Builder builder = new AstyanaxContext.Builder()
      .forCluster(clusterName)
      .forKeyspace(keyspace2)
      .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()     
          .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
      )
      .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
          .setMaxConnsPerHost(2)
          .setInitConnsPerHost(2)
          .setSeeds(seeds2)
      )
      .withConnectionPoolMonitor(new CountingConnectionPoolMonitor());
   
   
    if(!"localhost:9160".equals(seeds2)) {
      if(!seeds2.contains(","))
        throw new IllegalArgumentException("You must specify a comma delimited list of seeds OR 'localhost:9160' as the seed");
      //for a multi-node cluster, we want the test suite using quorum on writes and
      //reads so we have no issues...
      AstyanaxConfigurationImpl config = new AstyanaxConfigurationImpl();
      config.setDefaultWriteConsistencyLevel(ConsistencyLevel.CL_QUORUM);
      config.setDefaultReadConsistencyLevel(ConsistencyLevel.CL_QUORUM);
      builder = builder.withAstyanaxConfiguration(config);
    }   
    properties.put(Bootstrap.CASSANDRA_BUILDER, builder);
  }
View Full Code Here

      else
        throw new RuntimeException(Bootstrap.CASSANDRA_THRIFT_PORT+" key in map has a value of type="+port.getClass()+" but that must be a String or Integer");
      poolConfig.setPort(portVal);
    }
   
    Builder builder = new AstyanaxContext.Builder()
      .forCluster(clusterName)
      .forKeyspace(keyspace2)
      .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()     
          .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
          .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
    .setClock(new MicrosecondsAsyncClock())
      )
      .withConnectionPoolConfiguration(poolConfig)
      .withConnectionPoolMonitor(new CountingConnectionPoolMonitor());

    String clStr = (String) properties.get(Bootstrap.CASSANDRA_DEFAULT_CONSISTENCY_LEVEL);
    if(clStr != null) {
      ConsistencyLevel cl = null;
      for(ConsistencyLevel l : ConsistencyLevel.values()) {
        if(l.toString().equals(clStr)) {
          cl = l;
          break;
        }
      }
      if(cl == null)
        throw new IllegalArgumentException("Consistency level must be one of the strings mathcin astyanax ConsistencyLevel.XXXX");

      AstyanaxConfigurationImpl config = new AstyanaxConfigurationImpl();
      config.setDefaultWriteConsistencyLevel(cl);
      config.setDefaultReadConsistencyLevel(cl);
      builder = builder.withAstyanaxConfiguration(config);
    } else if(seeds2.contains(",")) {
      //for a multi-node cluster, we want the test suite using quorum on writes and
      //reads so we have no issues...
      AstyanaxConfigurationImpl config = new AstyanaxConfigurationImpl();
      config.setDefaultWriteConsistencyLevel(ConsistencyLevel.CL_QUORUM);
      config.setDefaultReadConsistencyLevel(ConsistencyLevel.CL_QUORUM);
      builder = builder.withAstyanaxConfiguration(config);
    }
    properties.put(Bootstrap.CASSANDRA_BUILDER, builder);
  }
View Full Code Here

TOP

Related Classes of com.netflix.astyanax.AstyanaxContext.Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.