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

How to use
connect
method
in
com.datastax.driver.core.Cluster

Best Java code snippets using com.datastax.driver.core.Cluster.connect (Showing top 20 results out of 1,305)

Refine searchRefine arrow

  • Cluster.builder
  • Cluster.Builder.build
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: 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: 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: jooby-project/jooby

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 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: kaaproject/kaa

@Override
protected void load() {
 String hostIp = EmbeddedCassandraServerHelper.getHost();
 int port = EmbeddedCassandraServerHelper.getNativeTransportPort();
 cluster = new Cluster.Builder().addContactPoints(hostIp).withPort(port).withSocketOptions(getSocketOptions())
   .build();
 session = cluster.connect();
 CQLDataLoader dataLoader = new CQLDataLoader(session);
 dataLoader.load(dataSet);
 session = dataLoader.getSession();
}
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: 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());
}
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: pulsarIO/realtime-analytics

private void connectInternal() {
  try {
    Cluster cluster = config.createBuilder().build();
    cassandraSession = cluster.connect(keySpace);
    cassandraMetrics = cluster.getMetrics();
    connected.set(true);
  } catch (Exception e) {
    LOGGER.error("Error connection to Cassandra" + e.getMessage());
    if (pool != null) {
      pool.shutdownNow();
      pool = null;
    }
    if (cassandraSession != null) {
      cassandraSession.close();
      if (cassandraSession.getCluster() != null)
        cassandraSession.getCluster().close();
    }
    connected.set(false);
  }
}
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: com.datastax.cassandra/cassandra-driver-core

@BeforeMethod(groups = {"short", "unit"})
public void setUp() {
 originalSlow = slow.getLevel();
 originalError = error.getLevel();
 slow.setLevel(INFO);
 error.setLevel(INFO);
 slow.addAppender(slowAppender = new MemoryAppender());
 error.addAppender(errorAppender = new MemoryAppender());
 queryLogger = null;
 cluster = createClusterBuilder().withRetryPolicy(FallthroughRetryPolicy.INSTANCE).build();
 session = cluster.connect();
}
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: com.datastax.cassandra/cassandra-driver-core

@BeforeClass(groups = {"short", "long"})
public void beforeTestClass() {
 super.beforeTestClass();
 Cluster.Builder builder = createClusterBuilder();
 cluster = builder.build();
 host = retrieveSingleHost(cluster);
 session = cluster.connect();
}
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: com.datastax.cassandra/cassandra-driver-core

/**
 * When no consistency level is defined the default of LOCAL_ONE should be used.
 *
 * @test_category consistency
 */
@Test(groups = "short")
public void should_use_global_default_cl_when_none_specified() throws Throwable {
 // Build a cluster with no CL level set in the query options.
 Cluster cluster = builder().build();
 try {
  Session session = cluster.connect();
  // Construct unique simple statement query, with no CL defined.
  // Check to ensure
  String queryString = "default_cl";
  Query clQuery = executeSimple(session, queryString, null, null);
  assertTrue(clQuery.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString()));
  // Check prepared statement default CL
  String prepareString = "prepared_default_cl";
  PreparedStatementExecution pse = executePrepared(session, prepareString, null, null);
  assertTrue(pse.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString()));
  // Check batch statement default CL
  String batchStateString = "batch_default_cl";
  BatchExecution batch = executeBatch(session, batchStateString, null, null);
  assertTrue(batch.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString()));
 } finally {
  cluster.close();
 }
}
origin: com.datastax.cassandra/cassandra-driver-core

public void should_detect_cluster_init_failure_and_close_cluster() {
 Cluster cluster =
   Cluster.builder()
     .addContactPointsWithPorts(new InetSocketAddress("127.0.0.1", 65534))
     .withNettyOptions(nonQuietClusterCloseOptions)
     .build();
 try {
  cluster.connect();
  fail("Should not have been able to connect.");
 } catch (NoHostAvailableException e) {
  try {
   cluster.connect();
   fail("Should error when connect is called.");
  } catch (IllegalStateException e1) {
origin: com.datastax.cassandra/cassandra-driver-core

Cluster cluster = builder().build();
try {
 Session session = cluster.connect();
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: com.datastax.cassandra/cassandra-driver-core

  builder().withQueryOptions(new QueryOptions().setConsistencyLevel(cl)).build();
try {
 Session session = cluster.connect();
com.datastax.driver.coreClusterconnect

Javadoc

Creates a new session on this cluster and initialize it.

Note that this method will initialize the newly created session, trying to connect to the Cassandra nodes before returning. If you only want to create a Session object without initializing it right away, see #newSession.

Popular methods of Cluster

  • builder
    Creates a new Cluster.Builder instance. This is a convenience method for new Cluster.Builder().
  • getMetadata
    Returns read-only metadata on the connected cluster. This includes the known nodes with their status
  • close
    Initiates a shutdown of this cluster instance and blocks until that shutdown completes. This method
  • getConfiguration
    The cluster configuration.
  • isClosed
    Whether this Cluster instance has been closed. Note that this method returns true as soon as one of
  • getClusterName
    The name of this cluster object. Note that this is not the Cassandra cluster name, but rather a name
  • closeAsync
    Initiates a shutdown of this cluster instance. This method is asynchronous and return a future on th
  • register
    Registers the provided listener to be updated with schema change events. Registering the same liste
  • newSession
    Creates a new session on this cluster but does not initialize it. Because this method does not perfo
  • getMetrics
    The cluster metrics.
  • init
    Initialize this Cluster instance. This method creates an initial connection to one of the contact po
  • connectAsync
    Creates a new session on this cluster, and initializes it to the given keyspace asynchronously. This
  • init,
  • connectAsync,
  • unregister,
  • <init>,
  • buildFrom,
  • checkNotEmpty,
  • timeSince,
  • checkNotClosed,
  • getDriverVersion

Popular in Java

  • Finding current android device location
  • onRequestPermissionsResult (Fragment)
  • getContentResolver (Context)
  • getSharedPreferences (Context)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • Collectors (java.util.stream)
  • JComboBox (javax.swing)
  • JTable (javax.swing)
  • Top Vim plugins
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