当前位置: 首页>>代码示例>>Java>>正文


Java ConsistencyLevel类代码示例

本文整理汇总了Java中com.datastax.driver.core.ConsistencyLevel的典型用法代码示例。如果您正苦于以下问题:Java ConsistencyLevel类的具体用法?Java ConsistencyLevel怎么用?Java ConsistencyLevel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConsistencyLevel类属于com.datastax.driver.core包,在下文中一共展示了ConsistencyLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCluster

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:apache,项目名称:beam,代码行数:28,代码来源:CassandraServiceImpl.java

示例2: testVerifyQueryLogInfo

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
@Test
public void testVerifyQueryLogInfo() throws Exception {
  long currentTimestamp = System.currentTimeMillis();
  String[] queries = new String[] {"select * from table1"};
  primeAndExecuteQueries(queries, queries);

  List<QueryLog> queryLogs = getAllQueryLogs(server.getLogs(server.getCluster()));
  assertThat(queryLogs.size()).isEqualTo(1);
  QueryLog log = queryLogs.get(0);
  assertThat(log.getConnection()).isNotNull();
  assertThat(log.getConsistency()).isEqualTo(adapt(ConsistencyLevel.LOCAL_ONE));
  assertThat(log.getReceivedTimestamp()).isNotZero();
  assertThat(log.getReceivedTimestamp()).isGreaterThan(currentTimestamp);
  assertThat(log.getClientTimestamp()).isEqualTo(100);
  assertThat(log.isPrimed()).isTrue();
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:17,代码来源:ActivityLogIntegrationTest.java

示例3: getClientSession

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
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;
    }
}
 
开发者ID:mcfongtw,项目名称:flink-cassandra-connector-examples,代码行数:22,代码来源:ClientSessionProvider.java

示例4: config

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
public static ConfigDef config() {
  return new ConfigDef()
      .define(CONTACT_POINTS_CONFIG, ConfigDef.Type.LIST, ImmutableList.of("localhost"), ConfigDef.Importance.MEDIUM, CONTACT_POINTS_DOC)
      .define(PORT_CONFIG, ConfigDef.Type.INT, 9042, ValidPort.of(), ConfigDef.Importance.MEDIUM, PORT_DOC)
      .define(CONSISTENCY_LEVEL_CONFIG, ConfigDef.Type.STRING, ConsistencyLevel.LOCAL_QUORUM.toString(), ValidEnum.of(ConsistencyLevel.class), ConfigDef.Importance.MEDIUM, CONSISTENCY_LEVEL_DOC)
      .define(USERNAME_CONFIG, ConfigDef.Type.STRING, "cassandra", ConfigDef.Importance.MEDIUM, USERNAME_DOC)
      .define(PASSWORD_CONFIG, ConfigDef.Type.PASSWORD, "cassandra", ConfigDef.Importance.MEDIUM, PASSWORD_DOC)
      .define(SECURITY_ENABLE_CONFIG, ConfigDef.Type.BOOLEAN, false, ConfigDef.Importance.MEDIUM, SECURITY_ENABLE_DOC)
      .define(COMPRESSION_CONFIG, ConfigDef.Type.STRING, "NONE", ConfigDef.ValidString.in(CLIENT_COMPRESSION.keySet().stream().toArray(String[]::new)), ConfigDef.Importance.MEDIUM, COMPRESSION_DOC)
      .define(SSL_ENABLED_CONFIG, ConfigDef.Type.BOOLEAN, false, ConfigDef.Importance.MEDIUM, SSL_ENABLED_DOC)
      .define(SSL_PROVIDER_CONFIG, ConfigDef.Type.STRING, SslProvider.JDK.toString(), ValidEnum.of(SslProvider.class), ConfigDef.Importance.MEDIUM, SSL_PROVIDER_DOC)
      .define(DELETES_ENABLE_CONFIG, ConfigDef.Type.BOOLEAN, true, ConfigDef.Importance.MEDIUM, DELETES_ENABLE_DOC)
      .define(KEYSPACE_CONFIG, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, KEYSPACE_DOC)
      .define(KEYSPACE_CREATE_ENABLED_CONFIG, ConfigDef.Type.BOOLEAN, true, ConfigDef.Importance.HIGH, KEYSPACE_CREATE_ENABLED_DOC)
      .define(TABLE_MANAGE_ENABLED_CONFIG, ConfigDef.Type.BOOLEAN, true, ConfigDef.Importance.MEDIUM, SCHEMA_MANAGE_CREATE_DOC)
      .define(TABLE_CREATE_COMPRESSION_ENABLED_CONFIG, ConfigDef.Type.BOOLEAN, true, ConfigDef.Importance.MEDIUM, TABLE_CREATE_COMPRESSION_ENABLED_DOC)
      .define(TABLE_CREATE_COMPRESSION_ALGORITHM_CONFIG, ConfigDef.Type.STRING, "NONE", ConfigDef.ValidString.in(TABLE_COMPRESSION.keySet().stream().toArray(String[]::new)), ConfigDef.Importance.MEDIUM, TABLE_CREATE_COMPRESSION_ALGORITHM_DOC)
      .define(TABLE_CREATE_CACHING_CONFIG, ConfigDef.Type.STRING, SchemaBuilder.Caching.NONE.toString(), ValidEnum.of(SchemaBuilder.Caching.class), ConfigDef.Importance.MEDIUM, TABLE_CREATE_CACHING_DOC);
}
 
