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

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

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

Cluster.builder介绍

[英]Creates a new Cluster.Builder instance.

This is a convenience method for new Cluster.Builder().
[中]创建一个新集群。生成器实例。
这是一种方便的新集群方法。生成器()。

代码示例

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

  1. /**
  2. * Creates new EndpointSpecificConfigurationMigration instance.
  3. */
  4. public EndpointSpecificConfigurationMigration(String host, String db, String nosql) {
  5. cluster = Cluster.builder()
  6. .addContactPoint(host)
  7. .build();
  8. dbName = db;
  9. this.nosql = nosql;
  10. }

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

  1. /**
  2. * Add field use_raw_configuration_schema to endpointProfile that used to support devices using
  3. * SDK version 0.9.0
  4. */
  5. public void transform() {
  6. //mongo
  7. MongoClient client = new MongoClient(host);
  8. MongoDatabase database = client.getDatabase(dbName);
  9. MongoCollection<Document> endpointProfile = database.getCollection("endpoint_profile");
  10. endpointProfile.updateMany(new Document(), eq("$set", eq("use_raw_schema", false)));
  11. //cassandra
  12. Cluster cluster = Cluster.builder().addContactPoint(host).build();
  13. Session session = cluster.connect(dbName);
  14. session.execute("ALTER TABLE ep_profile ADD use_raw_schema boolean");
  15. session.close();
  16. cluster.close();
  17. }
  18. }

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

  1. cluster = Cluster.builder().withCredentials(username, password)
  2. .withPort(Integer.valueOf(port)).addContactPoints(hosts).build();
  3. } else {
  4. cluster = Cluster.builder().withPort(Integer.valueOf(port))
  5. .addContactPoints(hosts).build();
  6. session = cluster.connect(keyspace);

代码示例来源:origin: testcontainers/testcontainers-java

  1. public static Cluster getCluster(ContainerState containerState) {
  2. return Cluster.builder()
  3. .addContactPoint(containerState.getContainerIpAddress())
  4. .withPort(containerState.getMappedPort(CQL_PORT))
  5. .build();
  6. }

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

  1. @Test(groups = "short")
  2. public void testMissingRpcAddressAtStartup() throws Exception {
  3. deleteNode2RpcAddressFromNode1();
  4. // Use only one contact point to make sure that the control connection is on node1
  5. Cluster cluster =
  6. register(
  7. Cluster.builder()
  8. .addContactPoints(getContactPoints().get(0))
  9. .withPort(ccm().getBinaryPort())
  10. .build());
  11. cluster.connect();
  12. // Since node2's RPC address is unknown on our control host, it should have been ignored
  13. assertEquals(cluster.getMetrics().getConnectedToHosts().getValue().intValue(), 1);
  14. assertNull(cluster.getMetadata().getHost(getContactPointsWithPorts().get(1)));
  15. }

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

  1. public TestHost(InetSocketAddress address)
  2. {
  3. super(address, new ConvictionPolicy.DefaultConvictionPolicy.Factory(), Cluster.builder().addContactPoints("localhost").build().manager);
  4. }
  5. }

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

  1. @Test(groups = "short", expectedExceptions = AuthenticationException.class)
  2. public void should_fail_to_connect_without_credentials() {
  3. Cluster cluster =
  4. register(
  5. Cluster.builder()
  6. .addContactPoints(getContactPoints())
  7. .withPort(ccm().getBinaryPort())
  8. .build());
  9. cluster.connect();
  10. }

