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


Java Cluster.Builder方法代码示例

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


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

示例1: getCluster

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
/**
 * Get a Cassandra cluster using hosts and port.
 */
private Cluster getCluster(List<String> hosts, int port, String username, String password,
                           String localDc, String consistencyLevel) {
  Cluster.Builder builder = Cluster.builder()
      .addContactPoints(hosts.toArray(new String[0]))
      .withPort(port);

  if (username != null) {
    builder.withAuthProvider(new PlainTextAuthProvider(username, password));
  }

  if (localDc != null) {
    builder.withLoadBalancingPolicy(
        new TokenAwarePolicy(new DCAwareRoundRobinPolicy.Builder().withLocalDc(localDc).build()));
  } else {
    builder.withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
  }

  if (consistencyLevel != null) {
    builder.withQueryOptions(
        new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevel)));
  }

  return builder.build();
}
 
开发者ID:apache,项目名称:beam,代码行数:28,代码来源:CassandraServiceImpl.java

示例2: getClientSession

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
public static Session getClientSession(String hostAddr) {
    if(REGISTRY.containsKey(hostAddr)) {
        return REGISTRY.get(hostAddr);
    } else {
        Cluster.Builder clientClusterBuilder = new Cluster.Builder()
                .addContactPoint(hostAddr)
                .withQueryOptions(new QueryOptions()
                        .setConsistencyLevel(ConsistencyLevel.ONE)
                        .setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL))
                .withoutJMXReporting()
                .withoutMetrics()
                .withReconnectionPolicy(new ConstantReconnectionPolicy(RECONNECT_DELAY_IN_MS));
        long startTimeInMillis = System.currentTimeMillis();
        Cluster clientCluster = clientClusterBuilder.build();
        Session clientSession = clientCluster.connect();

        LOG.info("Client session established after {} ms.", System.currentTimeMillis() - startTimeInMillis);
        REGISTRY.putIfAbsent(hostAddr, clientSession);
        return clientSession;
    }
}
 
开发者ID:mcfongtw,项目名称:flink-cassandra-connector-examples,代码行数:22,代码来源:ClientSessionProvider.java

示例3: adminSession

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
/** */
private static synchronized Session adminSession() {
    if (adminSes != null) {
        return adminSes;
    }
    try {
        Cluster.Builder builder = Cluster.builder();
        builder = builder.withCredentials(getAdminUser(), getAdminPassword());
        builder.addContactPoints(getContactPoints());
        builder.addContactPointsWithPorts(getContactPointsWithPorts());
        adminCluster = builder.build();
        return adminSes = adminCluster.connect();
    }
    catch (Throwable e) {
        throw new RuntimeException("Failed to create admin session to Cassandra database", e);
    }
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:18,代码来源:CassandraHelper.java

示例4: regularSession

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
/** */
private static synchronized Session regularSession() {
    if (regularSes != null) {
        return regularSes;
    }
    try {
        Cluster.Builder builder = Cluster.builder();
        builder = builder.withCredentials(getRegularUser(), getRegularPassword());
        builder.addContactPoints(getContactPoints());
        builder.addContactPointsWithPorts(getContactPointsWithPorts());
        regularCluster = builder.build();
        return regularSes = regularCluster.connect();
    }
    catch (Throwable e) {
        throw new RuntimeException("Failed to create regular session to Cassandra database", e);
    }
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:18,代码来源:CassandraHelper.java

示例5: setup

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
private void setup()
throws IOException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException,
              CertificateException, UnrecoverableKeyException  {
// Connect to Cassandra
Cluster.Builder clusterBuilder = Cluster.builder()
    .addContactPoint(host)
    .withPort(port)
    .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().build()));
if (null != username)
    clusterBuilder = clusterBuilder.withCredentials(username, password);
       if (null != truststorePath)
           clusterBuilder = clusterBuilder.withSSL(createSSLOptions());

cluster = clusterBuilder.build();
       if (null == cluster) {
           throw new IOException("Could not create cluster");
       }
session = cluster.connect();
   }
 
开发者ID:brianmhess,项目名称:cassandra-count,代码行数:20,代码来源:CqlCount.java

示例6: init

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
public void init(Class<T> tClass) {
    try {
        Cluster.Builder builder = Cluster.builder();
        final String[] nodesList = nodes.split(",");
        for (String node : nodesList) {
            builder.addContactPoint(node).withPort(Integer.parseInt(port));
            LOGGER.info(String.format("Added cassandra node : %s", node + ":" + port));
        }
        cluster = builder.build();
        session = null;
        if (keyspace != null) {
            session = cluster.connect(keyspace);
        } else {
            session = cluster.connect();
        }
        MappingManager mappingManager = new MappingManager(session);
        mapper = mappingManager.mapper(tClass);
    } catch (Exception e) {
        LOGGER.error("Error initializing CassandraDao");
        throw e;
    }
}
 
