com.datastax.driver.core.Cluster.getConfiguration()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(165)

本文整理了Java中com.datastax.driver.core.Cluster.getConfiguration()方法的一些代码示例,展示了Cluster.getConfiguration()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cluster.getConfiguration()方法的具体详情如下:
包路径:com.datastax.driver.core.Cluster
类名称:Cluster
方法名:getConfiguration

Cluster.getConfiguration介绍

[英]The cluster configuration.
[中]群集配置。

代码示例

代码示例来源:origin: apache/storm

  1. private MappingManager getMappingManager(Session session) {
  2. synchronized (mappingManagers) {
  3. MappingManager mappingManager = mappingManagers.get(session);
  4. if (mappingManager == null) {
  5. mappingManager = new MappingManager(session);
  6. mappingManagers.put(session, mappingManager);
  7. CodecRegistry codecRegistry = session.getCluster().getConfiguration().getCodecRegistry();
  8. for (TypeCodec<?> codec : codecs) {
  9. codecRegistry.register(codec);
  10. }
  11. for (Class<?> udtClass : udtClasses) {
  12. mappingManager.udtCodec(udtClass);
  13. }
  14. }
  15. return mappingManager;
  16. }
  17. }
  18. }

代码示例来源:origin: prestodb/presto

  1. private <T> T executeWithSession(SessionCallable<T> sessionCallable)
  2. {
  3. ReconnectionPolicy reconnectionPolicy = cluster.getConfiguration().getPolicies().getReconnectionPolicy();
  4. ReconnectionSchedule schedule = reconnectionPolicy.newSchedule();
  5. long deadline = System.currentTimeMillis() + noHostAvailableRetryTimeout.toMillis();
  6. while (true) {
  7. try {
  8. return sessionCallable.executeWithSession(session.get());
  9. }
  10. catch (NoHostAvailableException e) {
  11. long timeLeft = deadline - System.currentTimeMillis();
  12. if (timeLeft <= 0) {
  13. throw e;
  14. }
  15. else {
  16. long delay = Math.min(schedule.nextDelayMs(), timeLeft);
  17. log.warn(e.getCustomMessage(10, true, true));
  18. log.warn("Reconnecting in %dms", delay);
  19. try {
  20. Thread.sleep(delay);
  21. }
  22. catch (InterruptedException interrupted) {
  23. Thread.currentThread().interrupt();
  24. throw new RuntimeException("interrupted", interrupted);
  25. }
  26. }
  27. }
  28. }
  29. }

代码示例来源:origin: apache/storm

  1. public void prepare() {
  2. LOG.info("Preparing state for {}", options.toString());
  3. Preconditions.checkNotNull(options.getMapper, "CassandraBackingMap.Options should have getMapper");
  4. Preconditions.checkNotNull(options.putMapper, "CassandraBackingMap.Options should have putMapper");
  5. client = options.clientProvider.getClient(conf);
  6. session = client.connect();
  7. if (options.maxParallelism == null || options.maxParallelism <= 0) {
  8. PoolingOptions po = session.getCluster().getConfiguration().getPoolingOptions();
  9. Integer maxRequestsPerHost = Math.min(
  10. po.getMaxConnectionsPerHost(HostDistance.LOCAL) * po.getMaxRequestsPerConnection(HostDistance.LOCAL),
  11. po.getMaxConnectionsPerHost(HostDistance.REMOTE) * po.getMaxRequestsPerConnection(HostDistance.REMOTE)
  12. );
  13. options.maxParallelism = maxRequestsPerHost / 2;
  14. LOG.info("Parallelism default set to {}", options.maxParallelism);
  15. }
  16. throttle = new Semaphore(options.maxParallelism, false);
  17. this.getResultMapper = new TridentAyncCQLResultSetValuesMapper(options.stateMapper.getStateFields(), throttle);
  18. this.putResultMapper = new TridentAyncCQLResultSetValuesMapper(null, throttle);
  19. }

