Java 类com.datastax.driver.core.QueryOptions 实例源码

项目:flink-cassandra-connector-examples    文件:ClientSessionProvider.java   
public static Session getClientSession(String hostAddr) {
    if(REGISTRY.containsKey(hostAddr)) {
        return REGISTRY.get(hostAddr);
    } else {
        Cluster.Builder clientClusterBuilder = new Cluster.Builder()
                .addContactPoint(hostAddr)
                .withQueryOptions(new QueryOptions()
                        .setConsistencyLevel(ConsistencyLevel.ONE)
                        .setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL))
                .withoutJMXReporting()
                .withoutMetrics()
                .withReconnectionPolicy(new ConstantReconnectionPolicy(RECONNECT_DELAY_IN_MS));
        long startTimeInMillis = System.currentTimeMillis();
        Cluster clientCluster = clientClusterBuilder.build();
        Session clientSession = clientCluster.connect();

        LOG.info("Client session established after {} ms.", System.currentTimeMillis() - startTimeInMillis);
        REGISTRY.putIfAbsent(hostAddr, clientSession);
        return clientSession;
    }
}
项目:dmaap-framework    文件:CassandraConfigDb.java   
public CassandraConfigDb(List<String> contactPoints, int port) {

    this.contactPoints = new ArrayList<InetAddress> (contactPoints.size());

    for (String contactPoint : contactPoints) {
        try {
            this.contactPoints.add(InetAddress.getByName(contactPoint));
        } catch (UnknownHostException e) {
               throw new IllegalArgumentException(e.getMessage());
        }
    }

    this.port = port;

    cluster = (new Cluster.Builder()).withPort (this.port)
            .addContactPoints(this.contactPoints)
            .withSocketOptions(new SocketOptions().setReadTimeoutMillis(60000).setKeepAlive(true).setReuseAddress(true))
            .withLoadBalancingPolicy(new RoundRobinPolicy())
            .withReconnectionPolicy(new ConstantReconnectionPolicy(500L))
            .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.ONE))
            .build ();

    session = cluster.newSession();
    preparedStatements = new ConcurrentHashMap<StatementName, PreparedStatement> ();
    prepareStatementCreateLock = new Object();
}
项目:beam    文件:CassandraServiceImpl.java   
/**
 * Get a Cassandra cluster using hosts and port.
 */
private Cluster getCluster(List<String> hosts, int port, String username, String password,
                           String localDc, String consistencyLevel) {
  Cluster.Builder builder = Cluster.builder()
      .addContactPoints(hosts.toArray(new String[0]))
      .withPort(port);

  if (username != null) {
    builder.withAuthProvider(new PlainTextAuthProvider(username, password));
  }

  if (localDc != null) {
    builder.withLoadBalancingPolicy(
        new TokenAwarePolicy(new DCAwareRoundRobinPolicy.Builder().withLocalDc(localDc).build()));
  } else {
    builder.withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
  }

  if (consistencyLevel != null) {
    builder.withQueryOptions(
        new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevel)));
  }

  return builder.build();
}
项目:storm-cassandra-cql    文件:MapConfiguredCqlClientFactory.java   
private void configureQueryOptions() {

        final String consistencyConfiguration = (String) configuration.get(TRIDENT_CASSANDRA_CONSISTENCY);
        final String serialConsistencyConfiguration = (String) configuration.get(TRIDENT_CASSANDRA_SERIAL_CONSISTENCY);
        final QueryOptions queryOptions = builder.getConfiguration().getQueryOptions();

        if (StringUtils.isNotEmpty(consistencyConfiguration)) {
            queryOptions.setConsistencyLevel(ConsistencyLevel.valueOf(consistencyConfiguration));
        }

        if (StringUtils.isNotEmpty(serialConsistencyConfiguration)) {
            queryOptions.setSerialConsistencyLevel(ConsistencyLevel.valueOf(serialConsistencyConfiguration));
        }

        builder = builder.withQueryOptions(queryOptions);

    }