代码示例来源:origin: Netflix/conductor

  1. @Override
  2. public Cluster get() {
  3. String host = configuration.getHostAddress();
  4. int port = configuration.getPort();
  5. LOGGER.info("Connecting to cassandra cluster with host:{}, port:{}", host, port);
  6. Cluster cluster = Cluster.builder()
  7. .addContactPoint(host)
  8. .withPort(port)
  9. .build();
  10. Metadata metadata = cluster.getMetadata();
  11. LOGGER.info("Connected to cluster: {}", metadata.getClusterName());
  12. metadata.getAllHosts().forEach(h -> {
  13. LOGGER.info("Datacenter:{}, host:{}, rack: {}", h.getDatacenter(), h.getAddress(), h.getRack());
  14. });
  15. return cluster;
  16. }
  17. }

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

  1. @Test(groups = "short")
  2. public void should_connect_with_credentials() {
  3. PlainTextAuthProvider authProvider = spy(new PlainTextAuthProvider("cassandra", "cassandra"));
  4. Cluster cluster =
  5. Cluster.builder()
  6. .addContactPoints(getContactPoints())
  7. .withPort(ccm().getBinaryPort())
  8. .withAuthProvider(authProvider)
  9. .build();
  10. cluster.connect();
  11. verify(authProvider, atLeastOnce())
  12. .newAuthenticator(
  13. findHost(cluster, 1).getSocketAddress(),
  14. "org.apache.cassandra.auth.PasswordAuthenticator");
  15. assertThat(cluster.getMetrics().getErrorMetrics().getAuthenticationErrors().getCount())
  16. .isEqualTo(0);
  17. }

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

  1. /**
  2. * Create a new instance of UpdateUuidsMigration.
  3. *
  4. * @param connection the connection to relational database
  5. * @param options the options for configuring NoSQL databases
  6. */
  7. public UpdateUuidsMigration(Connection connection, Options options) {
  8. this.connection = connection;
  9. client = new MongoClient(options.getHost());
  10. cluster = Cluster.builder()
  11. .addContactPoint(options.getHost())
  12. .build();
  13. dbName = options.getDbName();
  14. this.nosql = options.getNoSql();
  15. }

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

  1. Cluster cluster =
  2. register(
  3. Cluster.builder()
  4. .addContactPoints(getContactPoints())
  5. .withPort(ccm().getBinaryPort())
  6. .withCodecRegistry(codecRegistry)
  7. .build());
  8. Session session = cluster.connect(keyspace);
  9. setUpTupleTypes(cluster);
  10. codecRegistry.register(new LocationCodec(TypeCodec.tuple(locationType)));

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

  1. /**
  2. * Create entity that responsible for data migration from old tables notification to
  3. * new ctl based ones.
  4. *
  5. * @param connection the connection to relational database
  6. * @param options the options for configuring NoSQL databases
  7. */
  8. public CtlNotificationMigration(Connection connection, Options options) {
  9. super(connection);
  10. client = new MongoClient(options.getHost());
  11. cluster = Cluster.builder()
  12. .addContactPoint(options.getHost())
  13. .build();
  14. dbName = options.getDbName();
  15. this.nosql = options.getDbName();
  16. }

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

  1. Cluster cluster =
  2. register(
  3. Cluster.builder()
  4. .addContactPoints(getContactPoints())
  5. .withPort(ccm().getBinaryPort())
  6. .withCodecRegistry(codecRegistry)
  7. .build());
  8. Session session = cluster.connect(keyspace);
  9. setUpTupleTypes(cluster);
  10. codecRegistry.register(new LocationCodec(TypeCodec.tuple(locationType)));

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

  1. private Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext,
  2. String username, String password) {
  3. Cluster.Builder builder = Cluster.builder().addContactPointsWithPorts(contactPoints);
  4. if (sslContext != null) {
  5. JdkSSLOptions sslOptions = JdkSSLOptions.builder()
  6. .withSSLContext(sslContext)
  7. .build();
  8. builder = builder.withSSL(sslOptions);
  9. }
  10. if (username != null && password != null) {
  11. builder = builder.withCredentials(username, password);
  12. }
  13. return builder.build();
  14. }
  15. }

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

  1. @BeforeMethod(groups = "short")
  2. public void setUp() {
  3. sCluster = ScassandraCluster.builder().withNodes(4).build();
  4. sCluster.init();
  5. cluster =
  6. Cluster.builder()
  7. .addContactPoints(sCluster.address(1).getAddress())
  8. .withPort(sCluster.getBinaryPort())
  9. .withLoadBalancingPolicy(lbSpy)
  10. .withNettyOptions(nonQuietClusterCloseOptions)
  11. .build();
  12. session = cluster.connect();
  13. // Reset invocations before entering test.
  14. Mockito.reset(lbSpy);
  15. }