开发者ID:echauchot,项目名称:bigDataRocks,代码行数:23,代码来源:ACassandraDao.java

示例7: buildCluster

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
static Cluster buildCluster(Cassandra3Storage cassandra) {
  Cluster.Builder builder = Cluster.builder();
  List<InetSocketAddress> contactPoints = parseContactPoints(cassandra);
  int defaultPort = findConnectPort(contactPoints);
  builder.addContactPointsWithPorts(contactPoints);
  builder.withPort(defaultPort); // This ends up protocolOptions.port
  if (cassandra.username != null && cassandra.password != null) {
    builder.withCredentials(cassandra.username, cassandra.password);
  }
  builder.withRetryPolicy(ZipkinRetryPolicy.INSTANCE);
  builder.withLoadBalancingPolicy(new TokenAwarePolicy(new LatencyAwarePolicy.Builder(
      cassandra.localDc != null
          ? DCAwareRoundRobinPolicy.builder().withLocalDc(cassandra.localDc).build()
          : new RoundRobinPolicy()
      // This can select remote, but LatencyAwarePolicy will prefer local
  ).build()));
  builder.withPoolingOptions(new PoolingOptions().setMaxConnectionsPerHost(
      HostDistance.LOCAL, cassandra.maxConnections
  ));
  return builder.build();
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:22,代码来源:DefaultSessionFactory.java

示例8: buildCluster

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
static Cluster buildCluster(CassandraStorage cassandra) {
  Cluster.Builder builder = Cluster.builder();
  List<InetSocketAddress> contactPoints = parseContactPoints(cassandra);
  int defaultPort = findConnectPort(contactPoints);
  builder.addContactPointsWithPorts(contactPoints);
  builder.withPort(defaultPort); // This ends up protocolOptions.port
  if (cassandra.username != null && cassandra.password != null) {
    builder.withCredentials(cassandra.username, cassandra.password);
  }
  builder.withRetryPolicy(ZipkinRetryPolicy.INSTANCE);
  builder.withLoadBalancingPolicy(new TokenAwarePolicy(new LatencyAwarePolicy.Builder(
      cassandra.localDc != null
          ? DCAwareRoundRobinPolicy.builder().withLocalDc(cassandra.localDc).build()
          : new RoundRobinPolicy()
      // This can select remote, but LatencyAwarePolicy will prefer local
  ).build()));
  builder.withPoolingOptions(new PoolingOptions().setMaxConnectionsPerHost(
      HostDistance.LOCAL, cassandra.maxConnections
  ));
  return builder.build();
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:22,代码来源:SessionFactory.java

示例9: getClusterBuilderConfigurer

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
protected ClusterBuilderConfigurer getClusterBuilderConfigurer() {
	return new ClusterBuilderConfigurer() {

		@Override
		public Cluster.Builder configure(Cluster.Builder clusterBuilder) {
			if (CassandraConfiguration.this.cassandraProperties.isUseSsl()) {
				JdkSSLOptions.Builder optsBuilder = JdkSSLOptions.builder();
				if (CassandraConfiguration.this.cassandraProperties.isSkipSslValidation()) {
					try {
						optsBuilder.withSSLContext(TrustAllSSLContextFactory.getSslContext());
					}
					catch (NoSuchAlgorithmException | KeyManagementException e) {
						throw new RuntimeException("Unable to configure a Cassandra cluster using SSL.", e);
					}
				}
				return clusterBuilder.withSSL(optsBuilder.build());
			}
			else {
				return clusterBuilder;
			}
		}
	};
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:cassandra,代码行数:25,代码来源:CassandraConfiguration.java

示例10: testHostNotFoundErrorHandling

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Test(expected = NoHostAvailableException.class)
public void testHostNotFoundErrorHandling() throws Exception {
	CassandraSinkBase base = new CassandraSinkBase(new ClusterBuilder() {
		@Override
		protected Cluster buildCluster(Cluster.Builder builder) {
			return builder
				.addContactPoint("127.0.0.1")
				.withoutJMXReporting()
				.withoutMetrics().build();
		}
	}) {
		@Override
		public ListenableFuture send(Object value) {
			return null;
		}
	};

	base.open(new Configuration());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:20,代码来源:CassandraSinkBaseTest.java

示例11: createClusterBuilder

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
protected Cluster.Builder createClusterBuilder() throws Exception {
    CassandraLoadBalancingPolicies cassLoadBalancingPolicies = new CassandraLoadBalancingPolicies();
    Cluster.Builder clusterBuilder = Cluster.builder();
    for (String host : hosts.split(",")) {
        clusterBuilder = clusterBuilder.addContactPoint(host);
    }
    if (port != null) {
        clusterBuilder = clusterBuilder.withPort(port);
    }
    if (clusterName != null) {
        clusterBuilder = clusterBuilder.withClusterName(clusterName);
    }
    if (username != null && !username.isEmpty() && password != null) {
        clusterBuilder.withCredentials(username, password);
    }
    if (loadBalancingPolicy != null && !loadBalancingPolicy.isEmpty()) {
        clusterBuilder.withLoadBalancingPolicy(cassLoadBalancingPolicies.getLoadBalancingPolicy(loadBalancingPolicy));
    }
    return clusterBuilder;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:CassandraEndpoint.java

示例12: newSession

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
@Override
public CassandraSession newSession(CassandraSinkConnectorConfig config) {
  Cluster.Builder clusterBuilder = Cluster.builder()
      .withPort(config.port)
      .addContactPoints(config.contactPoints)
      .withProtocolVersion(ProtocolVersion.NEWEST_SUPPORTED);
  if (config.securityEnabled) {
    clusterBuilder.withCredentials(config.username, config.password);
  }
  if (config.sslEnabled) {
    final SslContextBuilder sslContextBuilder = SslContextBuilder.forClient();
    sslContextBuilder.sslProvider(config.sslProvider);
    final SslContext context;
    try {
      context = sslContextBuilder.build();
    } catch (SSLException e) {
      throw new ConnectException(e);
    }
    final SSLOptions sslOptions = new RemoteEndpointAwareNettySSLOptions(context);
    clusterBuilder.withSSL(sslOptions);
  }
  clusterBuilder.withCompression(config.compression);
  Cluster cluster = clusterBuilder.build();
  log.info("Creating session");
  final Session session = cluster.newSession();
  return new CassandraSessionImpl(config, cluster, session);
}
 
开发者ID:jcustenborder,项目名称:kafka-connect-cassandra,代码行数:28,代码来源:CassandraSessionFactoryImpl.java

示例13: provideCluster

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
/**
 * Creates a cluster to use for connecting to Cassandra.
 *
 * @return The cluster singleton to use within the Injector
 */
@Provides
@Singleton
Cluster provideCluster() {
    final Cluster.Builder builder = Cluster.builder().withClusterName(this.name);

    // Contact points are required
    final String contactPointsString = this.configuration.get(CONTACT_POINTS_KEY);
    if (contactPointsString == null) {
        throw new IllegalArgumentException(CONTACT_POINTS_KEY + " value is missing and is required.");
    }
    final String[] contactPoints = contactPointsString.split(",");
    final ImmutableList.Builder<InetAddress> contactAddresses = ImmutableList.builder();
    for (final String contactPoint : contactPoints) {
        try {
            contactAddresses.add(InetAddress.getByName(contactPoint));
        } catch (final UnknownHostException uhe) {
            throw new IllegalArgumentException("Can't parse contact point " + contactPoint, uhe);
        }
    }
    builder.addContactPoints(contactAddresses.build());
    final String port = this.configuration.get(PORT_KEY);
    if (port != null) {
        builder.withPort(Integer.parseInt(port));
    }

    final String username = this.configuration.get(USERNAME_KEY);
    final String password = this.configuration.get(PASSWORD_KEY);
    if (username != null && password != null) {
        builder.withCredentials(username, password);
    }
    return builder.build();
}
 
开发者ID:Netflix,项目名称:metacat,代码行数:38,代码来源:CassandraConnectorModule.java

示例14: dropTestKeyspace

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
public static void dropTestKeyspace( String keyspace, String[] hosts, int port ) {

        Cluster.Builder builder = Cluster.builder();
        for ( String host : hosts ) {
            builder = builder.addContactPoint( host ).withPort( port );
        }

        final QueryOptions queryOptions = new QueryOptions().setConsistencyLevel( ConsistencyLevel.LOCAL_QUORUM );
        builder.withQueryOptions( queryOptions );
        Cluster cluster = builder.build();

        Session session = cluster.connect();
        logger.info("Dropping test keyspace: {}", keyspace);
        session.execute( "DROP KEYSPACE IF EXISTS " + keyspace );
    }
 
开发者ID:apache,项目名称:usergrid-qakka,代码行数:16,代码来源:KeyspaceDropper.java

示例15: setHost

import com.datastax.driver.core.Cluster; //导入方法依赖的package包/类
/**
 * Sets the cassandra host/port to connect to.
 *
 * @param host host to connect to
 * @param port port to connect to
 * @return this builder
 */
public CassandraSinkBuilder<IN> setHost(final String host, final int port) {
	if (this.builder != null) {
		throw new IllegalArgumentException("Builder was already set. You must use either setHost() or setClusterBuilder().");
	}
	this.builder = new ClusterBuilder() {
		@Override
		protected Cluster buildCluster(Cluster.Builder builder) {
			return builder.addContactPoint(host).withPort(port).build();
		}
	};
	return this;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:20,代码来源:CassandraSink.java


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