项目:Mache    文件:MacheAbstractCassandraKafkaSamplerClient.java   
protected void createCache(Map<String, String> mapParams) throws Exception {
    final Cluster.Builder bluePrint = Cluster.builder().withClusterName("BluePrint")
            .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM))
            .withRetryPolicy(DefaultRetryPolicy.INSTANCE)
            .withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy()))
            .addContactPoint(mapParams.get("cassandra.server.ip.address")).withPort(9042);

    cache1 = mache(String.class, CassandraTestEntity.class)
            .cachedBy(guava())
            .storedIn(cassandra()
                    .withCluster(bluePrint)
                    .withKeyspace(mapParams.get("keyspace.name"))
                    .withSchemaOptions(SchemaOptions.CREATE_SCHEMA_IF_NEEDED)
                    .build())
            .withMessaging(kafka()
                    .withKafkaMqConfig(KafkaMqConfigBuilder.builder()
                            .withZkHost(mapParams.get("kafka.connection"))
                            .build())
                    .withTopic(mapParams.get("kafka.topic"))
                    .build())
            .macheUp();
}
项目:jena-nosql    文件:CassandraStorageLayerFactory.java   
/**
 * Creates the query options for this factory.
 * 
 * @param configuration the configuration.
 * @return the query options for this factory.
 */