开发者ID:jcustenborder,项目名称:kafka-connect-cassandra,代码行数:20,代码来源:CassandraSinkConnectorConfig.java

示例5: CassandraConfigDb

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
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();
}
 
开发者ID:att,项目名称:dmaap-framework,代码行数:27,代码来源:CassandraConfigDb.java

示例6: executePut

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
public void executePut(String query, String consistency){
	logger.debug("in data store handle, executing put:"+query);
	long start = System.currentTimeMillis();
	Statement statement = new SimpleStatement(query);
	if(consistency.equalsIgnoreCase("critical")){
		logger.info("Executing critical put query:"+query);
		statement.setConsistencyLevel(ConsistencyLevel.QUORUM);
	}
	else if (consistency.equalsIgnoreCase("eventual")){
		logger.info("Executing normal put query:"+query);
		statement.setConsistencyLevel(ConsistencyLevel.ONE);
	}
	session.execute(statement); 
	long end = System.currentTimeMillis();
	logger.debug("Time taken for actual put in cassandra:"+(end-start));
}
 
开发者ID:att,项目名称:music,代码行数:17,代码来源:MusicDataStore.java

示例7: PSInfo

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
/**
 * Create a PSInfo and create Prepared Statement
 * 
 * @param trans
 * @param theCQL
 * @param loader
 */
public PSInfo(TRANS trans, String theCQL, Loader<DATA> loader, ConsistencyLevel consistency) {
	this.loader = loader;
	this.consistency=consistency;
	psinfos.add(this);

	cql = theCQL.trim().toUpperCase();
	if(cql.startsWith("INSERT")) {
		crud = CRUD.create;
	} else if(cql.startsWith("UPDATE")) {
		crud = CRUD.update;
	} else if(cql.startsWith("DELETE")) {
		crud = CRUD.delete;
	} else {
		crud = CRUD.read;
	}
	
	int idx = 0, count=0;
	while((idx=cql.indexOf('?',idx))>=0) {
		++idx;
		++count;
	}
	size=count;
}
 
开发者ID:att,项目名称:AAF,代码行数:31,代码来源:AbsCassDAO.java

示例8: insertSubscription

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
@Timed(name = "bv.emodb.databus.CqlSubscriptionDAO.insertSubscription", absolute = true)
@Override
public void insertSubscription(String ownerId, String subscription, Condition tableFilter,
                               Duration subscriptionTtl, Duration eventTtl) {
    Map<String, Object> json = ImmutableMap.<String, Object>builder()
            .put("filter", tableFilter.toString())
            .put("expiresAt", _clock.millis() + subscriptionTtl.getMillis())
            .put("eventTtl", Ttls.toSeconds(eventTtl, 1, Integer.MAX_VALUE))
            .put("ownerId", ownerId)
            .build();

    _keyspace.getCqlSession().execute(
            insertInto(CF_NAME)
                    .value(rowkeyColumn(), ROW_KEY)
                    .value(subscriptionNameColumn(), subscription)
                    .value(subscriptionColumn(), JsonHelper.asJson(json))
                    .using(ttl(Ttls.toSeconds(subscriptionTtl, 1, Integer.MAX_VALUE)))
                    .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM));
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:20,代码来源:CqlSubscriptionDAO.java

