com.datastax.driver.core.ProtocolOptions.Compression Java Examples

The following examples show how to use com.datastax.driver.core.ProtocolOptions.Compression. 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: AbstractCassandraCluster.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
protected void init(String keyspaceName) {
    this.keyspaceName = keyspaceName;
    Cluster.Builder builder = Cluster.builder()
            .addContactPointsWithPorts(getContactPoints(url))
            .withClusterName(clusterName)
            .withSocketOptions(socketOpts.getOpts())
            .withPoolingOptions(new PoolingOptions()
                    .setMaxRequestsPerConnection(HostDistance.LOCAL, 32768)
                    .setMaxRequestsPerConnection(HostDistance.REMOTE, 32768));
    builder.withQueryOptions(queryOpts.getOpts());
    builder.withCompression(StringUtils.isEmpty(compression) ? Compression.NONE : Compression.valueOf(compression.toUpperCase()));
    if (ssl) {
        builder.withSSL();
    }
    if (!jmx) {
        builder.withoutJMXReporting();
    }
    if (!metrics) {
        builder.withoutMetrics();
    }
    if (credentials) {
        builder.withCredentials(username, password);
    }
    cluster = builder.build();
    cluster.init();
    if (!isInstall()) {
        initSession();
    }
}
 
Example #2
Source File: CumulusDataAccessLayerFactory.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public void accept(final Configuration<Map<String, Object>> configuration) {

	synchronized (CLUSTER_LOCK) {
		if (cluster == null) {
			
			final String hosts = configuration.getAttribute(HOSTS, "localhost");

			final Compression compression = compression(configuration);
			final Cluster.Builder builder = Cluster.builder()
					.addContactPoints(hosts.split("\\s*,\\s*"))
					.withRetryPolicy(retryPolicy(configuration))
					.withReconnectionPolicy(reconnectionPolicy(configuration))
					.withLoadBalancingPolicy(loadBalancingPolicy(configuration))
					.withPoolingOptions(poolingOptions(configuration))
					.withQueryOptions(queryOptions(configuration))
					.withSocketOptions(socketOptions(configuration));

			if (compression != null) {
				builder.withCompression(compression);
			}
			
			cluster = builder.build();
			
			LOGGER.debug(MessageCatalog._00107_CONNECTED_TO_CLUSTER);
		}
	}

	_session = cluster.connect();

	_keyspaceName = configuration.getAttribute(KEYSPACE, "KeyspaceCumulus") + _keyspaceNameSuffix;
	_replicationFactor = configuration.getAttribute(REPLICATION_FACTOR, Integer.valueOf(1));
	_ttl = configuration.getAttribute(TTL, Integer.valueOf(-1));
}
 
Example #3
Source File: CQLService.java    From Doradus with Apache License 2.0 5 votes vote down vote up
private Cluster buildClusterSpecs() {
    Cluster.Builder builder = Cluster.builder();
    
    // dbhost
    String dbhost = getParamString("dbhost");
    String[] nodeAddresses = dbhost.split(",");
    for (String address : nodeAddresses) {
        builder.addContactPoint(address);
    }
    
    // dbport
    builder.withPort(getParamInt("dbport", 9042));
    
    // db_timeout_millis and db_connect_retry_wait_millis
    SocketOptions socketOpts = new SocketOptions();
    socketOpts.setReadTimeoutMillis(getParamInt("db_timeout_millis", 10000));
    socketOpts.setConnectTimeoutMillis(getParamInt("db_connect_retry_wait_millis", 5000));
    builder.withSocketOptions(socketOpts);
    
    // dbuser/dbpassword
    String dbuser = getParamString("dbuser");
    if (!Utils.isEmpty(dbuser)) {
        builder.withCredentials(dbuser, getParamString("dbpassword"));
    }
    
    // compression
    builder.withCompression(Compression.SNAPPY);
    
    // TLS/SSL
    if (getParamBoolean("dbtls")) {
        builder.withSSL(getSSLOptions());
    }
    
    return builder.build();
}
 
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: CassandraSessionImpl.java    From newts with Apache License 2.0 4 votes vote down vote up
@Inject
public CassandraSessionImpl(@Named("cassandra.keyspace") String keyspace, @Named("cassandra.hostname") String hostname,
        @Named("cassandra.port") int port, @Named("cassandra.compression") String compression,
        @Named("cassandra.username") String username, @Named("cassandra.password") String password,
        @Named("cassandra.ssl") boolean ssl,
        @Named("cassandra.pool.core-connections-per-host") Integer coreConnectionsPerHost,
        @Named("cassandra.pool.max-connections-per-host") Integer maxConnectionsPerHost,
        @Named("cassandra.pool.max-requests-per-connection") Integer maxRequestsPerConnection) {

    checkNotNull(keyspace, "keyspace argument");
    checkNotNull(hostname, "hostname argument");
    checkArgument(port > 0 && port < 65535, "not a valid port number: %d", port);
    checkNotNull(compression, "compression argument");

    LOG.info("Setting up session with {}:{} using compression {}", hostname, port, compression.toUpperCase());

    final PoolingOptions poolingOptions = new PoolingOptions();
    if (coreConnectionsPerHost != null) {
        LOG.debug("Using {} core connections per host.", coreConnectionsPerHost);
        poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, coreConnectionsPerHost)
                .setCoreConnectionsPerHost(HostDistance.REMOTE, coreConnectionsPerHost);
    }
    if (maxConnectionsPerHost != null) {
        LOG.debug("Using {} max connections per host.", maxConnectionsPerHost);
        poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnectionsPerHost)
                .setMaxConnectionsPerHost(HostDistance.REMOTE, maxConnectionsPerHost);
    }
    if (maxRequestsPerConnection != null) {
        LOG.debug("Using {} max requests per connection.", maxRequestsPerConnection);
        poolingOptions.setMaxRequestsPerConnection(HostDistance.LOCAL, maxRequestsPerConnection)
                .setMaxRequestsPerConnection(HostDistance.REMOTE, maxRequestsPerConnection);
    }

    Builder builder = Cluster
            .builder()
            .withPort(port)
            .addContactPoints(hostname.split(","))
            .withReconnectionPolicy(new ExponentialReconnectionPolicy(1000, 2 * 60 * 1000))
            .withPoolingOptions(poolingOptions)
            .withCompression(Compression.valueOf(compression.toUpperCase()));

    if (username != null && password != null) {
        LOG.info("Using username: {} and password: XXXXXXXX", username);
        builder.withCredentials(username, password);
    }

    if (ssl) {
        LOG.info("Enabling SSL.");
        builder.withSSL();
    }

    m_session = builder.build().connect(keyspace);
}
 
Example #6
Source File: CassandraClusterConfig.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
public Compression getCompression() {
	return compression;
}
 
Example #7
Source File: CassandraClusterConfig.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
public void setCompression(Compression compression) {
	this.compression = compression;
}