private QueryOptions configureQueryOptions(final Configuration<Map<String, Object>> configuration) {
    final QueryOptions queryOptions = new QueryOptions();

    queryOptions.setConsistencyLevel(
                ConsistencyLevel.valueOf(
                        configuration.getParameter(
                                "consistency_level",
                                "ONE")));

    queryOptions.setSerialConsistencyLevel(
                ConsistencyLevel.valueOf(
                        configuration.getParameter(
                                "serial_consistency_level",
                                "ONE")));

    queryOptions.setFetchSize(configuration.getParameter(
                    "fetch_size",
                    1000));

    return queryOptions;
}
项目:glowroot    文件:CentralModule.java   
private static Cluster createCluster(CentralConfiguration centralConfig,
        TimestampGenerator defaultTimestampGenerator) {
    Cluster.Builder builder = Cluster.builder()
            .addContactPoints(
                    centralConfig.cassandraContactPoint().toArray(new String[0]))
            // aggressive reconnect policy seems ok since not many clients
            .withReconnectionPolicy(new ConstantReconnectionPolicy(1000))
            // let driver know that only idempotent queries are used so it will retry on timeout
            .withQueryOptions(new QueryOptions()
                    .setDefaultIdempotence(true)
                    .setConsistencyLevel(centralConfig.cassandraConsistencyLevel()))
            // central runs lots of parallel async queries and is very spiky since all
            // aggregates come in right after each minute marker
            .withPoolingOptions(
                    new PoolingOptions().setMaxQueueSize(Session.MAX_CONCURRENT_QUERIES))
            .withTimestampGenerator(defaultTimestampGenerator);
    String cassandraUsername = centralConfig.cassandraUsername();
    if (!cassandraUsername.isEmpty()) {
        // empty password is strange but valid
        builder.withCredentials(cassandraUsername, centralConfig.cassandraPassword());
    }
    return builder.build();
}
项目:hawkular-metrics    文件:JobSchedulerTest.java   
@BeforeSuite
public static void initSuite() {
    Cluster cluster = Cluster.builder()
            .addContactPoints("127.0.0.01")
            .withQueryOptions(new QueryOptions().setRefreshSchemaIntervalMillis(0))
            .build();
    String keyspace = System.getProperty("keyspace", "hawkulartest");
    session = cluster.connect("system");
    rxSession = new RxSessionImpl(session);

    boolean resetdb = Boolean.valueOf(System.getProperty("resetdb", "true"));

    SchemaService schemaService = new SchemaService();
    schemaService.run(session, keyspace, resetdb);

    session.execute("USE " + keyspace);

    jobsService = new JobsService(rxSession);

    findFinishedJobs = session.prepare("SELECT job_id FROM finished_jobs_idx WHERE time_slice = ?");
    getActiveTimeSlices = session.prepare("SELECT distinct time_slice FROM active_time_slices");
    addActiveTimeSlice = session.prepare("INSERT INTO active_time_slices (time_slice) VALUES (?)");
}
项目:hawkular-metrics    文件:BaseITest.java   
@BeforeSuite
public static void initSuite() {
    String nodeAddresses = System.getProperty("nodes", "127.0.0.1");
    Cluster cluster = new Cluster.Builder()
            .addContactPoints(nodeAddresses.split(","))
            .withQueryOptions(new QueryOptions().setRefreshSchemaIntervalMillis(0))
            .build();
    session = cluster.connect();
    rxSession = new RxSessionImpl(session);

    SchemaService schemaService = new SchemaService();
    schemaService.run(session, getKeyspace(), Boolean.valueOf(System.getProperty("resetdb", "true")));

    session.execute("USE " + getKeyspace());

    metricRegistry = new HawkularMetricRegistry();
    metricRegistry.setMetricNameService(new MetricNameService());
}
项目:gora    文件:CassandraClient.java   
private Cluster.Builder populateQueryOptions(Properties properties, Cluster.Builder builder) {
  String consistencyLevelProp = properties.getProperty(CassandraStoreParameters.CONSISTENCY_LEVEL);
  String serialConsistencyLevelProp = properties.getProperty(CassandraStoreParameters.SERIAL_CONSISTENCY_LEVEL);
  String fetchSize = properties.getProperty(CassandraStoreParameters.FETCH_SIZE);
  QueryOptions options = new QueryOptions();
  if (consistencyLevelProp != null) {
    options.setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevelProp));
  }
  if (serialConsistencyLevelProp != null) {
    options.setSerialConsistencyLevel(ConsistencyLevel.valueOf(serialConsistencyLevelProp));
  }
  if (fetchSize != null) {
    options.setFetchSize(Integer.parseInt(fetchSize));
  }
  return builder.withQueryOptions(options);
}
项目:carbon-data    文件:CassandraConfig.java   
private Builder populateQueryOptions(Map<String, String> properties, Builder builder) {
    String consistencyLevelProp = properties.get(DBConstants.Cassandra.CONSISTENCY_LEVEL);
    String serialConsistencyLevelProp = properties.get(DBConstants.Cassandra.SERIAL_CONSISTENCY_LEVEL);
    String fetchSize = properties.get(DBConstants.Cassandra.FETCH_SIZE);
    QueryOptions options = new QueryOptions();
    if (consistencyLevelProp != null) {
        options.setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevelProp));
    }
    if (serialConsistencyLevelProp != null) {
        options.setSerialConsistencyLevel(ConsistencyLevel.valueOf(serialConsistencyLevelProp));
    }
    if (fetchSize != null) {
        options.setFetchSize(Integer.parseInt(fetchSize));
    }
    return builder.withQueryOptions(options);
}
项目:Armory    文件:CassandraConfiguration.java   
private QueryOptions getQueryOptions(CassandraProperties properties) {
    QueryOptions options = new QueryOptions();
    if (properties.getConsistencyLevel() != null) {
        options.setConsistencyLevel(properties.getConsistencyLevel());
    }
    if (properties.getSerialConsistencyLevel() != null) {
        options.setSerialConsistencyLevel(properties.getSerialConsistencyLevel());
    }
    options.setFetchSize(properties.getFetchSize());
    return options;
}
项目:ats-framework    文件:CassandraDbProvider.java   
/**
 * Currently we connect just once and then reuse the connection.
 * We do not bother with closing the connection.
 *
 * It is normal to use one Session per DB. The Session is thread safe.
 */
