本文整理了Java中com.datastax.driver.core.Cluster.builder()
方法的一些代码示例,展示了Cluster.builder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cluster.builder()
方法的具体详情如下:
包路径:com.datastax.driver.core.Cluster
类名称:Cluster
方法名:builder
[英]Creates a new Cluster.Builder instance.
This is a convenience method for new Cluster.Builder().
[中]创建一个新集群。生成器实例。
这是一种方便的新集群方法。生成器()。
代码示例来源:origin: kaaproject/kaa
/**
* Creates new EndpointSpecificConfigurationMigration instance.
*/
public EndpointSpecificConfigurationMigration(String host, String db, String nosql) {
cluster = Cluster.builder()
.addContactPoint(host)
.build();
dbName = db;
this.nosql = nosql;
}
代码示例来源:origin: kaaproject/kaa
/**
* Add field use_raw_configuration_schema to endpointProfile that used to support devices using
* SDK version 0.9.0
*/
public void transform() {
//mongo
MongoClient client = new MongoClient(host);
MongoDatabase database = client.getDatabase(dbName);
MongoCollection<Document> endpointProfile = database.getCollection("endpoint_profile");
endpointProfile.updateMany(new Document(), eq("$set", eq("use_raw_schema", false)));
//cassandra
Cluster cluster = Cluster.builder().addContactPoint(host).build();
Session session = cluster.connect(dbName);
session.execute("ALTER TABLE ep_profile ADD use_raw_schema boolean");
session.close();
cluster.close();
}
}
代码示例来源:origin: brianfrankcooper/YCSB
cluster = Cluster.builder().withCredentials(username, password)
.withPort(Integer.valueOf(port)).addContactPoints(hosts).build();
} else {
cluster = Cluster.builder().withPort(Integer.valueOf(port))
.addContactPoints(hosts).build();
session = cluster.connect(keyspace);
代码示例来源:origin: testcontainers/testcontainers-java
public static Cluster getCluster(ContainerState containerState) {
return Cluster.builder()
.addContactPoint(containerState.getContainerIpAddress())
.withPort(containerState.getMappedPort(CQL_PORT))
.build();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void testMissingRpcAddressAtStartup() throws Exception {
deleteNode2RpcAddressFromNode1();
// Use only one contact point to make sure that the control connection is on node1
Cluster cluster =
register(
Cluster.builder()
.addContactPoints(getContactPoints().get(0))
.withPort(ccm().getBinaryPort())
.build());
cluster.connect();
// Since node2's RPC address is unknown on our control host, it should have been ignored
assertEquals(cluster.getMetrics().getConnectedToHosts().getValue().intValue(), 1);
assertNull(cluster.getMetadata().getHost(getContactPointsWithPorts().get(1)));
}
代码示例来源:origin: prestodb/presto
public TestHost(InetSocketAddress address)
{
super(address, new ConvictionPolicy.DefaultConvictionPolicy.Factory(), Cluster.builder().addContactPoints("localhost").build().manager);
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short", expectedExceptions = AuthenticationException.class)
public void should_fail_to_connect_without_credentials() {
Cluster cluster =
register(
Cluster.builder()
.addContactPoints(getContactPoints())
.withPort(ccm().getBinaryPort())
.build());
cluster.connect();
}
代码示例来源:origin: Netflix/conductor
@Override
public Cluster get() {
String host = configuration.getHostAddress();
int port = configuration.getPort();
LOGGER.info("Connecting to cassandra cluster with host:{}, port:{}", host, port);
Cluster cluster = Cluster.builder()
.addContactPoint(host)
.withPort(port)
.build();
Metadata metadata = cluster.getMetadata();
LOGGER.info("Connected to cluster: {}", metadata.getClusterName());
metadata.getAllHosts().forEach(h -> {
LOGGER.info("Datacenter:{}, host:{}, rack: {}", h.getDatacenter(), h.getAddress(), h.getRack());
});
return cluster;
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_connect_with_credentials() {
PlainTextAuthProvider authProvider = spy(new PlainTextAuthProvider("cassandra", "cassandra"));
Cluster cluster =
Cluster.builder()
.addContactPoints(getContactPoints())
.withPort(ccm().getBinaryPort())
.withAuthProvider(authProvider)
.build();
cluster.connect();
verify(authProvider, atLeastOnce())
.newAuthenticator(
findHost(cluster, 1).getSocketAddress(),
"org.apache.cassandra.auth.PasswordAuthenticator");
assertThat(cluster.getMetrics().getErrorMetrics().getAuthenticationErrors().getCount())
.isEqualTo(0);
}
代码示例来源:origin: kaaproject/kaa
/**
* Create a new instance of UpdateUuidsMigration.
*
* @param connection the connection to relational database
* @param options the options for configuring NoSQL databases
*/
public UpdateUuidsMigration(Connection connection, Options options) {
this.connection = connection;
client = new MongoClient(options.getHost());
cluster = Cluster.builder()
.addContactPoint(options.getHost())
.build();
dbName = options.getDbName();
this.nosql = options.getNoSql();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
Cluster cluster =
register(
Cluster.builder()
.addContactPoints(getContactPoints())
.withPort(ccm().getBinaryPort())
.withCodecRegistry(codecRegistry)
.build());
Session session = cluster.connect(keyspace);
setUpTupleTypes(cluster);
codecRegistry.register(new LocationCodec(TypeCodec.tuple(locationType)));
代码示例来源:origin: kaaproject/kaa
/**
* Create entity that responsible for data migration from old tables notification to
* new ctl based ones.
*
* @param connection the connection to relational database
* @param options the options for configuring NoSQL databases
*/
public CtlNotificationMigration(Connection connection, Options options) {
super(connection);
client = new MongoClient(options.getHost());
cluster = Cluster.builder()
.addContactPoint(options.getHost())
.build();
dbName = options.getDbName();
this.nosql = options.getDbName();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
Cluster cluster =
register(
Cluster.builder()
.addContactPoints(getContactPoints())
.withPort(ccm().getBinaryPort())
.withCodecRegistry(codecRegistry)
.build());
Session session = cluster.connect(keyspace);
setUpTupleTypes(cluster);
codecRegistry.register(new LocationCodec(TypeCodec.tuple(locationType)));
代码示例来源:origin: apache/nifi
private Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext,
String username, String password) {
Cluster.Builder builder = Cluster.builder().addContactPointsWithPorts(contactPoints);
if (sslContext != null) {
JdkSSLOptions sslOptions = JdkSSLOptions.builder()
.withSSLContext(sslContext)
.build();
builder = builder.withSSL(sslOptions);
}
if (username != null && password != null) {
builder = builder.withCredentials(username, password);
}
return builder.build();
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@BeforeMethod(groups = "short")
public void setUp() {
sCluster = ScassandraCluster.builder().withNodes(4).build();
sCluster.init();
cluster =
Cluster.builder()
.addContactPoints(sCluster.address(1).getAddress())
.withPort(sCluster.getBinaryPort())
.withLoadBalancingPolicy(lbSpy)
.withNettyOptions(nonQuietClusterCloseOptions)
.build();
session = cluster.connect();
// Reset invocations before entering test.
Mockito.reset(lbSpy);
}
代码示例来源:origin: spring-projects/spring-data-examples
@Override
protected void before() throws Throwable {
dependency.before();
Cluster cluster = Cluster.builder().addContactPoint(getHost()).withPort(getPort())
.withNettyOptions(new NettyOptions() {
@Override
public void onClusterClose(EventLoopGroup eventLoopGroup) {
eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS).syncUninterruptibly();
}
}).build();
Session session = cluster.newSession();
try {
if (requiredVersion != null) {
Version cassandraReleaseVersion = CassandraVersion.getReleaseVersion(session);
if (cassandraReleaseVersion.isLessThan(requiredVersion)) {
throw new AssumptionViolatedException(
String.format("Cassandra at %s:%s runs in Version %s but we require at least %s", getHost(), getPort(),
cassandraReleaseVersion, requiredVersion));
}
}
session.execute(String.format("CREATE KEYSPACE IF NOT EXISTS %s \n"
+ "WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", keyspaceName));
} finally {
session.close();
cluster.close();
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Verifies that the driver can connect to 3.10 with the following combination of options: Version
* UNSET Flag UNSET Expected version: V4
*
* @jira_ticket JAVA-1248
*/
@Test(groups = "short")
public void
should_connect_after_renegotiation_when_no_version_explicitly_required_and_flag_not_set()
throws Exception {
// Note: when the driver's ProtocolVersion.NEWEST_SUPPORTED will be incremented to V6 or higher
// the renegotiation will start downgrading the version from V6 to V4 instead of V5 to V4,
// but the test should remain valid since it's executed against 3.10 exclusively
Cluster cluster =
Cluster.builder()
.addContactPoints(getContactPoints())
.withPort(ccm().getBinaryPort())
.build();
cluster.connect();
assertThat(cluster.getConfiguration().getProtocolOptions().getProtocolVersion()).isEqualTo(V4);
}
}
代码示例来源:origin: apache/nifi
/**
* Uses a Cluster.Builder to create a Cassandra cluster reference using the given parameters
*
* @param contactPoints The contact points (hostname:port list of Cassandra nodes)
* @param sslContext The SSL context (used for secure connections)
* @param username The username for connection authentication
* @param password The password for connection authentication
* @return A reference to the Cluster object associated with the given Cassandra configuration
*/
protected Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext,
String username, String password) {
Cluster.Builder builder = Cluster.builder().addContactPointsWithPorts(contactPoints);
if (sslContext != null) {
JdkSSLOptions sslOptions = JdkSSLOptions.builder()
.withSSLContext(sslContext)
.build();
builder = builder.withSSL(sslOptions);
}
if (username != null && password != null) {
builder = builder.withCredentials(username, password);
}
return builder.build();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
Cluster cluster =
register(
Cluster.builder()
.addContactPoints(getContactPoints())
.withPort(ccm().getBinaryPort())
.withCredentials("bogus", "bogus")
.build());
cluster.connect();
fail("Should throw AuthenticationException when attempting to connect");
} catch (AuthenticationException e) {
try {
cluster.connect();
fail("Should throw IllegalStateException when attempting to connect again.");
} catch (IllegalStateException e1) {
代码示例来源:origin: prestodb/presto
requireNonNull(extraColumnMetadataCodec, "extraColumnMetadataCodec is null");
Cluster.Builder clusterBuilder = Cluster.builder()
.withProtocolVersion(config.getProtocolVersion());
clusterBuilder.withPort(config.getNativeProtocolPort());
clusterBuilder.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 10000));
clusterBuilder.withRetryPolicy(config.getRetryPolicy().getPolicy());
new ReopeningCluster(() -> {
contactPoints.forEach(clusterBuilder::addContactPoint);
return clusterBuilder.build();
}),
config.getNoHostAvailableRetryTimeout());
内容来源于网络,如有侵权,请联系作者删除!