congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Cluster$Builder.build
Code IndexAdd Tabnine to your IDE (free)

How to use
build
method
in
com.datastax.driver.core.Cluster$Builder

Best Java code snippets using com.datastax.driver.core.Cluster$Builder.build (Showing top 20 results out of 1,332)

Refine searchRefine arrow

  • Cluster.Builder.addContactPoints
  • Cluster.Builder.withPort
  • Cluster.builder
  • Cluster.connect
  • Test.<init>
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: 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: apache/ignite

/**
 * Returns Cassandra session and its generation number.
 *
 * @return Wrapper object providing Cassandra session and its generation number.
 */
private synchronized WrappedSession session() {
  if (wrapperSes != null)
    return wrapperSes;
  Session ses = SessionPool.get(this);
  if (ses != null) {
    this.wrapperSes = new WrappedSession(ses, generation);
    return this.wrapperSes;
  }
  synchronized (sesStatements) {
    sesStatements.clear();
  }
  try {
    ses = builder.build().connect();
    generation++;
    this.wrapperSes = new WrappedSession(ses, generation);
  }
  catch (Throwable e) {
    throw new IgniteException("Failed to establish session with Cassandra database", e);
  }
  return this.wrapperSes;
}
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: com.datastax.cassandra/cassandra-driver-core

/**
 * Tests the NoHostAvailableException. by attempting to build a cluster using the IP address
 * "255.255.255.255" and test all available exception methods.
 */
@Test(groups = "short")
public void noHostAvailableException() throws Exception {
 try {
  Cluster.builder().addContactPoints("255.255.255.255").build();
 } catch (NoHostAvailableException e) {
  assertEquals(e.getErrors().size(), 1);
  assertTrue(
    e.getErrors()
      .values()
      .iterator()
      .next()
      .toString()
      .contains("[/255.255.255.255] Cannot connect"));
  NoHostAvailableException copy = (NoHostAvailableException) e.copy();
  assertEquals(copy.getMessage(), e.getMessage());
  assertEquals(copy.getErrors(), e.getErrors());
 }
}
origin: com.datastax.cassandra/cassandra-driver-core

 @Test(groups = "short")
 public void should_countdown_inflight_requests_metrics() {
  sCluster
    .node(1)
    .primingClient()
    .prime(PrimingRequest.queryBuilder().withQuery("mock query").withThen(then()).build());

  Cluster cluster = null;
  try {
   cluster = builder().build();
   Session session = cluster.connect();

   assertThat(cluster.getMetrics().getInFlightRequests().getValue()).isEqualTo(0);
   session.executeAsync("mock query").getUninterruptibly();
   session.executeAsync("mock query").getUninterruptibly();
   assertThat(cluster.getMetrics().getInFlightRequests().getValue()).isEqualTo(0);

  } finally {
   if (cluster != null) {
    cluster.close();
   }
  }
 }
}
origin: apache/flink

  @Override
  protected Cluster buildCluster(Cluster.Builder builder) {
    return builder.addContactPoint(host).withPort(port).build();
  }
};
origin: kairosdb/kairosdb

      .withPort(hostPort.getValue());
  builder.withSSL();
m_cluster = builder.build();
origin: com.datastax.cassandra/cassandra-driver-core

