本文整理匯總了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);
}
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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);
}
示例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);
});
});
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}