private void connect() {

    if (cluster == null) {

        log.info("Connecting to Cassandra server on " + this.dbHost + " at port " + this.dbPort);

        // allow fetching as much data as present in the DB
        QueryOptions queryOptions = new QueryOptions();
        queryOptions.setFetchSize(Integer.MAX_VALUE);
        queryOptions.setConsistencyLevel(ConsistencyLevel.ONE);

        cluster = Cluster.builder()
                         .addContactPoint(this.dbHost)
                         .withPort(this.dbPort)
                         .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()))
                         .withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 30000))
                         .withQueryOptions(queryOptions)
                         .withCredentials(this.dbUser, this.dbPassword)
                         .build();

    }

    if (session == null) {

        log.info("Connecting to Cassandra DB with name " + this.dbName);
        session = cluster.connect(dbName);
    }
}
项目:xm-gate    文件:CassandraConfiguration.java   
private static QueryOptions getQueryOptions(CassandraProperties properties) {
    QueryOptions options = new QueryOptions();
    if (properties.getConsistencyLevel() != null) {
        options.setConsistencyLevel(properties.getConsistencyLevel());
    }
    if (properties.getSerialConsistencyLevel() != null) {
        options.setSerialConsistencyLevel(properties.getSerialConsistencyLevel());
    }
    options.setFetchSize(properties.getFetchSize());
    return options;
}
项目:eventapis    文件:CassandraSession.java   
private QueryOptions getQueryOptions() {
    QueryOptions options = new QueryOptions();
    if (eventStoreConfig.getConsistencyLevel() != null) {
        options.setConsistencyLevel(eventStoreConfig.getConsistencyLevel());
    }
    if (eventStoreConfig.getSerialConsistencyLevel() != null) {
        options.setSerialConsistencyLevel(eventStoreConfig.getSerialConsistencyLevel());
    }
    options.setFetchSize(eventStoreConfig.getFetchSize());
    return options;
}
项目:devoxxus-jhipster-microservices-demo    文件:CassandraConfiguration.java   
private QueryOptions getQueryOptions(CassandraProperties properties) {
    QueryOptions options = new QueryOptions();
    if (properties.getConsistencyLevel() != null) {
        options.setConsistencyLevel(properties.getConsistencyLevel());
    }
    if (properties.getSerialConsistencyLevel() != null) {
        options.setSerialConsistencyLevel(properties.getSerialConsistencyLevel());
    }
    options.setFetchSize(properties.getFetchSize());
    return options;
}
项目:Microservices-with-JHipster-and-Spring-Boot    文件:CassandraConfiguration.java   
private QueryOptions getQueryOptions(CassandraProperties properties) {
    QueryOptions options = new QueryOptions();
    if (properties.getConsistencyLevel() != null) {
        options.setConsistencyLevel(properties.getConsistencyLevel());
    }
    if (properties.getSerialConsistencyLevel() != null) {
        options.setSerialConsistencyLevel(properties.getSerialConsistencyLevel());
    }
    options.setFetchSize(properties.getFetchSize());
    return options;
}
项目:vos_backend    文件:Cassandra.java   
/**
 * initConnection
 * tries connect to one of cassandra instances defined in CassandraProperties
 * @throws Exception
 */