protected void initTestCluster(Object testInstance) throws Exception {
 if (ccmTestConfig.createCcm() && ccmTestConfig.createCluster()) {
  Cluster.Builder builder = ccmTestConfig.clusterProvider(testInstance);
  // add contact points only if the provided builder didn't do so
  if (builder.getContactPoints().isEmpty()) builder.addContactPoints(getContactPoints());
  builder.withPort(ccm.getBinaryPort());
  cluster = register(builder.build());
  cluster.init();
 }
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_handle_tuples_with_custom_codecs() {
 CodecRegistry codecRegistry = new CodecRegistry();
 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: com.datastax.cassandra/cassandra-driver-core

/**
 * Validates that when a Cluster is initialized that {@link
 * SpeculativeExecutionPolicy#init(Cluster)} is called and that when a Cluster is closed {@link
 * SpeculativeExecutionPolicy#close()} is called.
 *
 * @test_category queries:speculative_execution
 * @expected_result init and close are called on cluster init and close.
 * @jira_ticket JAVA-796
 * @since 2.0.11, 2.1.7, 2.2.1
 */
@Test(groups = "short")
public void should_init_and_close_policy_on_cluster() {
 SpeculativeExecutionPolicy mockPolicy = mock(SpeculativeExecutionPolicy.class);
 Cluster cluster =
   Cluster.builder()
     .addContactPoints(scassandras.address(2).getAddress())
     .withPort(scassandras.getBinaryPort())
     .withSpeculativeExecutionPolicy(mockPolicy)
     .build();
 verify(mockPolicy, times(0)).init(cluster);
 verify(mockPolicy, times(0)).close();
 try {
  cluster.init();
  verify(mockPolicy, times(1)).init(cluster);
 } finally {
  cluster.close();
  verify(mockPolicy, times(1)).close();
 }
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_count_inflight_requests_metrics() {
 sCluster
   .node(1)
   .primingClient()
   .prime(
     PrimingRequest.queryBuilder()
       .withQuery("mock query")
       .withThen(then().withFixedDelay(100000L))
       .build());
 Cluster cluster = null;
 try {
  cluster = builder().build();
  Session session = cluster.connect();
  assertThat(cluster.getMetrics().getInFlightRequests().getValue()).isEqualTo(0);
  session.executeAsync("mock query");
  session.executeAsync("mock query");
  assertThat(cluster.getMetrics().getInFlightRequests().getValue()).isEqualTo(2);
 } finally {
  if (cluster != null) {
   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: 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: jooby-project/jooby

  .addContactPoints(cstr.contactPoints())
  .withPort(cstr.port());
Cluster cluster = builder.build();
Session session = cluster.connect(cstr.keyspace());
hierarchy(session.getClass(), type -> bind.apply(type, cstr.keyspace(), session));
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_handle_partial_tuples_with_custom_codecs() {
 CodecRegistry codecRegistry = new CodecRegistry();
 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: com.datastax.cassandra/cassandra-driver-core

/**
 * Verifies that the cluster builder fails when beta flag is set and user attempts to pass a
 * version explicitly.
 *
 * @jira_ticket JAVA-1248
 */
@Test(groups = "short")
public void should_not_initialize_when_beta_flag_is_set_and_version_explicitly_required()
  throws Exception {
 try {
  Cluster.builder()
    .addContactPoints(getContactPoints())
    .withPort(ccm().getBinaryPort())
    .allowBetaProtocolVersion()
    .withProtocolVersion(V4)
    .build();
  fail("Expected IllegalStateException");
 } catch (IllegalStateException e) {
  assertThat(e.getMessage())
    .isEqualTo("Can not set the version explicitly if `allowBetaProtocolVersion` was used.");
 }
}
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: 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: pulsarIO/realtime-analytics

private void startUp() {
  int port = 9042;
  String[] seeds;
  if (configuration.containsKey(CONTACT_POINTS)) {
    seeds = configuration.get(CONTACT_POINTS).split(",");
  } else {
    seeds = new String[] {LOCALHOST};
  }
  Cluster cluster = new Cluster.Builder()
    .addContactPoints(seeds)
    .withPort(port)
    .build();
  String keySpace = configuration.get(KEY_SPACE);
  if (keySpace == null || keySpace.isEmpty()) {
    keySpace=DEFAULT_KEYSPACE;
  }
  session = Optional.of(cluster.connect(keySpace));
  dataAccess = new DataAccess(session.get());
}
com.datastax.driver.coreCluster$Builderbuild

Javadoc

Builds the cluster with the configured set of initial contact points and policies.

This is a convenience method for Cluster.buildFrom(this).

Popular methods of Cluster$Builder

  • withPort
    The port to use to connect to the Cassandra host. If not set through this method, the default port (
  • addContactPoint
    Adds a contact point - or many if the given address resolves to multiple InetAddresss (A records). C
  • addContactPoints
    Adds contact points. See Builder#addContactPoint for more details on contact points. Note that all
  • withCredentials
    Uses the provided credentials when connecting to Cassandra hosts. This should be used if the Cassand
  • withLoadBalancingPolicy
    Configures the load balancing policy to use for the new cluster. If no load balancing policy is set
  • withSocketOptions
    Sets the SocketOptions to use for the newly created Cluster. If no socket options are set through th
  • withPoolingOptions
    Sets the PoolingOptions to use for the newly created Cluster. If no pooling options are set through
  • withQueryOptions
    Sets the QueryOptions to use for the newly created Cluster. If no query options are set through this
  • withReconnectionPolicy
    Configures the reconnection policy to use for the new cluster. If no reconnection policy is set thro
  • withSSL
    Enable the use of SSL for the created Cluster using the provided options.
  • withRetryPolicy
    Configures the retry policy to use for the new cluster. If no retry policy is set through this metho
  • withCompression
    Sets the compression to use for the transport.
  • withRetryPolicy,
  • withCompression,
  • withClusterName,
  • withoutJMXReporting,
  • withProtocolVersion,
  • addContactPointsWithPorts,
  • <init>,
  • withAuthProvider,
  • withoutMetrics

Popular in Java

  • Reactive rest calls using spring rest template
  • requestLocationUpdates (LocationManager)
  • addToBackStack (FragmentTransaction)
  • compareTo (BigDecimal)
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now