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


Java SocketOptions类代码示例

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


SocketOptions类属于com.datastax.driver.core包,在下文中一共展示了SocketOptions类的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);
    }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:25,代码来源:CassandraSocketOptions.java

示例2: CassandraConfigDb

import com.datastax.driver.core.SocketOptions; //导入依赖的package包/类
public CassandraConfigDb(List<String> contactPoints, int port) {
	
	this.contactPoints = new ArrayList<InetAddress> (contactPoints.size());
	
	for (String contactPoint : contactPoints) {
		try {
			this.contactPoints.add(InetAddress.getByName(contactPoint));
		} catch (UnknownHostException e) {
               throw new IllegalArgumentException(e.getMessage());
		}
	}
	
	this.port = port;
	
	cluster = (new Cluster.Builder()).withPort (this.port)
			.addContactPoints(this.contactPoints)
			.withSocketOptions(new SocketOptions().setReadTimeoutMillis(60000).setKeepAlive(true).setReuseAddress(true))
			.withLoadBalancingPolicy(new RoundRobinPolicy())
			.withReconnectionPolicy(new ConstantReconnectionPolicy(500L))
			.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.ONE))
			.build ();
	
	session = cluster.newSession();
	preparedStatements = new ConcurrentHashMap<StatementName, PreparedStatement> ();
	prepareStatementCreateLock = new Object();
}
 
开发者ID:att,项目名称:dmaap-framework,代码行数:27,代码来源:CassandraConfigDb.java

示例3: createSession

import com.datastax.driver.core.SocketOptions; //导入依赖的package包/类
static Session createSession() throws Exception {
    Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1")
            // long read timeout is sometimes needed on slow travis ci machines
            .withSocketOptions(new SocketOptions().setReadTimeoutMillis(30000))
            .withQueryOptions(getQueryOptions())
            .build();
    Session session = cluster.connect();
    session.execute("CREATE KEYSPACE IF NOT EXISTS test WITH REPLICATION ="
            + " { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }");
    session.execute("CREATE TABLE IF NOT EXISTS test.users"
            + " (id int PRIMARY KEY, fname text, lname text)");
    try {
        session.execute("TRUNCATE test.users");
    } catch (NoHostAvailableException e) {
        // sometimes slow, so give it a second chance
        session.execute("TRUNCATE test.users");
    }
    for (int i = 0; i < 10; i++) {
        session.execute("INSERT INTO test.users (id, fname, lname) VALUES (" + i + ", 'f" + i
                + "', 'l" + i + "')");
    }
    return session;
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:24,代码来源:Sessions.java

示例4: 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;
}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:28,代码来源:SessionManager.java

示例5: 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();
}
 
开发者ID:apache,项目名称:beam,代码行数:16,代码来源:HIFIOWithEmbeddedCassandraTest.java

示例6: getInputCluster

import com.datastax.driver.core.SocketOptions; //导入依赖的package包/类
public static Cluster getInputCluster(String[] hosts, Configuration conf)
{
    int port = getInputNativePort(conf);
    Optional<AuthProvider> authProvider = getAuthProvider(conf);
    Optional<SSLOptions> sslOptions = getSSLOptions(conf);
    Optional<Integer> protocolVersion = getProtocolVersion(conf);
    LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(conf, hosts);
    SocketOptions socketOptions = getReadSocketOptions(conf);
    QueryOptions queryOptions = getReadQueryOptions(conf);
    PoolingOptions poolingOptions = getReadPoolingOptions(conf);
    
    Cluster.Builder builder = Cluster.builder()
                                     .addContactPoints(hosts)
                                     .withPort(port)
                                     .withCompression(ProtocolOptions.Compression.NONE);

    if (authProvider.isPresent())
        builder.withAuthProvider(authProvider.get());
    if (sslOptions.isPresent())
        builder.withSSL(sslOptions.get());

    if (protocolVersion.isPresent()) {
        builder.withProtocolVersion(protocolVersion.get());
    }
    builder.withLoadBalancingPolicy(loadBalancingPolicy)
           .withSocketOptions(socketOptions)
           .withQueryOptions(queryOptions)
           .withPoolingOptions(poolingOptions);

    return builder.build();
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:32,代码来源:CqlConfigHelper.java

示例7: 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;
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:32,代码来源:CqlConfigHelper.java

示例8: CassandraConn

import com.datastax.driver.core.SocketOptions; //导入依赖的package包/类
public CassandraConn(String node, String keyspace, String username, String password) {
   
  PoolingOptions pools = new PoolingOptions();
     pools.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, maxRequestPerConnection);
     pools.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, minRequestPerConnection);
     pools.setCoreConnectionsPerHost(HostDistance.LOCAL, coreConnectionLocalPerHost);
     pools.setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnectionLocalPerHost);
     pools.setCoreConnectionsPerHost(HostDistance.REMOTE, coreConnectionRemotePerHost);
     pools.setMaxConnectionsPerHost(HostDistance.REMOTE, maxConnectionRemotePerHost);

       
     cluster = Cluster.builder()
           .addContactPoint(node)
           .withPoolingOptions(pools)