private synchronized void initConnection () throws Exception {

  for (int i = 0; i < this.topology.size(); i ++) {

    for (int j = 0; j < this.connectRetries; j ++) {

      try {

        this.cluster =
          Cluster.builder()
            .addContactPoint(this.topology.get(i).getIp() )
            .withQueryOptions(
              new QueryOptions().setFetchSize(this.fetchSize) )
            .build();
        this.cluster.init();
        this.session = this.cluster.connect();

        reconnectFlag.set(false);

        return;
      } catch (Exception e) {

        if (i == (this.topology.size() - 1) &&
            j == (this.connectRetries - 1) ) {

          reconnectFlag.set(false);

          throw e;
        }
      }
    }
  }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:CassandraAutoConfiguration.java   
private QueryOptions getQueryOptions() {
    QueryOptions options = new QueryOptions();
    CassandraProperties properties = this.properties;
    if (properties.getConsistencyLevel() != null) {
        options.setConsistencyLevel(properties.getConsistencyLevel());
    }
    if (properties.getSerialConsistencyLevel() != null) {
        options.setSerialConsistencyLevel(properties.getSerialConsistencyLevel());
    }
    options.setFetchSize(properties.getFetchSize());
    return options;
}
项目:Thesis-JHipster    文件:_CassandraConfiguration.java   
private QueryOptions getQueryOptions(CassandraProperties properties) {
    QueryOptions options = new QueryOptions();
    if (properties.getConsistencyLevel() != null) {
        options.setConsistencyLevel(properties.getConsistencyLevel());
    }
    if (properties.getSerialConsistencyLevel() != null) {
        options.setSerialConsistencyLevel(properties.getSerialConsistencyLevel());
    }
    options.setFetchSize(properties.getFetchSize());
    return options;
}
项目:usergrid-qakka    文件:KeyspaceDropper.java   
public static void dropTestKeyspace( String keyspace, String[] hosts, int port ) {

        Cluster.Builder builder = Cluster.builder();
        for ( String host : hosts ) {
            builder = builder.addContactPoint( host ).withPort( port );
        }

        final QueryOptions queryOptions = new QueryOptions().setConsistencyLevel( ConsistencyLevel.LOCAL_QUORUM );
        builder.withQueryOptions( queryOptions );
        Cluster cluster = builder.build();

        Session session = cluster.connect();
        logger.info("Dropping test keyspace: {}", keyspace);
        session.execute( "DROP KEYSPACE IF EXISTS " + keyspace );
    }
项目:flink    文件:CassandraConnectorITCase.java   
@Override
protected Cluster buildCluster(Cluster.Builder builder) {
    return builder
        .addContactPointsWithPorts(new InetSocketAddress(HOST, PORT))
        .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.ONE).setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL))
        .withoutJMXReporting()
        .withoutMetrics().build();
}
项目:flink    文件:CassandraConnectorITCase.java   
@Override
protected Cluster buildCluster(Cluster.Builder builder) {
    return builder
        .addContactPoint("127.0.0.1")
        .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.ONE).setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL))
        .withoutJMXReporting()
        .withoutMetrics().build();
}
项目:spring-boot-concourse    文件:CassandraAutoConfiguration.java   
private QueryOptions getQueryOptions() {
    QueryOptions options = new QueryOptions();
    CassandraProperties properties = this.properties;
    if (properties.getConsistencyLevel() != null) {
        options.setConsistencyLevel(properties.getConsistencyLevel());
    }
    if (properties.getSerialConsistencyLevel() != null) {
        options.setSerialConsistencyLevel(properties.getSerialConsistencyLevel());
    }
    options.setFetchSize(properties.getFetchSize());
    return options;
}
项目:cassandra-reaper    文件:CassandraStorage.java   
private static void overrideQueryOptions(CassandraFactory cassandraFactory) {
  // all INSERT and DELETE stmt prepared in this class are idempoten
  if (cassandraFactory.getQueryOptions().isPresent()
      && ConsistencyLevel.LOCAL_ONE != cassandraFactory.getQueryOptions().get().getConsistencyLevel()) {
    LOG.warn("Customization of cassandra's queryOptions is not supported and will be overridden");
  }
  cassandraFactory.setQueryOptions(java.util.Optional.of(new QueryOptions().setDefaultIdempotence(true)));
}
项目:cassandra-kmean    文件:CqlConfigHelper.java   
public static Cluster getInputCluster(String[] hosts, Configuration conf)
{
    int port = getInputNativePort(conf);
    Optional<AuthProvider> authProvider = getAuthProvider(conf);
    Optional<SSLOptions> sslOptions = getSSLOptions(conf);
    Optional<Integer> protocolVersion = getProtocolVersion(conf);
    LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(conf, hosts);
    SocketOptions socketOptions = getReadSocketOptions(conf);
    QueryOptions queryOptions = getReadQueryOptions(conf);
    PoolingOptions poolingOptions = getReadPoolingOptions(conf);

    Cluster.Builder builder = Cluster.builder()
                                     .addContactPoints(hosts)
                                     .withPort(port)
                                     .withCompression(ProtocolOptions.Compression.NONE);

    if (authProvider.isPresent())
        builder.withAuthProvider(authProvider.get());
    if (sslOptions.isPresent())
        builder.withSSL(sslOptions.get());

    if (protocolVersion.isPresent()) {
        builder.withProtocolVersion(protocolVersion.get());
    }
    builder.withLoadBalancingPolicy(loadBalancingPolicy)
           .withSocketOptions(socketOptions)
           .withQueryOptions(queryOptions)
           .withPoolingOptions(poolingOptions);

    return builder.build();
}
项目:cassandra-kmean    文件:CqlConfigHelper.java   
private static QueryOptions getReadQueryOptions(Configuration conf)
{
    String CL = ConfigHelper.getReadConsistencyLevel(conf);
    Optional<Integer> fetchSize = getInputPageRowSize(conf);
    QueryOptions queryOptions = new QueryOptions();
    if (CL != null && !CL.isEmpty())
        queryOptions.setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel.valueOf(CL));

    if (fetchSize.isPresent())
        queryOptions.setFetchSize(fetchSize.get());
    return queryOptions;
}
项目:contestparser    文件:CassandraAutoConfiguration.java   
private QueryOptions getQueryOptions() {
    QueryOptions options = new QueryOptions();
    CassandraProperties properties = this.properties;
    if (properties.getConsistencyLevel() != null) {
        options.setConsistencyLevel(properties.getConsistencyLevel());
    }
    if (properties.getSerialConsistencyLevel() != null) {
        options.setSerialConsistencyLevel(properties.getSerialConsistencyLevel());
    }
    options.setFetchSize(properties.getFetchSize());
    return options;
}
项目:heroic    文件:ManagedSetupConnection.java   
public AsyncFuture<Connection> construct() {
    AsyncFuture<Session> session = async.call(() -> {
        // @formatter:off
        final PoolingOptions pooling = new PoolingOptions();

        final QueryOptions queryOptions = new QueryOptions()
            .setFetchSize(fetchSize)
            .setConsistencyLevel(consistencyLevel);

        final SocketOptions socketOptions = new SocketOptions()
            .setReadTimeoutMillis((int) readTimeout.toMilliseconds());

        final Cluster.Builder cluster = Cluster.builder()
            .addContactPointsWithPorts(seeds)
            .withRetryPolicy(retryPolicy)
            .withPoolingOptions(pooling)
            .withQueryOptions(queryOptions)
            .withSocketOptions(socketOptions)
            .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
        // @formatter:on

        authentication.accept(cluster);
        return cluster.build().connect();
    });

    if (configure) {
        session = session.lazyTransform(s -> {
            return schema.configure(s).directTransform(i -> s);
        });
    }

    return session.lazyTransform(s -> {
        return schema.instance(s).directTransform(schema -> {
            return new Connection(s, schema);
        });
    });
}
项目:storm-cassandra-cql    文件:ConstructorConfiguredCqlClientFactory.java   
public Cluster.Builder getClusterBuilder() {

        final List<InetSocketAddress> sockets = new ArrayList<InetSocketAddress>();
        for (String host : hosts) {
            if(StringUtils.contains(host, ":")) {
                String hostParts [] = StringUtils.split(host, ":");
                sockets.add(new InetSocketAddress(hostParts[0], Integer.valueOf(hostParts[1])));
                LOG.debug("Connecting to [" + host + "] with port [" + hostParts[1] + "]");
            } else {
                sockets.add(new InetSocketAddress(host, ProtocolOptions.DEFAULT_PORT));
                LOG.debug("Connecting to [" + host + "] with port [" + ProtocolOptions.DEFAULT_PORT + "]");
            }
        }

        Cluster.Builder builder = Cluster.builder().addContactPointsWithPorts(sockets).withCompression(compression);
        QueryOptions queryOptions = new QueryOptions();
        queryOptions.setConsistencyLevel(clusterConsistencyLevel);
        queryOptions.setSerialConsistencyLevel(serialConsistencyLevel);
        builder = builder.withQueryOptions(queryOptions);

        if (StringUtils.isNotEmpty(clusterName)) {
            builder = builder.withClusterName(clusterName);
        }

        return builder;

    }
