當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。