.withCredentials(username, password)
              .withSocketOptions(new SocketOptions().setTcpNoDelay(true))
              .build();
     
     Metadata metadata = cluster.getMetadata();
     System.out.printf("Connected to cluster: %s\n", 
           metadata.getClusterName());
     for ( Host host : metadata.getAllHosts() ) {
        System.out.printf("Datatacenter: %s; Host: %s; Rack: %s\n",
              host.getDatacenter(), host.getAddress(), host.getRack());
     }
     session = cluster.connect(keyspace);
  }
 
开发者ID:bailoo,项目名称:Agamemnon,代码行数:28,代码来源:CassandraConn.java

示例9: construct

import com.datastax.driver.core.SocketOptions; //导入依赖的package包/类
public AsyncFuture<Connection> construct() {
    AsyncFuture<Session> session = async.call(() -> {
        // @formatter:off
        final PoolingOptions pooling = new PoolingOptions();

        final QueryOptions queryOptions = new QueryOptions()
            .setFetchSize(fetchSize)
            .setConsistencyLevel(consistencyLevel);

        final SocketOptions socketOptions = new SocketOptions()
            .setReadTimeoutMillis((int) readTimeout.toMilliseconds());

        final Cluster.Builder cluster = Cluster.builder()
            .addContactPointsWithPorts(seeds)
            .withRetryPolicy(retryPolicy)
            .withPoolingOptions(pooling)
            .withQueryOptions(queryOptions)
            .withSocketOptions(socketOptions)
            .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
        // @formatter:on

        authentication.accept(cluster);
        return cluster.build().connect();
    });

    if (configure) {
        session = session.lazyTransform(s -> {
            return schema.configure(s).directTransform(i -> s);
        });
    }

    return session.lazyTransform(s -> {
        return schema.instance(s).directTransform(schema -> {
            return new Connection(s, schema);
        });
    });
}
 
开发者ID:spotify,项目名称:heroic,代码行数:38,代码来源:ManagedSetupConnection.java

示例10: 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);
}
 
开发者ID:hpcc-systems,项目名称:storm-cassandra-cql,代码行数:16,代码来源:MapConfiguredCqlClientFactory.java

示例11: cluster

import com.datastax.driver.core.SocketOptions; //导入依赖的package包/类
private Cluster cluster() {
    return Cluster.builder()
                  .addContactPoints(contactPoint).withPort(port)
                  .withCredentials(username, password)
                  .withSocketOptions(new SocketOptions().setKeepAlive(true)
                                                        .setReadTimeoutMillis(readTimeoutMillis))
                  .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder()
                                                                  .withLocalDc(localDatacenter)
                                                                  .build())
                  .build();
}
 
开发者ID:bric3,项目名称:cql-maven-plugin,代码行数:12,代码来源:CqlExecuteMojo.java

示例12: setSocketOptions

import com.datastax.driver.core.SocketOptions; //导入依赖的package包/类
/**
 * Sets socket options to use.
 *
 * @param options Socket options.
 */
@SuppressWarnings("UnusedDeclaration")
public void setSocketOptions(SocketOptions options) {
    sockOptions = options;

    invalidate();
}
 
开发者ID:apache,项目名称:ignite,代码行数:12,代码来源:DataSource.java

