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


Java Builder.addContactPoint方法代码示例

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


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

示例1: LockFactory

import com.datastax.driver.core.Cluster.Builder; //导入方法依赖的package包/类
/**
 * Constructor, creates Cassandra session
 * @param contactPoints Cassandra cluster contact points
 * @param keyspace Keyspace for `lock_leases`
 */
public LockFactory(String contactPoints, String keyspace) {
	Builder builder = Cluster.builder();
	for (String point : contactPoints.split(",")) {
		builder.addContactPoint(point.trim());
	}
	
	Cluster cluster = builder.build();
    session = cluster.connect();
    session.execute("USE " + keyspace);
    generalInit();
}
 
开发者ID:dekses,项目名称:cassandra-lock,代码行数:17,代码来源:LockFactory.java

示例2: connect

import com.datastax.driver.core.Cluster.Builder; //导入方法依赖的package包/类
private void connect(String nodes, String dataCenter, String username, String password) {
    Builder builder = Cluster.builder();
    if (nodes == null || nodes.isEmpty()) {
        throw new RuntimeException(Const.CASS_NODES + " is not defined");
    }
    if (dataCenter != null && !dataCenter.isEmpty()) {
        DCAwareRoundRobinPolicy policy = DCAwareRoundRobinPolicy.builder()
                .withLocalDc(dataCenter)
                .build();
        builder.withLoadBalancingPolicy(policy);
    }
    String[] nodeParts = nodes.split(",");
    for (String node : nodeParts) {
        node = node.trim();
        if (!node.isEmpty()) {
            LOGGER.info("Adding Cassandra node {}", node);
            builder.addContactPoint(node);
        }
    }
    if (username != null && !username.isEmpty() && password != null && !password.isEmpty()) {
        builder.withCredentials(username, password);
    }
    cluster = builder.build();
    Metadata metadata = cluster.getMetadata();
    LOGGER.info("Connected to cluster: {}", metadata.getClusterName());
    for (Host host : metadata.getAllHosts()) {
        LOGGER.info("Datacenter: {} Host: {} Rack: {}", host.getDatacenter(), host.getAddress(), host.getRack());
    }
}
 
开发者ID:Jukkorsis,项目名称:Hadrian,代码行数:30,代码来源:CassandraDataAccessFactory.java

示例3: createBuilder

import com.datastax.driver.core.Cluster.Builder; //导入方法依赖的package包/类
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;
}
 
开发者ID:pulsarIO,项目名称:realtime-analytics,代码行数:60,代码来源:CassandraConfig.java

示例4: populateSettings

import com.datastax.driver.core.Cluster.Builder; //导入方法依赖的package包/类
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;
}
 
开发者ID:wso2,项目名称:carbon-data,代码行数:50,代码来源:CassandraConfig.java


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