代码示例来源:origin: spring-projects/spring-data-examples

  1. @Override
  2. protected void before() throws Throwable {
  3. dependency.before();
  4. Cluster cluster = Cluster.builder().addContactPoint(getHost()).withPort(getPort())
  5. .withNettyOptions(new NettyOptions() {
  6. @Override
  7. public void onClusterClose(EventLoopGroup eventLoopGroup) {
  8. eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS).syncUninterruptibly();
  9. }
  10. }).build();
  11. Session session = cluster.newSession();
  12. try {
  13. if (requiredVersion != null) {
  14. Version cassandraReleaseVersion = CassandraVersion.getReleaseVersion(session);
  15. if (cassandraReleaseVersion.isLessThan(requiredVersion)) {
  16. throw new AssumptionViolatedException(
  17. String.format("Cassandra at %s:%s runs in Version %s but we require at least %s", getHost(), getPort(),
  18. cassandraReleaseVersion, requiredVersion));
  19. }
  20. }
  21. session.execute(String.format("CREATE KEYSPACE IF NOT EXISTS %s \n"
  22. + "WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", keyspaceName));
  23. } finally {
  24. session.close();
  25. cluster.close();
  26. }
  27. }

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

  1. /**
  2. * Verifies that the driver can connect to 3.10 with the following combination of options: Version
  3. * UNSET Flag UNSET Expected version: V4
  4. *
  5. * @jira_ticket JAVA-1248
  6. */
  7. @Test(groups = "short")
  8. public void
  9. should_connect_after_renegotiation_when_no_version_explicitly_required_and_flag_not_set()
  10. throws Exception {
  11. // Note: when the driver's ProtocolVersion.NEWEST_SUPPORTED will be incremented to V6 or higher
  12. // the renegotiation will start downgrading the version from V6 to V4 instead of V5 to V4,
  13. // but the test should remain valid since it's executed against 3.10 exclusively
  14. Cluster cluster =
  15. Cluster.builder()
  16. .addContactPoints(getContactPoints())
  17. .withPort(ccm().getBinaryPort())
  18. .build();
  19. cluster.connect();
  20. assertThat(cluster.getConfiguration().getProtocolOptions().getProtocolVersion()).isEqualTo(V4);
  21. }
  22. }

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

  1. /**
  2. * Uses a Cluster.Builder to create a Cassandra cluster reference using the given parameters
  3. *
  4. * @param contactPoints The contact points (hostname:port list of Cassandra nodes)
  5. * @param sslContext The SSL context (used for secure connections)
  6. * @param username The username for connection authentication
  7. * @param password The password for connection authentication
  8. * @return A reference to the Cluster object associated with the given Cassandra configuration
  9. */
  10. protected Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext,
  11. String username, String password) {
  12. Cluster.Builder builder = Cluster.builder().addContactPointsWithPorts(contactPoints);
  13. if (sslContext != null) {
  14. JdkSSLOptions sslOptions = JdkSSLOptions.builder()
  15. .withSSLContext(sslContext)
  16. .build();
  17. builder = builder.withSSL(sslOptions);
  18. }
  19. if (username != null && password != null) {
  20. builder = builder.withCredentials(username, password);
  21. }
  22. return builder.build();
  23. }

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

  1. Cluster cluster =
  2. register(
  3. Cluster.builder()
  4. .addContactPoints(getContactPoints())
  5. .withPort(ccm().getBinaryPort())
  6. .withCredentials("bogus", "bogus")
  7. .build());
  8. cluster.connect();
  9. fail("Should throw AuthenticationException when attempting to connect");
  10. } catch (AuthenticationException e) {
  11. try {
  12. cluster.connect();
  13. fail("Should throw IllegalStateException when attempting to connect again.");
  14. } catch (IllegalStateException e1) {

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

  1. requireNonNull(extraColumnMetadataCodec, "extraColumnMetadataCodec is null");
  2. Cluster.Builder clusterBuilder = Cluster.builder()
  3. .withProtocolVersion(config.getProtocolVersion());
  4. clusterBuilder.withPort(config.getNativeProtocolPort());
  5. clusterBuilder.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 10000));
  6. clusterBuilder.withRetryPolicy(config.getRetryPolicy().getPolicy());
  7. new ReopeningCluster(() -> {
  8. contactPoints.forEach(clusterBuilder::addContactPoint);
  9. return clusterBuilder.build();
  10. }),
  11. config.getNoHostAvailableRetryTimeout());

相关文章