Java Code Examples for com.datastax.driver.core.Cluster#init()

The following examples show how to use com.datastax.driver.core.Cluster#init() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NamespaceOverrideMapper.java    From hawkular-metrics with Apache License 2.0 6 votes vote down vote up
private Session createSession() {
    Cluster.Builder clusterBuilder = new Cluster.Builder();

    String nodes = System.getProperty("hawkular.metrics.cassandra.nodes", "hawkular-cassandra");
    Arrays.stream(nodes.split(",")).forEach(clusterBuilder::addContactPoint);

    if (System.getProperty("hawkular.metrics.cassandra.use-ssl") != null && !System.getProperty("hawkular.metrics.cassandra.use-ssl").equals("false")) {
        SSLOptions sslOptions = null;
        try {
            String[] defaultCipherSuites = {"TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_256_CBC_SHA"};
            sslOptions = JdkSSLOptions.builder().withSSLContext(SSLContext.getDefault())
                    .withCipherSuites(defaultCipherSuites).build();
            clusterBuilder.withSSL(sslOptions);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("SSL support is required but is not available in the JVM.", e);
        }
    }

    Cluster cluster = clusterBuilder.build();
    cluster.init();

    Session session = cluster.connect();

    return session;
}
 
Example 2
Source File: Installer.java    From hawkular-metrics with Apache License 2.0 5 votes vote down vote up
private Session createSession() {
    Cluster.Builder clusterBuilder = new Cluster.Builder();
    clusterBuilder.addContactPoints(cassandraNodes.toArray(new String[] {}));
    if (useSSL) {
        SSLOptions sslOptions = null;
        try {
            String[] defaultCipherSuites = {"TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_256_CBC_SHA"};
            sslOptions = JdkSSLOptions.builder().withSSLContext(SSLContext.getDefault())
                    .withCipherSuites(defaultCipherSuites).build();
            clusterBuilder.withSSL(sslOptions);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("SSL support is required but is not available in the JVM.", e);
        }
    }

    clusterBuilder.withoutJMXReporting();

    Cluster cluster = clusterBuilder.build();
    cluster.init();
    Session createdSession = null;
    try {
        createdSession = cluster.connect("system");
        return createdSession;
    } finally {
        if (createdSession == null) {
            cluster.close();
        }
    }
}