本文整理汇总了Java中com.datastax.driver.core.SocketOptions.setReadTimeoutMillis方法的典型用法代码示例。如果您正苦于以下问题:Java SocketOptions.setReadTimeoutMillis方法的具体用法?Java SocketOptions.setReadTimeoutMillis怎么用?Java SocketOptions.setReadTimeoutMillis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.datastax.driver.core.SocketOptions
的用法示例。
在下文中一共展示了SocketOptions.setReadTimeoutMillis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initOpts
import com.datastax.driver.core.SocketOptions; //导入方法依赖的package包/类
@PostConstruct
public void initOpts() {
opts = new SocketOptions();
opts.setConnectTimeoutMillis(connectTimeoutMillis);
opts.setReadTimeoutMillis(readTimeoutMillis);
if (keepAlive != null) {
opts.setKeepAlive(keepAlive);
}
if (reuseAddress != null) {
opts.setReuseAddress(reuseAddress);
}
if (soLinger != null) {
opts.setSoLinger(soLinger);
}
if (tcpNoDelay != null) {
opts.setTcpNoDelay(tcpNoDelay);
}
if (receiveBufferSize != null) {
opts.setReceiveBufferSize(receiveBufferSize);
}
if (sendBufferSize != null) {
opts.setSendBufferSize(sendBufferSize);
}
}
示例2: getCluster
import com.datastax.driver.core.SocketOptions; //导入方法依赖的package包/类
private static Cluster getCluster(){
if(cluster==null){
synchronized (SessionManager.class) {
if(cluster==null){
PoolingOptions poolingOptions = new PoolingOptions();
poolingOptions
.setMaxRequestsPerConnection(HostDistance.REMOTE, max)
.setMaxRequestsPerConnection(HostDistance.LOCAL,max)
.setMaxQueueSize(max*10)
.setCoreConnectionsPerHost(HostDistance.LOCAL, 1)
.setMaxConnectionsPerHost( HostDistance.LOCAL, 2)
.setCoreConnectionsPerHost(HostDistance.REMOTE, 1)
.setMaxConnectionsPerHost( HostDistance.REMOTE, 2);
SocketOptions socketOptions = new SocketOptions();
socketOptions.setConnectTimeoutMillis(60000);
socketOptions.setReadTimeoutMillis(60000);
cluster = Cluster.builder().addContactPoint(url).withPoolingOptions(poolingOptions).withSocketOptions(socketOptions).build();
Metadata metadata = cluster.getMetadata();
Set<Host> allHosts = metadata.getAllHosts();
for(Host host:allHosts){
System.out.println("host:"+host.getAddress());
}
}
}
}
return cluster;
}
示例3: startCassandra
import com.datastax.driver.core.SocketOptions; //导入方法依赖的package包/类
@BeforeClass
public static void startCassandra() throws Exception {
//Start the Embedded Cassandra Service
cassandra.start();
final SocketOptions socketOptions = new SocketOptions();
// Setting this to 0 disables read timeouts.
socketOptions.setReadTimeoutMillis(0);
// This defaults to 5 s. Increase to a minute.
socketOptions.setConnectTimeoutMillis(60 * 1000);
cluster =
Cluster.builder().addContactPoint(CASSANDRA_HOST).withClusterName("beam")
.withSocketOptions(socketOptions).build();
session = cluster.connect();
createCassandraData();
}
示例4: getReadSocketOptions
import com.datastax.driver.core.SocketOptions; //导入方法依赖的package包/类
private static SocketOptions getReadSocketOptions(Configuration conf)
{
SocketOptions socketOptions = new SocketOptions();
Optional<Integer> connectTimeoutMillis = getInputNativeConnectionTimeout(conf);
Optional<Integer> readTimeoutMillis = getInputNativeReadConnectionTimeout(conf);
Optional<Integer> receiveBufferSize = getInputNativeReceiveBufferSize(conf);
Optional<Integer> sendBufferSize = getInputNativeSendBufferSize(conf);
Optional<Integer> soLinger = getInputNativeSolinger(conf);
Optional<Boolean> tcpNoDelay = getInputNativeTcpNodelay(conf);
Optional<Boolean> reuseAddress = getInputNativeReuseAddress(conf);
Optional<Boolean> keepAlive = getInputNativeKeepAlive(conf);
if (connectTimeoutMillis.isPresent())
socketOptions.setConnectTimeoutMillis(connectTimeoutMillis.get());
if (readTimeoutMillis.isPresent())
socketOptions.setReadTimeoutMillis(readTimeoutMillis.get());
if (receiveBufferSize.isPresent())
socketOptions.setReceiveBufferSize(receiveBufferSize.get());
if (sendBufferSize.isPresent())
socketOptions.setSendBufferSize(sendBufferSize.get());
if (soLinger.isPresent())
socketOptions.setSoLinger(soLinger.get());
if (tcpNoDelay.isPresent())
socketOptions.setTcpNoDelay(tcpNoDelay.get());
if (reuseAddress.isPresent())
socketOptions.setReuseAddress(reuseAddress.get());
if (keepAlive.isPresent())
socketOptions.setKeepAlive(keepAlive.get());
return socketOptions;
}
示例5: configureSocketOpts
import com.datastax.driver.core.SocketOptions; //导入方法依赖的package包/类
private void configureSocketOpts() {
final String readTimeoutConfiguration = (String) configuration.get(TRIDENT_CASSANDRA_READ_TIMEOUT);
final String connectTimeoutConfiguration = (String) configuration.get(TRIDENT_CASSANDRA_CONNECT_TIMEOUT);
final SocketOptions socketOptions = builder.getConfiguration().getSocketOptions();
if (StringUtils.isNotEmpty(readTimeoutConfiguration)) {
socketOptions.setReadTimeoutMillis(Integer.parseInt(readTimeoutConfiguration));
}
if (StringUtils.isNotEmpty(connectTimeoutConfiguration)) {
socketOptions.setConnectTimeoutMillis(Integer.parseInt(connectTimeoutConfiguration));
}
builder = builder.withSocketOptions(socketOptions);
}
示例6: populateSocketOptions
import com.datastax.driver.core.SocketOptions; //导入方法依赖的package包/类
private Cluster.Builder populateSocketOptions(Properties properties, Cluster.Builder builder) {
String connectionTimeoutMillisProp = properties.getProperty(CassandraStoreParameters.CONNECTION_TIMEOUT_MILLIS);
String keepAliveProp = properties.getProperty(CassandraStoreParameters.KEEP_ALIVE);
String readTimeoutMillisProp = properties.getProperty(CassandraStoreParameters.READ_TIMEOUT_MILLIS);
String receiveBufferSizeProp = properties.getProperty(CassandraStoreParameters.RECEIVER_BUFFER_SIZE);
String reuseAddress = properties.getProperty(CassandraStoreParameters.REUSE_ADDRESS);
String sendBufferSize = properties.getProperty(CassandraStoreParameters.SEND_BUFFER_SIZE);
String soLinger = properties.getProperty(CassandraStoreParameters.SO_LINGER);
String tcpNoDelay = properties.getProperty(CassandraStoreParameters.TCP_NODELAY);
SocketOptions options = new SocketOptions();
if (connectionTimeoutMillisProp != null) {
options.setConnectTimeoutMillis(Integer.parseInt(connectionTimeoutMillisProp));
}
if (keepAliveProp != null) {
options.setKeepAlive(Boolean.parseBoolean(keepAliveProp));
}
if (readTimeoutMillisProp != null) {
options.setReadTimeoutMillis(Integer.parseInt(readTimeoutMillisProp));
}
if (receiveBufferSizeProp != null) {
options.setReceiveBufferSize(Integer.parseInt(receiveBufferSizeProp));
}
if (reuseAddress != null) {
options.setReuseAddress(Boolean.parseBoolean(reuseAddress));
}
if (sendBufferSize != null) {
options.setSendBufferSize(Integer.parseInt(sendBufferSize));
}
if (soLinger != null) {
options.setSoLinger(Integer.parseInt(soLinger));
}
if (tcpNoDelay != null) {
options.setTcpNoDelay(Boolean.parseBoolean(tcpNoDelay));
}
return builder.withSocketOptions(options);
}
示例7: populateSocketOptions
import com.datastax.driver.core.SocketOptions; //导入方法依赖的package包/类
private Builder populateSocketOptions(Map<String, String> properties, Builder builder) throws DataServiceFault {
String connectionTimeoutMillisProp = properties.get(DBConstants.Cassandra.CONNECTION_TIMEOUT_MILLIS);
String keepAliveProp = properties.get(DBConstants.Cassandra.KEEP_ALIVE);
String readTimeoutMillisProp = properties.get(DBConstants.Cassandra.READ_TIMEOUT_MILLIS);
String receiveBufferSizeProp = properties.get(DBConstants.Cassandra.RECEIVER_BUFFER_SIZE);
String reuseAddress = properties.get(DBConstants.Cassandra.REUSE_ADDRESS);
String sendBufferSize = properties.get(DBConstants.Cassandra.SEND_BUFFER_SIZE);
String soLinger = properties.get(DBConstants.Cassandra.SO_LINGER);
String tcpNoDelay = properties.get(DBConstants.Cassandra.TCP_NODELAY);
SocketOptions options = new SocketOptions();
if (connectionTimeoutMillisProp != null) {
options.setConnectTimeoutMillis(Integer.parseInt(connectionTimeoutMillisProp));
}
if (keepAliveProp != null) {
options.setKeepAlive(Boolean.parseBoolean(keepAliveProp));
}
if (readTimeoutMillisProp != null) {
options.setReadTimeoutMillis(Integer.parseInt(readTimeoutMillisProp));
}
if (receiveBufferSizeProp != null) {
options.setReceiveBufferSize(Integer.parseInt(receiveBufferSizeProp));
}
if (reuseAddress != null) {
options.setReuseAddress(Boolean.parseBoolean(reuseAddress));
}
if (sendBufferSize != null) {
options.setSendBufferSize(Integer.parseInt(sendBufferSize));
}
if (soLinger != null) {
options.setSoLinger(Integer.parseInt(soLinger));
}
if (tcpNoDelay != null) {
options.setTcpNoDelay(Boolean.parseBoolean(tcpNoDelay));
}
return builder.withSocketOptions(options);
}
示例8: buildClusterSpecs
import com.datastax.driver.core.SocketOptions; //导入方法依赖的package包/类
private Cluster buildClusterSpecs() {
Cluster.Builder builder = Cluster.builder();
// dbhost
String dbhost = getParamString("dbhost");
String[] nodeAddresses = dbhost.split(",");
for (String address : nodeAddresses) {
builder.addContactPoint(address);
}
// dbport
builder.withPort(getParamInt("dbport", 9042));
// db_timeout_millis and db_connect_retry_wait_millis
SocketOptions socketOpts = new SocketOptions();
socketOpts.setReadTimeoutMillis(getParamInt("db_timeout_millis", 10000));
socketOpts.setConnectTimeoutMillis(getParamInt("db_connect_retry_wait_millis", 5000));
builder.withSocketOptions(socketOpts);
// dbuser/dbpassword
String dbuser = getParamString("dbuser");
if (!Utils.isEmpty(dbuser)) {
builder.withCredentials(dbuser, getParamString("dbpassword"));
}
// compression
builder.withCompression(Compression.SNAPPY);
// TLS/SSL
if (getParamBoolean("dbtls")) {
builder.withSSL(getSSLOptions());
}
return builder.build();
}
示例9: getSocketOptions
import com.datastax.driver.core.SocketOptions; //导入方法依赖的package包/类
private SocketOptions getSocketOptions(CassandraProperties properties) {
SocketOptions options = new SocketOptions();
if (nonNull(properties.getConnectTimeout())) {
options.setConnectTimeoutMillis((int) properties.getConnectTimeout().toMillis());
}
if (nonNull(properties.getConnectTimeout())) {
options.setReadTimeoutMillis((int) properties.getReadTimeout().toMillis());
}
return options;
}
示例10: getSocketOptions
import com.datastax.driver.core.SocketOptions; //导入方法依赖的package包/类
private SocketOptions getSocketOptions(CassandraProperties properties) {
SocketOptions options = new SocketOptions();
options.setConnectTimeoutMillis(properties.getConnectTimeoutMillis());
options.setReadTimeoutMillis(properties.getReadTimeoutMillis());
return options;
}
示例11: getSocketOptions
import com.datastax.driver.core.SocketOptions; //导入方法依赖的package包/类
private static SocketOptions getSocketOptions(CassandraProperties properties) {
SocketOptions options = new SocketOptions();
options.setConnectTimeoutMillis(properties.getConnectTimeoutMillis());
options.setReadTimeoutMillis(properties.getReadTimeoutMillis());
return options;
}
示例12: getSocketOptions
import com.datastax.driver.core.SocketOptions; //导入方法依赖的package包/类
private SocketOptions getSocketOptions() {
SocketOptions options = new SocketOptions();
options.setConnectTimeoutMillis(this.eventStoreConfig.getConnectTimeoutMillis());
options.setReadTimeoutMillis(this.eventStoreConfig.getReadTimeoutMillis());
return options;
}
示例13: init
import com.datastax.driver.core.SocketOptions; //导入方法依赖的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);
}
}
示例14: getSocketOptions
import com.datastax.driver.core.SocketOptions; //导入方法依赖的package包/类
private SocketOptions getSocketOptions() {
SocketOptions options = new SocketOptions();
options.setConnectTimeoutMillis(this.properties.getConnectTimeoutMillis());
options.setReadTimeoutMillis(this.properties.getReadTimeoutMillis());
return options;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:7,代码来源:CassandraAutoConfiguration.java
示例15: newCqlDriverBuilder
import com.datastax.driver.core.SocketOptions; //导入方法依赖的package包/类
private com.datastax.driver.core.Cluster.Builder newCqlDriverBuilder(ConnectionPoolConfiguration poolConfig,
MetricRegistry metricRegistry) {
performHostDiscovery(metricRegistry);
String[] seeds = _seeds.split(",");
List<String> contactPoints = Lists.newArrayListWithCapacity(seeds.length);
// Each seed may be a host name or a host name and port (e.g.; "1.2.3.4" or "1.2.3.4:9160"). These need
// to be converted into host names only.
for (String seed : seeds) {
HostAndPort hostAndPort = HostAndPort.fromString(seed);
seed = hostAndPort.getHostText();
if (hostAndPort.hasPort()) {
if (hostAndPort.getPort() == _thriftPort) {
_log.debug("Seed {} found using RPC port; swapping for native port {}", seed, _cqlPort);
} else if (hostAndPort.getPort() != _cqlPort) {
throw new IllegalArgumentException(String.format(
"Seed %s found with invalid port %s. The port must match either the RPC (thrift) port %s " +
"or the native (CQL) port %s", seed, hostAndPort.getPort(), _thriftPort, _cqlPort));
}
}
contactPoints.add(seed);
}
PoolingOptions poolingOptions = new PoolingOptions();
if (poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).isPresent()) {
poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).get());
}
if (poolConfig.getCoreConnectionsPerHost().or(getCoreConnectionsPerHost()).isPresent()) {
poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, poolConfig.getCoreConnectionsPerHost().or(getCoreConnectionsPerHost()).get());
}
SocketOptions socketOptions = new SocketOptions();
if (poolConfig.getConnectTimeout().or(getConnectTimeout()).isPresent()) {
socketOptions.setConnectTimeoutMillis(poolConfig.getConnectTimeout().or(getConnectTimeout()).get());
}
if (poolConfig.getSocketTimeout().or(getSocketTimeout()).isPresent()) {
socketOptions.setReadTimeoutMillis(poolConfig.getSocketTimeout().or(getSocketTimeout()).get());
}
AuthProvider authProvider = _authenticationCredentials != null
? new PlainTextAuthProvider(_authenticationCredentials.getUsername(), _authenticationCredentials.getPassword())
: AuthProvider.NONE;
return com.datastax.driver.core.Cluster.builder()
.addContactPoints(contactPoints.toArray(new String[contactPoints.size()]))
.withPort(_cqlPort)
.withPoolingOptions(poolingOptions)
.withSocketOptions(socketOptions)
.withRetryPolicy(Policies.defaultRetryPolicy())
.withAuthProvider(authProvider);
}