项目:cassandra-jdbc-wrapper    文件:BuildCluster.java   
public static boolean isClusterActive(){
    try{
        Builder builder = Cluster.builder().withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.QUORUM).setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL));
        cluster = builder.addContactPoint("127.0.0.1").build();
        session = cluster.connect();
        return true;
    } catch(Exception e){
        return false;           
    }

}
项目:scylla-tools-java    文件:CqlConfigHelper.java   
public static Cluster getCluster(String[] hosts, Configuration conf, int port)
{
    Optional<AuthProvider> authProvider = getAuthProvider(conf);
    Optional<SSLOptions> sslOptions = getSSLOptions(conf);
    Optional<Integer> protocolVersion = getProtocolVersion(conf);
    LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(hosts);
    SocketOptions socketOptions = getReadSocketOptions(conf);
    QueryOptions queryOptions = getReadQueryOptions(conf);
    PoolingOptions poolingOptions = getReadPoolingOptions(conf);

    Cluster.Builder builder = Cluster.builder()
            .addContactPoints(hosts)
            .withPort(port)
            .withCompression(ProtocolOptions.Compression.NONE);

    if (authProvider.isPresent())
        builder.withAuthProvider(authProvider.get());
    if (sslOptions.isPresent())
        builder.withSSL(sslOptions.get());

    if (protocolVersion.isPresent()) {
        builder.withProtocolVersion(ProtocolVersion.fromInt(protocolVersion.get()));
    }
    builder.withLoadBalancingPolicy(loadBalancingPolicy)
            .withSocketOptions(socketOptions)
            .withQueryOptions(queryOptions)
            .withPoolingOptions(poolingOptions);

    return builder.build();
}
项目:scylla-tools-java    文件:CqlConfigHelper.java   
private static QueryOptions getReadQueryOptions(Configuration conf)
{
    String CL = ConfigHelper.getReadConsistencyLevel(conf);
    Optional<Integer> fetchSize = getInputPageRowSize(conf);
    QueryOptions queryOptions = new QueryOptions();
    if (CL != null && !CL.isEmpty())
        queryOptions.setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel.valueOf(CL));

    if (fetchSize.isPresent())
        queryOptions.setFetchSize(fetchSize.get());
    return queryOptions;
}
项目:GraphTrek    文件:CqlConfigHelper.java   
public static Cluster getInputCluster(String[] hosts, Configuration conf)
{
    int port = getInputNativePort(conf);
    Optional<AuthProvider> authProvider = getAuthProvider(conf);
    Optional<SSLOptions> sslOptions = getSSLOptions(conf);
    LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(conf, hosts);
    SocketOptions socketOptions = getReadSocketOptions(conf);
    QueryOptions queryOptions = getReadQueryOptions(conf);
    PoolingOptions poolingOptions = getReadPoolingOptions(conf);

    Cluster.Builder builder = Cluster.builder()
                                     .addContactPoints(hosts)
                                     .withPort(port)
                                     .withCompression(ProtocolOptions.Compression.NONE);

    if (authProvider.isPresent())
        builder.withAuthProvider(authProvider.get());
    if (sslOptions.isPresent())
        builder.withSSL(sslOptions.get());

    builder.withLoadBalancingPolicy(loadBalancingPolicy)
           .withSocketOptions(socketOptions)
           .withQueryOptions(queryOptions)
           .withPoolingOptions(poolingOptions);

    return builder.build();
}
项目:GraphTrek    文件:CqlConfigHelper.java   
private static QueryOptions getReadQueryOptions(Configuration conf)
{
    String CL = ConfigHelper.getReadConsistencyLevel(conf);
    Optional<Integer> fetchSize = getInputPageRowSize(conf);
    QueryOptions queryOptions = new QueryOptions();
    if (CL != null && !CL.isEmpty())
        queryOptions.setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel.valueOf(CL));

    if (fetchSize.isPresent())
        queryOptions.setFetchSize(fetchSize.get());
    return queryOptions;
}
项目:glowroot    文件:Clusters.java   
static Cluster newCluster() {
    return Cluster.builder().addContactPoint("127.0.0.1")
            // long read timeout is sometimes needed on slow travis ci machines
            .withSocketOptions(new SocketOptions().setReadTimeoutMillis(30000))
            // let driver know that only idempotent queries are used so it will retry on timeout
            .withQueryOptions(new QueryOptions().setDefaultIdempotence(true))
            .build();
}
项目:glowroot    文件:Sessions.java   
private static QueryOptions getQueryOptions() {
    QueryOptions queryOptions = new QueryOptions();
    Method setDefaultIdempotenceMethod;
    try {
        setDefaultIdempotenceMethod =
                QueryOptions.class.getMethod("setDefaultIdempotence", boolean.class);
        setDefaultIdempotenceMethod.invoke(queryOptions, true);
    } catch (Exception e) {
        // early version of driver
    }
    return queryOptions;
}
项目:stratio-cassandra    文件:CqlConfigHelper.java   
public static Cluster getInputCluster(String[] hosts, Configuration conf)
{
    int port = getInputNativePort(conf);
    Optional<AuthProvider> authProvider = getAuthProvider(conf);
    Optional<SSLOptions> sslOptions = getSSLOptions(conf);
    Optional<Integer> protocolVersion = getProtocolVersion(conf);
    LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(conf, hosts);
    SocketOptions socketOptions = getReadSocketOptions(conf);
    QueryOptions queryOptions = getReadQueryOptions(conf);
    PoolingOptions poolingOptions = getReadPoolingOptions(conf);

    Cluster.Builder builder = Cluster.builder()
                                     .addContactPoints(hosts)
                                     .withPort(port)
                                     .withCompression(ProtocolOptions.Compression.NONE);

    if (authProvider.isPresent())
        builder.withAuthProvider(authProvider.get());
    if (sslOptions.isPresent())
        builder.withSSL(sslOptions.get());

    if (protocolVersion.isPresent()) {
        builder.withProtocolVersion(protocolVersion.get());
    }
    builder.withLoadBalancingPolicy(loadBalancingPolicy)
           .withSocketOptions(socketOptions)
           .withQueryOptions(queryOptions)
           .withPoolingOptions(poolingOptions);

    return builder.build();
}
项目:stratio-cassandra    文件:CqlConfigHelper.java   
private static QueryOptions getReadQueryOptions(Configuration conf)
{
    String CL = ConfigHelper.getReadConsistencyLevel(conf);
    Optional<Integer> fetchSize = getInputPageRowSize(conf);
    QueryOptions queryOptions = new QueryOptions();
    if (CL != null && !CL.isEmpty())
        queryOptions.setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel.valueOf(CL));

    if (fetchSize.isPresent())
        queryOptions.setFetchSize(fetchSize.get());
    return queryOptions;
}
项目:ob1k    文件:CqlSession.java   
public CqlSession(final String nodes, final int port, final String keyspace, final SocketOptions socketOptions,
                  final RetryPolicy retryPolicy, final QueryOptions queryOptions,
                  final LoadBalancingPolicy loadBalancingPolicy, final int maxConnectionsPerHost,
                  final MetricFactory metricFactory) {

  // this is temp. to reuse current hosts properties:
  final Iterable<String> nodesIter = Splitter.on(",").split(nodes);
  final String[] nodesArr = Iterables.toArray(
    StreamSupport.stream(nodesIter.spliterator(), false).map(input -> {
    if (input == null) return null;

    final int idx = input.lastIndexOf(":");
    return input.substring(0, idx);
  }).collect(Collectors.toList()), String.class);


  /*PoolingOptions poolingOptions = new PoolingOptions();
  poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnectionsPerHost);
  poolingOptions.setMaxConnectionsPerHost(HostDistance.REMOTE, maxConnectionsPerHost);*/


  final Cluster cluster = Cluster.builder().
          withPort(port).
          withSocketOptions(socketOptions).
          withQueryOptions(queryOptions).
          withLoadBalancingPolicy(loadBalancingPolicy).
          //  withPoolingOptions(poolingOptions).
                  addContactPoints(nodesArr).build();
  //cluster.init();
  this.session = cluster.connect(keyspace);
  this.retryPolicy = Preconditions.checkNotNull(retryPolicy);
  this.metricFactory = Preconditions.checkNotNull(metricFactory);
}