Search in sources :

Example 1 with Builder

use of com.datastax.driver.core.Cluster.Builder in project flink by apache.

the class CassandraPojoSinkExample method main.

public static void main(String[] args) throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStreamSource<Message> source = env.fromCollection(messages);
    CassandraSink.addSink(source).setClusterBuilder(new ClusterBuilder() {

        @Override
        protected Cluster buildCluster(Builder builder) {
            return builder.addContactPoint("127.0.0.1").build();
        }
    }).build();
    env.execute("Cassandra Sink example");
}
Also used : Builder(com.datastax.driver.core.Cluster.Builder) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)

Example 2 with Builder

use of com.datastax.driver.core.Cluster.Builder in project flink by apache.

the class CassandraTupleSinkExample method main.

public static void main(String[] args) throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStreamSource<Tuple2<String, Integer>> source = env.fromCollection(collection);
    CassandraSink.addSink(source).setQuery(INSERT).setClusterBuilder(new ClusterBuilder() {

        @Override
        protected Cluster buildCluster(Builder builder) {
            return builder.addContactPoint("127.0.0.1").build();
        }
    }).build();
    env.execute("WriteTupleIntoCassandra");
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) Builder(com.datastax.driver.core.Cluster.Builder) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)

Example 3 with Builder

use of com.datastax.driver.core.Cluster.Builder in project flink by apache.

the class BatchExample method main.

/*
	 *	table script: "CREATE TABLE test.batches (number int, strings text, PRIMARY KEY(number, strings));"
	 */
public static void main(String[] args) throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(1);
    ArrayList<Tuple2<Integer, String>> collection = new ArrayList<>(20);
    for (int i = 0; i < 20; i++) {
        collection.add(new Tuple2<>(i, "string " + i));
    }
    DataSet<Tuple2<Integer, String>> dataSet = env.fromCollection(collection);
    dataSet.output(new CassandraOutputFormat<Tuple2<Integer, String>>(INSERT_QUERY, new ClusterBuilder() {

        @Override
        protected Cluster buildCluster(Builder builder) {
            return builder.addContactPoints("127.0.0.1").build();
        }
    }));
    env.execute("Write");
    DataSet<Tuple2<Integer, String>> inputDS = env.createInput(new CassandraInputFormat<Tuple2<Integer, String>>(SELECT_QUERY, new ClusterBuilder() {

        @Override
        protected Cluster buildCluster(Builder builder) {
            return builder.addContactPoints("127.0.0.1").build();
        }
    }), TupleTypeInfo.of(new TypeHint<Tuple2<Integer, String>>() {
    }));
    inputDS.print();
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) TypeHint(org.apache.flink.api.common.typeinfo.TypeHint) Builder(com.datastax.driver.core.Cluster.Builder) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) ArrayList(java.util.ArrayList) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) TypeHint(org.apache.flink.api.common.typeinfo.TypeHint) Tuple2(org.apache.flink.api.java.tuple.Tuple2)

Example 4 with Builder

use of com.datastax.driver.core.Cluster.Builder in project cassandra-driver-mapping by valchkou.

the class SchemaSyncTest method init.

@BeforeClass
public static void init() {
    String node = "127.0.0.1";
    Builder builder = Cluster.builder();
    builder.addContactPoint(node);
    builder.withLoadBalancingPolicy(LatencyAwarePolicy.builder(new RoundRobinPolicy()).build());
    builder.withReconnectionPolicy(new ConstantReconnectionPolicy(1000L));
    cluster = builder.build();
    session = cluster.connect();
    Cache<String, PreparedStatement> cache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MILLISECONDS).maximumSize(1).concurrencyLevel(1).build();
    MappingSession.setStatementCache(cache);
}
Also used : Builder(com.datastax.driver.core.Cluster.Builder) CacheBuilder(com.google.common.cache.CacheBuilder) PreparedStatement(com.datastax.driver.core.PreparedStatement) RoundRobinPolicy(com.datastax.driver.core.policies.RoundRobinPolicy) ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy) BeforeClass(org.junit.BeforeClass)

Example 5 with Builder

use of com.datastax.driver.core.Cluster.Builder in project cassandra-driver-mapping by valchkou.

the class MappingSessionAsyncTest method init.

@BeforeClass
public static void init() {
    String node = "127.0.0.1";
    Builder builder = Cluster.builder();
    builder.addContactPoint(node);
    builder.withLoadBalancingPolicy(LatencyAwarePolicy.builder(new RoundRobinPolicy()).build());
    builder.withReconnectionPolicy(new ConstantReconnectionPolicy(1000L));
    cluster = builder.build();
    session = cluster.connect();
    Cache<String, PreparedStatement> cache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MILLISECONDS).maximumSize(1).concurrencyLevel(1).build();
    MappingSession.setStatementCache(cache);
}
Also used : Builder(com.datastax.driver.core.Cluster.Builder) CacheBuilder(com.google.common.cache.CacheBuilder) PreparedStatement(com.datastax.driver.core.PreparedStatement) RoundRobinPolicy(com.datastax.driver.core.policies.RoundRobinPolicy) ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy) BeforeClass(org.junit.BeforeClass)

Aggregations

Builder (com.datastax.driver.core.Cluster.Builder)6 ConstantReconnectionPolicy (com.datastax.driver.core.policies.ConstantReconnectionPolicy)3 RoundRobinPolicy (com.datastax.driver.core.policies.RoundRobinPolicy)3 CacheBuilder (com.google.common.cache.CacheBuilder)3 ClusterBuilder (org.apache.flink.streaming.connectors.cassandra.ClusterBuilder)3 PreparedStatement (com.datastax.driver.core.PreparedStatement)2 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)2 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)2 BeforeClass (org.junit.BeforeClass)2 QueryBuilder (com.datastax.driver.core.querybuilder.QueryBuilder)1 ArrayList (java.util.ArrayList)1 TypeHint (org.apache.flink.api.common.typeinfo.TypeHint)1 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)1