当前位置: 首页>>代码示例>>Java>>正文


Java Builder类代码示例

本文整理汇总了Java中com.datastax.driver.core.Cluster.Builder的典型用法代码示例。如果您正苦于以下问题:Java Builder类的具体用法?Java Builder怎么用?Java Builder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Builder类属于com.datastax.driver.core.Cluster包,在下文中一共展示了Builder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getClient

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
/**
 * Returns a Cassandra session object.
 * @return a connection session to Cassandra
 */
public static Session getClient() {
	if (session != null) {
		return session;
	}
	try {
		Builder builder = Cluster.builder().addContactPoints(DBHOSTS.split(",")).
				withPort(DBPORT).withCredentials(DBUSER, DBPASS);
		if (SSL) {
			builder.withSSL();
		}
		cluster = builder.build();
		session = cluster.connect();
		if (!existsTable(Config.getRootAppIdentifier())) {
			createTable(session, Config.getRootAppIdentifier());
		} else {
			session.execute("USE " + DBNAME + ";");
		}
		logger.debug("Cassandra host: " + DBHOSTS + ":" + DBPORT + ", keyspace: " + DBNAME);
	} catch (Exception e) {
		logger.error("Failed to connect ot Cassandra: {}.", e.getMessage());
	}

	Runtime.getRuntime().addShutdownHook(new Thread() {
		public void run() {
			shutdownClient();
		}
	});

	return session;
}
 
开发者ID:Erudika,项目名称:para-dao-cassandra,代码行数:35,代码来源:CassandraUtils.java

示例2: main

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
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");
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:18,代码来源:CassandraTupleSinkExample.java

示例3: main

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
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();
			}
		})
		.setMapperOptions(() -> new Mapper.Option[]{Mapper.Option.saveNullFields(true)})
		.build();

	env.execute("Cassandra Sink example");
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:18,代码来源:CassandraPojoSinkExample.java

示例4: main

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
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");
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:17,代码来源:CassandraPojoSinkExample.java

示例5: CassandraSession

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
public CassandraSession(String connectorId,
        final Builder clusterBuilder,
        int fetchSizeForPartitionKeySelect,
        int limitForPartitionKeySelect,
        JsonCodec<List<ExtraColumnMetadata>> extraColumnMetadataCodec)
{
    this.connectorId = connectorId;
    this.fetchSizeForPartitionKeySelect = fetchSizeForPartitionKeySelect;
    this.limitForPartitionKeySelect = limitForPartitionKeySelect;
    this.extraColumnMetadataCodec = extraColumnMetadataCodec;

    sessionBySchema = CacheBuilder.newBuilder()
            .build(new CacheLoader<String, Session>()
            {
                @Override
                public Session load(String key)
                        throws Exception
                {
                    return clusterBuilder.build().connect();
                }
            });
}
 
开发者ID:y-lan,项目名称:presto,代码行数:23,代码来源:CassandraSession.java

示例6: copyPoolingOptions

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
private void copyPoolingOptions(Builder builder) {
    PoolingOptions opts = new PoolingOptions();

    opts.setCoreConnectionsPerHost(HostDistance.REMOTE,
            remoteCoreConnectionsPerHost);
    opts.setCoreConnectionsPerHost(HostDistance.LOCAL,
            localCoreConnectionsPerHost);
    opts.setMaxConnectionsPerHost(HostDistance.REMOTE,
            remoteMaxConnectionsPerHost);
    opts.setMaxConnectionsPerHost(HostDistance.LOCAL,
            localMaxConnectionsPerHost);
    opts.setMaxSimultaneousRequestsPerConnectionThreshold(
            HostDistance.REMOTE,
            remoteMaxSimultaneousRequestsPerConnectionThreshold);
    opts.setMaxSimultaneousRequestsPerConnectionThreshold(
            HostDistance.LOCAL,
            localMaxSimultaneousRequestsPerConnectionThreshold);
    opts.setMinSimultaneousRequestsPerConnectionThreshold(
            HostDistance.REMOTE,
            remoteMinSimultaneousRequestsPerConnectionThreshold);
    opts.setMinSimultaneousRequestsPerConnectionThreshold(
            HostDistance.LOCAL,
            localMinSimultaneousRequestsPerConnectionThreshold);

    builder.withPoolingOptions(opts);
}
 
开发者ID:pulsarIO,项目名称:realtime-analytics,代码行数:27,代码来源:CassandraConfig.java