代码示例来源:origin: apache/nifi

  1. @OnScheduled
  2. public void onScheduled(final ProcessContext context) {
  3. super.onScheduled(context);
  4. final int fetchSize = context.getProperty(FETCH_SIZE).evaluateAttributeExpressions().asInteger();
  5. if (fetchSize > 0) {
  6. synchronized (cluster.get()) {
  7. cluster.get().getConfiguration().getQueryOptions().setFetchSize(fetchSize);
  8. }
  9. }
  10. }

代码示例来源:origin: apache/usergrid

  1. @Inject
  2. public DataStaxClusterImpl(final CassandraConfig cassandraFig ) throws Exception {
  3. this.cassandraConfig = cassandraFig;
  4. this.cluster = getCluster();
  5. logger.info("Initialized datastax cluster client. Hosts={}, Idle Timeout={}s, Pool Timeout={}s",
  6. getCluster().getMetadata().getAllHosts().toString(),
  7. getCluster().getConfiguration().getPoolingOptions().getIdleTimeoutSeconds(),
  8. getCluster().getConfiguration().getPoolingOptions().getPoolTimeoutMillis() / 1000);
  9. // always initialize the keyspaces
  10. this.createApplicationKeyspace(false);
  11. this.createApplicationLocalKeyspace(false);
  12. }

代码示例来源:origin: kaaproject/kaa

  1. .getConfiguration()
  2. .getCodecRegistry()
  3. .register(instance);

代码示例来源:origin: brianfrankcooper/YCSB

  1. MAX_CONNECTIONS_PROPERTY);
  2. if (maxConnections != null) {
  3. cluster.getConfiguration().getPoolingOptions()
  4. .setMaxConnectionsPerHost(HostDistance.LOCAL,
  5. Integer.valueOf(maxConnections));
  6. CORE_CONNECTIONS_PROPERTY);
  7. if (coreConnections != null) {
  8. cluster.getConfiguration().getPoolingOptions()
  9. .setCoreConnectionsPerHost(HostDistance.LOCAL,
  10. Integer.valueOf(coreConnections));
  11. CONNECT_TIMEOUT_MILLIS_PROPERTY);
  12. if (connectTimoutMillis != null) {
  13. cluster.getConfiguration().getSocketOptions()
  14. .setConnectTimeoutMillis(Integer.valueOf(connectTimoutMillis));
  15. READ_TIMEOUT_MILLIS_PROPERTY);
  16. if (readTimoutMillis != null) {
  17. cluster.getConfiguration().getSocketOptions()
  18. .setReadTimeoutMillis(Integer.valueOf(readTimoutMillis));

代码示例来源:origin: jooby-project/jooby

  1. Configuration configuration = cluster.getConfiguration();
  2. CodecRegistry codecRegistry = configuration.getCodecRegistry();

代码示例来源:origin: apache/nifi

  1. newCluster.getConfiguration().getQueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevel));
  2. Metadata metadata = newCluster.getMetadata();