示例9: getSubscription

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
@Timed(name = "bv.emodb.databus.CqlSubscriptionDAO.getSubscription", absolute = true)
@Override
public OwnedSubscription getSubscription(String subscription) {
    ResultSet resultSet = _keyspace.getCqlSession().execute(
            select(subscriptionNameColumn(), subscriptionColumn())
                    .from(CF_NAME)
                    .where(eq(rowkeyColumn(), ROW_KEY))
                    .and(eq(subscriptionNameColumn(), subscription))
                    .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM));

    Row row = resultSet.one();
    if (row == null) {
        return null;
    }
    return rowToOwnedSubscription(row);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:17,代码来源:CqlSubscriptionDAO.java

示例10: should_generate_simple_statement

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
@Test
public void should_generate_simple_statement() throws Exception {
    //Given
    String input = "SELECT * FROM users LIMIT 10;";
    CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM),
            Option.<ConsistencyLevel>empty(),
            Option.empty(),
            Option.<RetryPolicy>empty(),
            Option.empty());

    //When
    final SimpleStatement actual = helper.generateSimpleStatement(new SimpleStm(input), options, intrContext);

    //Then
    assertThat(actual).isNotNull();
    assertThat(actual.getQueryString()).isEqualTo("SELECT * FROM users LIMIT 10;");
    assertThat(actual.getConsistencyLevel()).isSameAs(QUORUM);
}
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:19,代码来源:InterpreterLogicTest.java

示例11: should_generate_batch_statement

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
@Test
public void should_generate_batch_statement() throws Exception {
    //Given
    Statement st1 = new SimpleStatement("SELECT * FROM users LIMIT 10;");
    Statement st2 = new SimpleStatement("INSERT INTO users(id) VALUES(10);");
    Statement st3 = new SimpleStatement("UPDATE users SET name = 'John DOE' WHERE id=10;");
    CassandraQueryOptions options = new CassandraQueryOptions(Option.apply(QUORUM),
            Option.<ConsistencyLevel>empty(),
            Option.empty(),
            Option.<RetryPolicy>empty(),
            Option.empty());

    //When
    BatchStatement actual = helper.generateBatchStatement(UNLOGGED, options, toScalaList(asList(st1, st2, st3)));

    //Then
    assertThat(actual).isNotNull();
    final List<Statement> statements = new ArrayList<>(actual.getStatements());
    assertThat(statements).hasSize(3);
    assertThat(statements.get(0)).isSameAs(st1);
    assertThat(statements.get(1)).isSameAs(st2);
    assertThat(statements.get(2)).isSameAs(st3);
    assertThat(actual.getConsistencyLevel()).isSameAs(QUORUM);
}
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:25,代码来源:InterpreterLogicTest.java

示例12: onReadTimeout

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
@Override
public RetryDecision onReadTimeout(
    Statement stmt,
    ConsistencyLevel cl,
    int required,
    int received,
    boolean retrieved,
    int retry) {

  if (retry > 1) {
    try {
      Thread.sleep(100);
    } catch (InterruptedException expected) { }
  }
  return null != stmt && stmt.isIdempotent()
      ? retry < 10 ? RetryDecision.retry(cl) : RetryDecision.rethrow()
      : DefaultRetryPolicy.INSTANCE.onReadTimeout(stmt, cl, required, received, retrieved, retry);
}
 
开发者ID:thelastpickle,项目名称:cassandra-reaper,代码行数:19,代码来源:CassandraStorage.java