示例7: createCluster

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
public void createCluster() {
    erroredOut = false;
    schemaCreated = false;
    cassandraCluster = CCMBridge.create("test", 1);
    try {
        Builder builder = Cluster.builder();
        builder = configure(builder);
        cluster = builder.addContactPoints(IP_PREFIX + '1').build();
        session = cluster.connect();
    } catch (NoHostAvailableException e) {
        erroredOut = true;
        for (Map.Entry<InetSocketAddress, Throwable> entry : e.getErrors().entrySet())
            logger.info("Error connecting to " + entry.getKey() + ": " + entry.getValue());
        throw new RuntimeException(e);
    }
}
 
开发者ID:adejanovski,项目名称:cassandra-jdbc-wrapper,代码行数:17,代码来源:CCMBridge.java

示例8: SchemaManager

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
@Inject
public SchemaManager(@Named("cassandra.keyspace") String keyspace, @Named("cassandra.host") String host, @Named("cassandra.port") int port,
        @Named("cassandra.username") String username, @Named("cassandra.password") String password, @Named("cassandra.ssl") boolean ssl) {
    m_keyspace = keyspace;

    Builder builder = Cluster.builder()
            .withPort(port)
            .addContactPoints(host.split(","));
    if (username != null && password != null) {
        LOG.info("Using username: {} and password: XXXXXXXX", username);
        builder.withCredentials(username, password);
    }

    if (ssl) {
        LOG.info("Using SSL.");
        builder.withSSL();
    }
    m_cluster= builder.build();
    m_session = m_cluster.connect();
}
 
开发者ID:OpenNMS,项目名称:newts,代码行数:21,代码来源:SchemaManager.java

示例9: CassandraConfig

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
public CassandraConfig(DataService dataService, String configId, Map<String, String> properties,
                       boolean odataEnable) throws DataServiceFault {
    super(dataService, configId, DataSourceTypes.CASSANDRA, properties, odataEnable);
    Builder builder = Cluster.builder();
    this.populateSettings(builder, properties);
    String keyspace = properties.get(DBConstants.Cassandra.KEYSPACE);
    this.cluster = builder.build();
    try {
        if (keyspace != null && keyspace.trim().length() > 0) {
            this.session = this.cluster.connect(keyspace);
        } else {
            this.session = this.cluster.connect();
        }
        this.nativeBatchRequestsSupported = this.session.getCluster().
                getConfiguration().getProtocolOptions().getProtocolVersion().toInt() > 1;
    } catch (NoHostAvailableException e) {
        throw new DataServiceFault(e, DBConstants.FaultCodes.CONNECTION_UNAVAILABLE_ERROR, e.getMessage());
    }
}
 
开发者ID:wso2,项目名称:carbon-data,代码行数:20,代码来源:CassandraConfig.java

示例10: populateQueryOptions

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
private Builder populateQueryOptions(Map<String, String> properties, Builder builder) {
    String consistencyLevelProp = properties.get(DBConstants.Cassandra.CONSISTENCY_LEVEL);
    String serialConsistencyLevelProp = properties.get(DBConstants.Cassandra.SERIAL_CONSISTENCY_LEVEL);
    String fetchSize = properties.get(DBConstants.Cassandra.FETCH_SIZE);
    QueryOptions options = new QueryOptions();
    if (consistencyLevelProp != null) {
        options.setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevelProp));
    }
    if (serialConsistencyLevelProp != null) {
        options.setSerialConsistencyLevel(ConsistencyLevel.valueOf(serialConsistencyLevelProp));
    }
    if (fetchSize != null) {
        options.setFetchSize(Integer.parseInt(fetchSize));
    }
    return builder.withQueryOptions(options);
}
 
开发者ID:wso2,项目名称:carbon-data,代码行数:17,代码来源:CassandraConfig.java

示例11: populateRetrytPolicy

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
private Builder populateRetrytPolicy(Map<String, String> properties, Builder builder) throws DataServiceFault {
    String retryPolicy = properties.get(DBConstants.Cassandra.RETRY_POLICY);
    if (retryPolicy != null) {
        if ("DefaultRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(DefaultRetryPolicy.INSTANCE);
        } else if ("DowngradingConsistencyRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
        } else if ("FallthroughRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(FallthroughRetryPolicy.INSTANCE);
        } else if ("LoggingDefaultRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE));
        } else if ("LoggingDowngradingConsistencyRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE));                
        } else if ("LoggingFallthroughRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(new LoggingRetryPolicy(FallthroughRetryPolicy.INSTANCE));                
        } else {
            throw new DataServiceFault("Invalid Cassandra retry policy: " + retryPolicy);
        }
    }
    return builder;
}
 
