com.datastax.driver.core.policies.WhiteListPolicy Java Examples

The following examples show how to use com.datastax.driver.core.policies.WhiteListPolicy. 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: Application.java    From cassandra-exporter with Apache License 2.0 6 votes vote down vote up
private Cluster establishClusterConnection() {
    final Cluster.Builder clusterBuilder = Cluster.builder()
            .addContactPointsWithPorts(cqlAddress)
            .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), ImmutableList.of(cqlAddress)));

    if (cqlUser != null ^ cqlPassword != null) {
        throw new ParameterException(commandSpec.commandLine(), "Both --cql-user and --cql-password are required when either is used.");
    }

    if (cqlUser != null && cqlPassword != null) {
        clusterBuilder.withCredentials(cqlUser, cqlPassword);
    }

    final Cluster cluster = clusterBuilder.build();

    cluster.connect();

    return cluster;
}
 
Example #2
Source File: CQLSession.java    From cassandra-sidecar with Apache License 2.0 5 votes vote down vote up
@Inject
public CQLSession(Configuration configuration)
{
    inet = InetSocketAddress.createUnresolved(configuration.getCassandraHost(), configuration.getCassandraPort());
    wlp = new WhiteListPolicy(new RoundRobinPolicy(), Collections.singletonList(inet));
    this.nettyOptions = new NettyOptions();
    this.queryOptions = new QueryOptions().setConsistencyLevel(ConsistencyLevel.ONE);
    this.reconnectionPolicy = new ExponentialReconnectionPolicy(1000,
                                                                configuration.getHealthCheckFrequencyMillis());
}
 
Example #3
Source File: CQLSession.java    From cassandra-sidecar with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
CQLSession(InetSocketAddress target, NettyOptions options)
{
    inet = target;
    wlp = new WhiteListPolicy(new RoundRobinPolicy(), Collections.singletonList(inet));
    this.nettyOptions = options;
    this.queryOptions = new QueryOptions().setConsistencyLevel(ConsistencyLevel.ONE);
    reconnectionPolicy = new ExponentialReconnectionPolicy(100, 1000);
}
 
Example #4
Source File: WhiteListPolicyFactoryTest.java    From dropwizard-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void buildsPolicy() throws Exception {
    final WhiteListPolicyFactory factory = new WhiteListPolicyFactory();
    factory.setSubPolicy(subPolicyFactory);
    factory.setWhiteList(Collections.singletonList(new InetSocketAddress("localhost", 9876)));

    final WhiteListPolicy policy = (WhiteListPolicy) factory.build();

    assertThat(policy.getChildPolicy()).isSameAs(subPolicy);
}
 
Example #5
Source File: JavaDriverClient.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public JavaDriverClient(StressSettings settings, String host, int port, EncryptionOptions.ClientEncryptionOptions encryptionOptions)
{
    this.host = host;
    this.port = port;
    this.username = settings.mode.username;
    this.password = settings.mode.password;
    this.authProvider = settings.mode.authProvider;
    this.encryptionOptions = encryptionOptions;
    if (settings.node.isWhiteList)
        whitelist = new WhiteListPolicy(new DCAwareRoundRobinPolicy(), settings.node.resolveAll(settings.port.nativePort));
    else
        whitelist = null;
}
 
Example #6
Source File: WhiteListPolicyFactory.java    From dropwizard-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public LoadBalancingPolicy build() {
    return new WhiteListPolicy(subPolicy.build(), whiteList);
}