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

The following examples show how to use com.datastax.driver.core.Cluster.Builder#withPort() . 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: CassandraConnector.java    From tutorials with MIT License 6 votes vote down vote up
public void connect(final String node, final Integer port) {

        Builder b = Cluster.builder().addContactPoint(node);

        if (port != null) {
            b.withPort(port);
        }
        cluster = b.build();

        Metadata metadata = cluster.getMetadata();
        LOG.info("Cluster name: " + metadata.getClusterName());

        for (Host host : metadata.getAllHosts()) {
            LOG.info("Datacenter: " + host.getDatacenter() + " Host: " + host.getAddress() + " Rack: " + host.getRack());
        }

        session = cluster.connect();
    }
 
Example 2
Source File: CassandraHelper.java    From cassandana with Apache License 2.0 5 votes vote down vote up
public void tryConnecting() {
	Builder b = Cluster.builder().addContactPoint(host);
	b.withPort(port);
       cluster = b.build();
       session = cluster.connect(dbName);//keyspace
       onConnected();
}
 
Example 3
Source File: CassandraConnector.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
public void connect(String node, Integer port, String keyspace) {
    Builder b = Cluster.builder().addContactPoint(node);
    if (port != null) {
        b.withPort(port);
    }
    cluster = b.build();
 
    session = cluster.connect(keyspace);
}
 
Example 4
Source File: CassandraConfig.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
private Builder populateSettings(Builder builder, Map<String, String> properties) throws DataServiceFault {
    String serversParam = properties.get(DBConstants.Cassandra.CASSANDRA_SERVERS);
    String[] servers = serversParam.split(",");
    for (String server : servers) {
        builder = builder.addContactPoint(server);
    }
    String portProp = properties.get(DBConstants.Cassandra.PORT);
    if (portProp != null) {
        builder = builder.withPort(Integer.parseInt(portProp));
    }
    String clusterNameProp = properties.get(DBConstants.Cassandra.CLUSTER_NAME);
    if (clusterNameProp != null) {
        builder = builder.withClusterName(clusterNameProp);
    }
    String compressionProp = properties.get(DBConstants.Cassandra.COMPRESSION);
    if (compressionProp != null) {
        builder = builder.withCompression(Compression.valueOf(compressionProp));
    }        
    builder = this.populateCredentials(properties, builder);        
    builder = this.populateLoadBalancingProp(properties, builder);          
    String enableJMXProp = properties.get(DBConstants.Cassandra.ENABLE_JMX_REPORTING);
    if (enableJMXProp != null) {
        if (!Boolean.parseBoolean(enableJMXProp)) {
            builder = builder.withoutJMXReporting();
        }
    }
    String enableMetricsProp = properties.get(DBConstants.Cassandra.ENABLE_METRICS);
    if (enableMetricsProp != null) {
        if (!Boolean.parseBoolean(enableMetricsProp)) {
            builder = builder.withoutMetrics();
        }
    }        
    builder = this.populatePoolingSettings(properties, builder);        
    String versionProp = properties.get(DBConstants.Cassandra.PROTOCOL_VERSION);
    if (versionProp != null) {
        builder = builder.withProtocolVersion(ProtocolVersion.fromInt(Integer.parseInt(versionProp)));
    }
    builder = this.populateQueryOptions(properties, builder);
    builder = this.populateReconnectPolicy(properties, builder);
    builder = this.populateRetrytPolicy(properties, builder);
    builder = this.populateSocketOptions(properties, builder);
    String enableSSLProp = properties.get(DBConstants.Cassandra.ENABLE_SSL);
    if (enableSSLProp != null) {
        if (Boolean.parseBoolean(enableSSLProp)) {
            builder = builder.withSSL();
        }
    }
    return builder;
}
 
Example 5
Source File: CassandraConfig.java    From realtime-analytics with GNU General Public License v2.0 4 votes vote down vote up
public Builder createBuilder() {
    Builder builder = Cluster.builder();
    for (String address : contactPoints) {
        builder.addContactPoint(address);
    }
    builder.withCompression(compression);
    if (username != null && password != null) {
        builder.withCredentials(username, password);
    }
 
    if (reconnectionPolicy != null) {
        builder.withReconnectionPolicy(reconnectionPolicy);
    }

    if (retryPolicy != null) {
        builder.withRetryPolicy(retryPolicy);
    }
    builder.withPort(port);

    if (!jmxEnabled) {
        builder.withoutJMXReporting();
    }

    if (!metricsEnabled) {
        builder.withoutMetrics();
    }

    if (sslOptions != null) {
        builder.withSSL(sslOptions);
    }

    copyPoolingOptions(builder);

    SocketOptions opts = new SocketOptions();
    opts.setConnectTimeoutMillis(connectTimeoutMillis);
    opts.setReadTimeoutMillis(readTimeoutMillis);

    if (receiveBufferSize != null) {
        opts.setReceiveBufferSize(receiveBufferSize);
    }
    if (sendBufferSize != null) {
        opts.setSendBufferSize(sendBufferSize);
    }
    if (soLinger != null) {
        opts.setSoLinger(soLinger);
    }
    if (keepAlive != null) {
        opts.setKeepAlive(keepAlive);
    }
    if (reuseAddress != null) {
        opts.setReuseAddress(reuseAddress);
    }
    if (tcpNoDelay != null) {
        opts.setTcpNoDelay(tcpNoDelay);
    }

    builder.withSocketOptions(opts);
    return builder;
}