代码示例来源:origin: apache/nifi

  1. newSession = newCluster.connect();
  2. newCluster.getConfiguration().getQueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevel));
  3. Metadata metadata = newCluster.getMetadata();
  4. log.info("Connected to Cassandra cluster: {}", new Object[]{metadata.getClusterName()});

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. private ProtocolVersion protocolVersion() {
  2. // Since the QueryLogger can be registered before the Cluster was initialized, we can't retrieve
  3. // it at construction time. Cache it field at first use (a volatile field is good enough since
  4. // we
  5. // don't need mutual exclusion).
  6. if (protocolVersion == null) {
  7. protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion();
  8. // At least one connection was established when QueryLogger is invoked
  9. assert protocolVersion != null : "protocol version should be defined";
  10. }
  11. return protocolVersion;
  12. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @Override
  2. public void init(Cluster cluster) {
  3. childPolicy.init(cluster);
  4. queryOptions = cluster.getConfiguration().getQueryOptions();
  5. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @BeforeMethod(groups = "unit")
  2. public void setUpQueryBuilder() throws Exception {
  3. CodecRegistry codecRegistry = new CodecRegistry();
  4. cluster = mock(Cluster.class);
  5. Configuration configuration = mock(Configuration.class);
  6. ProtocolOptions protocolOptions = mock(ProtocolOptions.class);
  7. when(cluster.getConfiguration()).thenReturn(configuration);
  8. when(configuration.getCodecRegistry()).thenReturn(codecRegistry);
  9. when(configuration.getProtocolOptions()).thenReturn(protocolOptions);
  10. when(protocolOptions.getProtocolVersion()).thenReturn(ProtocolVersion.NEWEST_SUPPORTED);
  11. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @Test(groups = "short")
  2. public void should_set_flag_on_successful_agreement() {
  3. ProtocolOptions protocolOptions = cluster().getConfiguration().getProtocolOptions();
  4. protocolOptions.maxSchemaAgreementWaitSeconds = 10;
  5. ResultSet rs = session().execute(String.format(CREATE_TABLE, COUNTER.getAndIncrement()));
  6. assertThat(rs.getExecutionInfo().isSchemaInAgreement()).isTrue();
  7. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @Test(groups = "short", priority = 1)
  2. public void should_unset_flag_on_failed_agreement() {
  3. // Setting to 0 results in no query being set, so agreement fails
  4. ProtocolOptions protocolOptions = cluster().getConfiguration().getProtocolOptions();
  5. protocolOptions.maxSchemaAgreementWaitSeconds = 0;
  6. ResultSet rs = session().execute(String.format(CREATE_TABLE, COUNTER.getAndIncrement()));
  7. assertThat(rs.getExecutionInfo().isSchemaInAgreement()).isFalse();
  8. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @Test(groups = "short")
  2. public void should_set_flag_on_non_schema_altering_statement() {
  3. ProtocolOptions protocolOptions = cluster().getConfiguration().getProtocolOptions();
  4. protocolOptions.maxSchemaAgreementWaitSeconds = 10;
  5. ResultSet rs = session().execute("select release_version from system.local");
  6. assertThat(rs.getExecutionInfo().isSchemaInAgreement()).isTrue();
  7. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. public void checkGetValuesReturnsSerializedValue(
  2. ProtocolVersion protocolVersion, SimpleStatement statement, TestTable table) {
  3. CodecRegistry codecRegistry = cluster().getConfiguration().getCodecRegistry();
  4. ByteBuffer[] values = statement.getValues(protocolVersion, codecRegistry);
  5. assertThat(values.length).isEqualTo(1);
  6. assertThat(values[0])
  7. .as("Value not serialized as expected for " + table.sampleValue)
  8. .isEqualTo(
  9. codecRegistry
  10. .codecFor(table.testColumnType)
  11. .serialize(table.sampleValue, protocolVersion));
  12. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. /** @jira_ticket JAVA-1209 */
  2. @Test(groups = "short")
  3. public void getProtocolVersion_should_return_version() throws InterruptedException {
  4. ProtocolVersion version =
  5. cluster().getConfiguration().getProtocolOptions().getProtocolVersion();
  6. assertThat(version).isNotNull();
  7. }
  8. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. /** @jira_ticket JAVA-1209 */
  2. @Test(groups = "unit")
  3. public void getProtocolVersion_should_return_null_if_not_connected() {
  4. Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
  5. assertThat(cluster.getConfiguration().getProtocolOptions().getProtocolVersion()).isNull();
  6. }

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

  1. @BeforeMethod(groups = "short")
  2. public void setup() {
  3. primingClient.prime(
  4. queryBuilder().withQuery(query).withThen(then().withFixedDelay(100L)).build());
  5. // Set default timeout too low
  6. cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(10);
  7. }

相关文章