本文整理汇总了Java中com.datastax.driver.core.Cluster.Builder.withCredentials方法的典型用法代码示例。如果您正苦于以下问题:Java Builder.withCredentials方法的具体用法?Java Builder.withCredentials怎么用?Java Builder.withCredentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.datastax.driver.core.Cluster.Builder
的用法示例。
在下文中一共展示了Builder.withCredentials方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: open
import com.datastax.driver.core.Cluster.Builder; //导入方法依赖的package包/类
public void open() {
if ( cluster == null || session == null ) {
Builder builder = Cluster.builder();
builder.addContactPoints( hosts );
if ( user != null && pass != null && !user.isEmpty() && !pass.isEmpty() ) {
builder = builder.withCredentials( user, pass );
}
cluster = builder.build();
session = cluster.connect( keyspace );
}
}
示例3: CassandraSessionImpl
import com.datastax.driver.core.Cluster.Builder; //导入方法依赖的package包/类
@Inject
public CassandraSessionImpl(@Named("cassandra.keyspace") String keyspace, @Named("cassandra.hostname") String hostname,
@Named("cassandra.port") int port, @Named("cassandra.compression") String compression,
@Named("cassandra.username") String username, @Named("cassandra.password") String password,
@Named("cassandra.ssl") boolean ssl) {
checkNotNull(keyspace, "keyspace argument");
checkNotNull(hostname, "hostname argument");
checkArgument(port > 0 && port < 65535, "not a valid port number: %d", port);
checkNotNull(compression, "compression argument");
LOG.info("Setting up session with {}:{} using compression {}", hostname, port, compression.toUpperCase());
Builder builder = Cluster
.builder()
.withPort(port)
.addContactPoints(hostname.split(","))
.withReconnectionPolicy(new ExponentialReconnectionPolicy(1000, 2 * 60 * 1000))
.withCompression(Compression.valueOf(compression.toUpperCase()));
if (username != null && password != null) {
LOG.info("Using username: {} and password: XXXXXXXX", username);
builder.withCredentials(username, password);
}
if (ssl) {
LOG.info("Enabling SSL.");
builder.withSSL();
}
m_session = builder.build().connect(keyspace);
}
示例4: populateCredentials
import com.datastax.driver.core.Cluster.Builder; //导入方法依赖的package包/类
private Builder populateCredentials(Map<String, String> properties, Builder builder) {
String usernameProp = properties.get(DBConstants.Cassandra.USERNAME);
String passwordProp = properties.get(DBConstants.Cassandra.PASSWORD);
if (usernameProp != null) {
builder = builder.withCredentials(usernameProp, passwordProp);
}
return builder;
}
示例5: 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());
}
}
示例6: create
import com.datastax.driver.core.Cluster.Builder; //导入方法依赖的package包/类
@Override
public Cluster create(CassandraServiceInfo serviceInfo,
ServiceConnectorConfig serviceConnectorConfig) {
Builder builder = Cluster.builder()
.addContactPoints(serviceInfo.getContactPoints().toArray(new String[0]))
.withPort(serviceInfo.getPort());
if (StringUtils.hasText(serviceInfo.getUsername())) {
builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword());
}
if (serviceConnectorConfig instanceof CassandraClusterConfig) {
CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig;
if (config.getCompression() != null) {
builder.withCompression(config.getCompression());
}
builder.withPoolingOptions(config.getPoolingOptions());
builder.withSocketOptions(config.getSocketOptions());
builder.withQueryOptions(config.getQueryOptions());
builder.withNettyOptions(config.getNettyOptions());
builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy());
builder.withReconnectionPolicy(config.getReconnectionPolicy());
builder.withRetryPolicy(config.getRetryPolicy());
builder.withProtocolVersion(config.getProtocolVersion());
if (!config.isMetricsEnabled()) {
builder.withoutMetrics();
}
if (!config.isJmxReportingEnabled()) {
builder.withoutJMXReporting();
}
}
return builder.build();
}
示例7: create
import com.datastax.driver.core.Cluster.Builder; //导入方法依赖的package包/类
@Override
public DataContext create(DataContextProperties properties, ResourceFactoryRegistry resourceFactoryRegistry)
throws UnsupportedDataContextPropertiesException, ConnectionException {
final Map<String, Object> map = properties.toMap();
final Builder clusterBuilder = Cluster.builder();
final String hostname = properties.getHostname();
if (!Strings.isNullOrEmpty(hostname)) {
clusterBuilder.addContactPoints(hostname.split(","));
}
if (properties.getPort() != null) {
clusterBuilder.withPort(properties.getPort());
}
if (map.containsKey("cluster-name")) {
clusterBuilder.withClusterName((String) map.get("cluster-name"));
}
if (properties.getUsername() != null && properties.getPassword() != null) {
clusterBuilder.withCredentials(properties.getUsername(), properties.getPassword());
}
final Cluster cluster = clusterBuilder.build();
final String keySpace = getString(map.get("keyspace"), properties.getDatabaseName());
return new CassandraDataContext(cluster, keySpace, properties.getTableDefs());
}
示例8: testStarted
import com.datastax.driver.core.Cluster.Builder; //导入方法依赖的package包/类
@Override
public void testStarted() {
Builder builder = Cluster.builder().withClusterName(clusterId).addContactPoint(contactPoint);
if (StringUtils.isNotBlank(user)) {
builder = builder.withCredentials(user, password);
}
builder = builder.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(consistency)));
ClusterHolder.putBuilder(getClusterId(), builder);
}
示例9: init
import com.datastax.driver.core.Cluster.Builder; //导入方法依赖的package包/类
/**
* 描述: 初始化配置
* 时间: 2017年11月15日 上午11:25:07
* @author yi.zhang
* @param servers 服务地址
* @param keyspace 命名空间
* @param username 账号
* @param password 密码
*/
public void init(String servers,String keyspace,String username,String password) {
try {
// socket 链接配置
SocketOptions socket = new SocketOptions();
socket.setKeepAlive(true);
socket.setReceiveBufferSize(1024* 1024);
socket.setSendBufferSize(1024* 1024);
socket.setConnectTimeoutMillis(5 * 1000);
socket.setReadTimeoutMillis(1000);
//设置连接池
PoolingOptions pool = new PoolingOptions();
// pool.setMaxRequestsPerConnection(HostDistance.LOCAL, 32);
// pool.setMaxRequestsPerConnection(HostDistance.REMOTE, 32);
// pool.setCoreConnectionsPerHost(HostDistance.LOCAL, 2);
// pool.setCoreConnectionsPerHost(HostDistance.REMOTE, 2);
// pool.setMaxConnectionsPerHost(HostDistance.LOCAL, 4);
// pool.setMaxConnectionsPerHost(HostDistance.REMOTE, 4);
pool.setHeartbeatIntervalSeconds(60);
pool.setIdleTimeoutSeconds(120);
pool.setPoolTimeoutMillis(5 * 1000);
List<InetSocketAddress> saddress = new ArrayList<InetSocketAddress>();
if (servers != null && !"".equals(servers)) {
for (String server : servers.split(",")) {
String[] address = server.split(":");
String ip = address[0];
int port = 9042;
if (address != null && address.length > 1) {
port = Integer.valueOf(address[1]);
}
saddress.add(new InetSocketAddress(ip, port));
}
}
InetSocketAddress[] addresses = new InetSocketAddress[saddress.size()];
saddress.toArray(addresses);
Builder builder = Cluster.builder();
builder.withSocketOptions(socket);
// 设置压缩方式
builder.withCompression(ProtocolOptions.Compression.LZ4);
// 负载策略
// DCAwareRoundRobinPolicy loadBalance = DCAwareRoundRobinPolicy.builder().withLocalDc("localDc").withUsedHostsPerRemoteDc(2).allowRemoteDCsForLocalConsistencyLevel().build();
// builder.withLoadBalancingPolicy(loadBalance);
// 重试策略
builder.withRetryPolicy(DefaultRetryPolicy.INSTANCE);
builder.withPoolingOptions(pool);
builder.addContactPointsWithPorts(addresses);
builder.withCredentials(username, password);
Cluster cluster = builder.build();
if (keyspace != null && !"".equals(keyspace)) {
session = cluster.connect(keyspace);
} else {
session = cluster.connect();
}
mapping = new MappingManager(session);
} catch (Exception e) {
logger.error("-----Cassandra Config init Error-----", e);
}
}
示例10: 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;
}