示例13: readExternal

import com.datastax.driver.core.SocketOptions; //导入依赖的package包/类
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    fetchSize = (Integer)in.readObject();
    readConsistency = (ConsistencyLevel)in.readObject();
    writeConsistency = (ConsistencyLevel)in.readObject();
    user = U.readString(in);
    pwd = U.readString(in);
    port = (Integer)in.readObject();
    contactPoints = (List<InetAddress>)in.readObject();
    contactPointsWithPorts = (List<InetSocketAddress>)in.readObject();
    maxSchemaAgreementWaitSeconds = (Integer)in.readObject();
    protoVer = (Integer)in.readObject();
    compression = U.readString(in);
    useSSL = (Boolean)in.readObject();
    collectMetrix = (Boolean)in.readObject();
    jmxReporting = (Boolean)in.readObject();
    creds = (Credentials)in.readObject();
    loadBalancingPlc = (LoadBalancingPolicy)readObject(in);
    reconnectionPlc = (ReconnectionPolicy)readObject(in);
    addrTranslator = (AddressTranslator)readObject(in);
    speculativeExecutionPlc = (SpeculativeExecutionPolicy)readObject(in);
    authProvider = (AuthProvider)readObject(in);
    sslOptions = (SSLOptions)readObject(in);
    poolingOptions = (PoolingOptions)readObject(in);
    sockOptions = (SocketOptions)readObject(in);
    nettyOptions = (NettyOptions)readObject(in);
}
 
开发者ID:apache,项目名称:ignite,代码行数:29,代码来源:DataSource.java

示例14: getCluster

import com.datastax.driver.core.SocketOptions; //导入依赖的package包/类
public static Cluster getCluster(String[] hosts, Configuration conf, int port)
{
    Optional<AuthProvider> authProvider = getAuthProvider(conf);
    Optional<SSLOptions> sslOptions = getSSLOptions(conf);
    Optional<Integer> protocolVersion = getProtocolVersion(conf);
    LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(hosts);
    SocketOptions socketOptions = getReadSocketOptions(conf);
    QueryOptions queryOptions = getReadQueryOptions(conf);
    PoolingOptions poolingOptions = getReadPoolingOptions(conf);

    Cluster.Builder builder = Cluster.builder()
            .addContactPoints(hosts)
            .withPort(port)
            .withCompression(ProtocolOptions.Compression.NONE);

    if (authProvider.isPresent())
        builder.withAuthProvider(authProvider.get());
    if (sslOptions.isPresent())
        builder.withSSL(sslOptions.get());

    if (protocolVersion.isPresent()) {
        builder.withProtocolVersion(ProtocolVersion.fromInt(protocolVersion.get()));
    }
    builder.withLoadBalancingPolicy(loadBalancingPolicy)
            .withSocketOptions(socketOptions)
            .withQueryOptions(queryOptions)
            .withPoolingOptions(poolingOptions);

    return builder.build();
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:31,代码来源:CqlConfigHelper.java

示例15: getInputCluster

import com.datastax.driver.core.SocketOptions; //导入依赖的package包/类
public static Cluster getInputCluster(String[] hosts, Configuration conf)
{
    int port = getInputNativePort(conf);
    Optional<AuthProvider> authProvider = getAuthProvider(conf);
    Optional<SSLOptions> sslOptions = getSSLOptions(conf);
    LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(conf, hosts);
    SocketOptions socketOptions = getReadSocketOptions(conf);
    QueryOptions queryOptions = getReadQueryOptions(conf);
    PoolingOptions poolingOptions = getReadPoolingOptions(conf);
    
    Cluster.Builder builder = Cluster.builder()
                                     .addContactPoints(hosts)
                                     .withPort(port)
                                     .withCompression(ProtocolOptions.Compression.NONE);

    if (authProvider.isPresent())
        builder.withAuthProvider(authProvider.get());
    if (sslOptions.isPresent())
        builder.withSSL(sslOptions.get());

    builder.withLoadBalancingPolicy(loadBalancingPolicy)
           .withSocketOptions(socketOptions)
           .withQueryOptions(queryOptions)
           .withPoolingOptions(poolingOptions);

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


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