示例13: testShouldAdaptConsistencyLevels

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
@Test
public void testShouldAdaptConsistencyLevels() {
  assertThat(adapt(ConsistencyLevel.ANY)).isEqualTo(ANY);
  assertThat(adapt(ConsistencyLevel.ONE)).isSameAs(ONE);
  assertThat(adapt(ConsistencyLevel.TWO)).isSameAs(TWO);
  assertThat(adapt(ConsistencyLevel.THREE)).isSameAs(THREE);
  assertThat(adapt(ConsistencyLevel.QUORUM)).isSameAs(QUORUM);
  assertThat(adapt(ConsistencyLevel.ALL)).isSameAs(ALL);
  assertThat(adapt(ConsistencyLevel.LOCAL_QUORUM)).isSameAs(LOCAL_QUORUM);
  assertThat(adapt(ConsistencyLevel.EACH_QUORUM)).isSameAs(EACH_QUORUM);
  assertThat(adapt(ConsistencyLevel.SERIAL)).isSameAs(SERIAL);
  assertThat(adapt(ConsistencyLevel.LOCAL_SERIAL)).isSameAs(LOCAL_SERIAL);
  assertThat(adapt(ConsistencyLevel.LOCAL_ONE)).isSameAs(LOCAL_ONE);
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:15,代码来源:DriverTypeAdaptersTest.java

示例14: testShouldExtractConsistencyLevels

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
@Test
public void testShouldExtractConsistencyLevels() {
  assertThat(extract(ANY)).isEqualTo(ConsistencyLevel.ANY);
  assertThat(extract(ONE)).isSameAs(ConsistencyLevel.ONE);
  assertThat(extract(TWO)).isSameAs(ConsistencyLevel.TWO);
  assertThat(extract(THREE)).isSameAs(ConsistencyLevel.THREE);
  assertThat(extract(QUORUM)).isSameAs(ConsistencyLevel.QUORUM);
  assertThat(extract(ALL)).isSameAs(ConsistencyLevel.ALL);
  assertThat(extract(LOCAL_QUORUM)).isSameAs(ConsistencyLevel.LOCAL_QUORUM);
  assertThat(extract(EACH_QUORUM)).isSameAs(ConsistencyLevel.EACH_QUORUM);
  assertThat(extract(SERIAL)).isSameAs(ConsistencyLevel.SERIAL);
  assertThat(extract(LOCAL_SERIAL)).isSameAs(ConsistencyLevel.LOCAL_SERIAL);
  assertThat(extract(LOCAL_ONE)).isSameAs(ConsistencyLevel.LOCAL_ONE);
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:15,代码来源:DriverTypeAdaptersTest.java

示例15: CassandraSinkConnectorConfig

import com.datastax.driver.core.ConsistencyLevel; //导入依赖的package包/类
public CassandraSinkConnectorConfig(Map<?, ?> originals) {
    super(config(), originals);
    this.port = getInt(PORT_CONFIG);
    final List<String> contactPoints = this.getList(CONTACT_POINTS_CONFIG);
    this.contactPoints = contactPoints.toArray(new String[contactPoints.size()]);
    this.consistencyLevel = ConfigUtils.getEnum(ConsistencyLevel.class, this, CONSISTENCY_LEVEL_CONFIG);
//    this.compression = ConfigUtils.getEnum(ProtocolOptions.Compression.class, this, COMPRESSION_CONFIG);
    this.username = getString(USERNAME_CONFIG);
    this.password = getPassword(PASSWORD_CONFIG).value();
    this.securityEnabled = getBoolean(SECURITY_ENABLE_CONFIG);
    this.sslEnabled = getBoolean(SSL_ENABLED_CONFIG);
    this.deletesEnabled = getBoolean(DELETES_ENABLE_CONFIG);

    final String keyspace = getString(KEYSPACE_CONFIG);

    if (Strings.isNullOrEmpty(keyspace)) {
      this.keyspace = null;
    } else {
      this.keyspace = keyspace;
    }

    final String compression = getString(COMPRESSION_CONFIG);
    this.compression = CLIENT_COMPRESSION.get(compression);
    this.sslProvider = ConfigUtils.getEnum(SslProvider.class, this, SSL_PROVIDER_CONFIG);
    this.keyspaceCreateEnabled = getBoolean(KEYSPACE_CREATE_ENABLED_CONFIG);
    this.tableManageEnabled = getBoolean(TABLE_MANAGE_ENABLED_CONFIG);
    this.tableCompressionEnabled = getBoolean(TABLE_CREATE_COMPRESSION_ENABLED_CONFIG);
    this.tableCompressionAlgorithm = ConfigUtils.getEnum(TableOptions.CompressionOptions.Algorithm.class, this, TABLE_CREATE_COMPRESSION_ALGORITHM_CONFIG);
    this.tableCaching = ConfigUtils.getEnum(SchemaBuilder.Caching.class, this, TABLE_CREATE_CACHING_CONFIG);
  }
 
开发者ID:jcustenborder,项目名称:kafka-connect-cassandra,代码行数:31,代码来源:CassandraSinkConnectorConfig.java


注:本文中的com.datastax.driver.core.ConsistencyLevel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。