开发者ID:wso2,项目名称:carbon-data,代码行数:22,代码来源:CassandraConfig.java

示例12: connectViaConnectionString

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
@Test
public void connectViaConnectionString() throws Exception {
  new MockUnit(Env.class, Config.class, Binder.class, Cluster.class, Cluster.Builder.class,
      Configuration.class, Session.class)
      .expect(clusterBuilder)
      .expect(serviceKey(new Env.ServiceKey()))
      .expect(contactPoints("localhost"))
      .expect(port(9042))
      .expect(codecRegistry)
      .expect(bind("beers", Cluster.class))
      .expect(bind(null, Cluster.class))
      .expect(bind("beers", Session.class))
      .expect(bind(null, Session.class))
      .expect(connect("beers"))
      .expect(mapper)
      .expect(bind("beers", MappingManager.class))
      .expect(bind(null, MappingManager.class))
      .expect(datastore)
      .expect(bind("beers", Datastore.class))
      .expect(bind(null, Datastore.class))
      .expect(routeMapper).expect(onStop)
      .run(unit -> {
        new Cassandra("cassandra://localhost/beers")
            .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:27,代码来源:CassandraTest.java

示例13: connectViaConnectionStringSupplier

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
@Test
public void connectViaConnectionStringSupplier() throws Exception {
  new MockUnit(Env.class, Config.class, Binder.class, Cluster.class, Cluster.Builder.class,
      Configuration.class, Session.class)
      .expect(clusterBuilderProvider)
      .expect(serviceKey(new Env.ServiceKey()))
      .expect(contactPoints("localhost"))
      .expect(port(9042))
      .expect(codecRegistry)
      .expect(bind("beers", Cluster.class))
      .expect(bind(null, Cluster.class))
      .expect(bind("beers", Session.class))
      .expect(bind(null, Session.class))
      .expect(connect("beers"))
      .expect(mapper)
      .expect(bind("beers", MappingManager.class))
      .expect(bind(null, MappingManager.class))
      .expect(datastore)
      .expect(bind("beers", Datastore.class))
      .expect(bind(null, Datastore.class))
      .expect(routeMapper).expect(onStop)
      .run(unit -> {
        new Cassandra("cassandra://localhost/beers", () -> unit.get(Cluster.Builder.class))
            .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:27,代码来源:CassandraTest.java

示例14: setUpBeforeClass

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
@BeforeClass
    public synchronized static void setUpBeforeClass() throws Exception {
        if (factory == null) {
//            logger.info("Starting embedded cassandra...");
//            EmbeddedCassandraServerHelper.startEmbeddedCassandra("unittest-cassandra.yaml", "./build/cassandra");
//            Thread.sleep(100);
//            logger.info("Successfully started embedded cassandra.");

            final Cluster cluster = new Builder().addContactPoint("localhost").withPort(CASSANDRA_PORT).build();
//            final Session session = cluster.newSession();
//            session.execute("CREATE KEYSPACE copper WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };");

            factory = new UnitTestCassandraEngineFactory(false);
            factory.setCassandraPort(CASSANDRA_PORT);
            factory.getEngine().startup();
        }
    }
 
开发者ID:copper-engine,项目名称:copper-engine,代码行数:18,代码来源:CassandraTest.java

示例15: CassandraSessionProxy

import com.datastax.driver.core.Cluster.Builder; //导入依赖的package包/类
private CassandraSessionProxy(Consumer<Builder> clusterBuilderSetter, String keyspaceName,
    String user, String password, String schemaCQL) {
  this.keyspaceName = keyspaceName;

  setCluster(clusterBuilderSetter, user, password);

  createSchema(schemaCQL, keyspaceName, true);

  try {
    session = createSessionForKeyspace(keyspaceName);
  } catch (Exception ex) {
    ex.printStackTrace();
  }
}
 
开发者ID:Telecooperation,项目名称:assistance-platform-server,代码行数:15,代码来源:CassandraSessionProxy.java


注:本文中的com.datastax.driver.core.Cluster.Builder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。