本文整理汇总了Java中com.datastax.driver.core.PoolingOptions类的典型用法代码示例。如果您正苦于以下问题:Java PoolingOptions类的具体用法?Java PoolingOptions怎么用?Java PoolingOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PoolingOptions类属于com.datastax.driver.core包,在下文中一共展示了PoolingOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import com.datastax.driver.core.PoolingOptions; //导入依赖的package包/类
static Session connect() {
String contactPoint = "localhost";
String keySpace = "ks1";
if(session == null) {
PoolingOptions poolingOptions = new PoolingOptions().setConnectionsPerHost(HostDistance.REMOTE, 1, 4);
cluster = Cluster.builder().addContactPoint(contactPoint).withPoolingOptions(poolingOptions)
.withCompression(Compression.SNAPPY).build();
cluster.init();
for (Host host : cluster.getMetadata().getAllHosts()) {
System.out.printf("Address: %s, Rack: %s, Datacenter: %s, Tokens: %s\n", host.getAddress(),
host.getDatacenter(), host.getRack(), host.getTokens());
}
session = cluster.connect(keySpace);
}
return session;
}
示例2: buildCluster
import com.datastax.driver.core.PoolingOptions; //导入依赖的package包/类
static Cluster buildCluster(Cassandra3Storage cassandra) {
Cluster.Builder builder = Cluster.builder();
List<InetSocketAddress> contactPoints = parseContactPoints(cassandra);
int defaultPort = findConnectPort(contactPoints);
builder.addContactPointsWithPorts(contactPoints);
builder.withPort(defaultPort); // This ends up protocolOptions.port
if (cassandra.username != null && cassandra.password != null) {
builder.withCredentials(cassandra.username, cassandra.password);
}
builder.withRetryPolicy(ZipkinRetryPolicy.INSTANCE);
builder.withLoadBalancingPolicy(new TokenAwarePolicy(new LatencyAwarePolicy.Builder(
cassandra.localDc != null
? DCAwareRoundRobinPolicy.builder().withLocalDc(cassandra.localDc).build()
: new RoundRobinPolicy()
// This can select remote, but LatencyAwarePolicy will prefer local
).build()));
builder.withPoolingOptions(new PoolingOptions().setMaxConnectionsPerHost(
HostDistance.LOCAL, cassandra.maxConnections
));
return builder.build();
}
示例3: buildCluster
import com.datastax.driver.core.PoolingOptions; //导入依赖的package包/类
static Cluster buildCluster(CassandraStorage cassandra) {
Cluster.Builder builder = Cluster.builder();
List<InetSocketAddress> contactPoints = parseContactPoints(cassandra);
int defaultPort = findConnectPort(contactPoints);
builder.addContactPointsWithPorts(contactPoints);
builder.withPort(defaultPort); // This ends up protocolOptions.port
if (cassandra.username != null && cassandra.password != null) {
builder.withCredentials(cassandra.username, cassandra.password);
}
builder.withRetryPolicy(ZipkinRetryPolicy.INSTANCE);
builder.withLoadBalancingPolicy(new TokenAwarePolicy(new LatencyAwarePolicy.Builder(
cassandra.localDc != null
? DCAwareRoundRobinPolicy.builder().withLocalDc(cassandra.localDc).build()
: new RoundRobinPolicy()
// This can select remote, but LatencyAwarePolicy will prefer local
).build()));
builder.withPoolingOptions(new PoolingOptions().setMaxConnectionsPerHost(
HostDistance.LOCAL, cassandra.maxConnections
));
return builder.build();
}
示例4: connectToMultipleAddresses
import com.datastax.driver.core.PoolingOptions; //导入依赖的package包/类
private void connectToMultipleAddresses(String address) {
PoolingOptions poolingOptions =
new PoolingOptions()
.setConnectionsPerHost(HostDistance.LOCAL, 4, 10)
.setConnectionsPerHost(HostDistance.REMOTE, 2, 4);
String[] music_hosts = address.split(",");
if (cluster == null) {
logger.debug("Initializing MUSIC Client with endpoints "+address);
cluster = Cluster.builder()
.withPort(9042)
.withPoolingOptions(poolingOptions)
.withoutMetrics()
.addContactPoints(music_hosts)
.build();
Metadata metadata = cluster.getMetadata();
logger.debug("Connected to cluster:"+metadata.getClusterName()+" at address:"+address);
}
session = cluster.connect();
}
示例5: connectToCassaCluster
import com.datastax.driver.core.PoolingOptions; //导入依赖的package包/类
@SuppressWarnings("unused")
private void connectToCassaCluster(String address) {
PoolingOptions poolingOptions =
new PoolingOptions()
.setConnectionsPerHost(HostDistance.LOCAL, 4, 10)
.setConnectionsPerHost(HostDistance.REMOTE, 2, 4);
Iterator<String> it = getAllPossibleLocalIps().iterator();
logger.debug("Iterating through possible ips:"+getAllPossibleLocalIps());
while (it.hasNext()) {
try {
cluster = Cluster.builder()
.withPort(9042)
.withPoolingOptions(poolingOptions)
.withoutMetrics()
.addContactPoint(address)
.build();
//cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(Integer.MAX_VALUE);
Metadata metadata = cluster.getMetadata();
logger.debug("Connected to cluster:"+metadata.getClusterName()+" at address:"+address);
session = cluster.connect();
break;
} catch (NoHostAvailableException e) {
address = it.next();
}
}
}
示例6: overridePoolingOptions
import com.datastax.driver.core.PoolingOptions; //导入依赖的package包/类
private static void overridePoolingOptions(CassandraFactory cassandraFactory) {
PoolingOptionsFactory newPoolingOptionsFactory = new PoolingOptionsFactory() {
@Override
public PoolingOptions build() {
if (null == getPoolTimeout()) {
setPoolTimeout(Duration.minutes(2));
}
return super.build().setMaxQueueSize(40960);
}
};
cassandraFactory.getPoolingOptions().ifPresent((originalPoolingOptions) -> {
newPoolingOptionsFactory.setHeartbeatInterval(originalPoolingOptions.getHeartbeatInterval());
newPoolingOptionsFactory.setIdleTimeout(originalPoolingOptions.getIdleTimeout());
newPoolingOptionsFactory.setLocal(originalPoolingOptions.getLocal());
newPoolingOptionsFactory.setRemote(originalPoolingOptions.getRemote());
newPoolingOptionsFactory.setPoolTimeout(originalPoolingOptions.getPoolTimeout());
});
cassandraFactory.setPoolingOptions(java.util.Optional.of(newPoolingOptionsFactory));
}
示例7: getReadPoolingOptions
import com.datastax.driver.core.PoolingOptions; //导入依赖的package包/类
private static PoolingOptions getReadPoolingOptions(Configuration conf)
{
Optional<Integer> coreConnections = getInputCoreConnections(conf);
Optional<Integer> maxConnections = getInputMaxConnections(conf);
Optional<Integer> maxSimultaneousRequests = getInputMaxSimultReqPerConnections(conf);
Optional<Integer> minSimultaneousRequests = getInputMinSimultReqPerConnections(conf);
PoolingOptions poolingOptions = new PoolingOptions();
for (HostDistance hostDistance : Arrays.asList(HostDistance.LOCAL, HostDistance.REMOTE))
{
if (coreConnections.isPresent())
poolingOptions.setCoreConnectionsPerHost(hostDistance, coreConnections.get());
if (maxConnections.isPresent())
poolingOptions.setMaxConnectionsPerHost(hostDistance, maxConnections.get());
if (minSimultaneousRequests.isPresent())
poolingOptions.setMinSimultaneousRequestsPerConnectionThreshold(hostDistance, minSimultaneousRequests.get());
if (maxSimultaneousRequests.isPresent())
poolingOptions.setMaxSimultaneousRequestsPerConnectionThreshold(hostDistance, maxSimultaneousRequests.get());
}
return poolingOptions;
}
示例8: setup
import com.datastax.driver.core.PoolingOptions; //导入依赖的package包/类
private void setup()
throws IOException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException,
CertificateException, UnrecoverableKeyException {
// Connect to Cassandra
PoolingOptions pOpts = new PoolingOptions();
pOpts.setCoreConnectionsPerHost(HostDistance.LOCAL, 4);
pOpts.setMaxConnectionsPerHost(HostDistance.LOCAL, 4);
Cluster.Builder clusterBuilder = Cluster.builder()
.addContactPoint(host)
.withPort(port)
.withPoolingOptions(pOpts)
.withLoadBalancingPolicy(new TokenAwarePolicy( DCAwareRoundRobinPolicy.builder().build()));
if (null != username)
clusterBuilder = clusterBuilder.withCredentials(username, password);
if (null != truststorePath)
clusterBuilder = clusterBuilder.withSSL(createSSLOptions());
cluster = clusterBuilder.build();
if (null == cluster) {
throw new IOException("Could not create cluster");
}
session = cluster.connect();
}
示例9: copyPoolingOptions
import com.datastax.driver.core.PoolingOptions; //导入依赖的package包/类
private void copyPoolingOptions(Builder builder) {
PoolingOptions opts = new PoolingOptions();
opts.setCoreConnectionsPerHost(HostDistance.REMOTE,
remoteCoreConnectionsPerHost);
opts.setCoreConnectionsPerHost(HostDistance.LOCAL,
localCoreConnectionsPerHost);
opts.setMaxConnectionsPerHost(HostDistance.REMOTE,
remoteMaxConnectionsPerHost);
opts.setMaxConnectionsPerHost(HostDistance.LOCAL,
localMaxConnectionsPerHost);
opts.setMaxSimultaneousRequestsPerConnectionThreshold(
HostDistance.REMOTE,
remoteMaxSimultaneousRequestsPerConnectionThreshold);
opts.setMaxSimultaneousRequestsPerConnectionThreshold(
HostDistance.LOCAL,
localMaxSimultaneousRequestsPerConnectionThreshold);
opts.setMinSimultaneousRequestsPerConnectionThreshold(
HostDistance.REMOTE,
remoteMinSimultaneousRequestsPerConnectionThreshold);
opts.setMinSimultaneousRequestsPerConnectionThreshold(
HostDistance.LOCAL,
localMinSimultaneousRequestsPerConnectionThreshold);
builder.withPoolingOptions(opts);
}
示例10: getReadPoolingOptions
import com.datastax.driver.core.PoolingOptions; //导入依赖的package包/类
private static PoolingOptions getReadPoolingOptions(Configuration conf)
{
Optional<Integer> coreConnections = getInputCoreConnections(conf);
Optional<Integer> maxConnections = getInputMaxConnections(conf);
Optional<Integer> maxSimultaneousRequests = getInputMaxSimultReqPerConnections(conf);
PoolingOptions poolingOptions = new PoolingOptions();
for (HostDistance hostDistance : Arrays.asList(HostDistance.LOCAL, HostDistance.REMOTE))
{
if (coreConnections.isPresent())
poolingOptions.setCoreConnectionsPerHost(hostDistance, coreConnections.get());
if (maxConnections.isPresent())
poolingOptions.setMaxConnectionsPerHost(hostDistance, maxConnections.get());
if (maxSimultaneousRequests.isPresent())
poolingOptions.setNewConnectionThreshold(hostDistance, maxSimultaneousRequests.get());
}
return poolingOptions;
}
示例11: build
import com.datastax.driver.core.PoolingOptions; //导入依赖的package包/类
public PoolingOptions build() {
PoolingOptions poolingOptions = new PoolingOptions();
if (local != null) {
setPoolingOptions(poolingOptions, HostDistance.LOCAL, local);
}
if (remote != null) {
setPoolingOptions(poolingOptions, HostDistance.REMOTE, remote);
}
if (heartbeatInterval != null) {
poolingOptions.setHeartbeatIntervalSeconds((int) heartbeatInterval.toSeconds());
}
if (poolTimeout != null) {
poolingOptions.setPoolTimeoutMillis((int) poolTimeout.toMilliseconds());
}
if (idleTimeout != null) {
poolingOptions.setIdleTimeoutSeconds((int) idleTimeout.toSeconds());
}
return poolingOptions;
}
示例12: buildsPoolingOptionsWithConfiguredValues
import com.datastax.driver.core.PoolingOptions; //导入依赖的package包/类
@Test
public void buildsPoolingOptionsWithConfiguredValues() throws Exception {
// given
final PoolingOptionsFactory factory = new PoolingOptionsFactory();
factory.setHeartbeatInterval(Duration.minutes(1));
factory.setPoolTimeout(Duration.seconds(2));
factory.setLocal(createHostDistanceOptions(1, 3, 5, 25));
factory.setRemote(createHostDistanceOptions(2, 4, 6, 30));
// when
final PoolingOptions poolingOptions = factory.build();
// then
assertThat(poolingOptions.getHeartbeatIntervalSeconds()).isEqualTo(60);
assertThat(poolingOptions.getPoolTimeoutMillis()).isEqualTo(2000);
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(1);
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(3);
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.LOCAL)).isEqualTo(5);
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.LOCAL)).isEqualTo(25);
assertThat(poolingOptions.getCoreConnectionsPerHost(HostDistance.REMOTE)).isEqualTo(2);
assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.REMOTE)).isEqualTo(4);
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.REMOTE)).isEqualTo(6);
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.REMOTE)).isEqualTo(30);
}
示例13: createCluster
import com.datastax.driver.core.PoolingOptions; //导入依赖的package包/类
private static Cluster createCluster(CentralConfiguration centralConfig,
TimestampGenerator defaultTimestampGenerator) {
Cluster.Builder builder = Cluster.builder()
.addContactPoints(
centralConfig.cassandraContactPoint().toArray(new String[0]))
// aggressive reconnect policy seems ok since not many clients
.withReconnectionPolicy(new ConstantReconnectionPolicy(1000))
// let driver know that only idempotent queries are used so it will retry on timeout
.withQueryOptions(new QueryOptions()
.setDefaultIdempotence(true)
.setConsistencyLevel(centralConfig.cassandraConsistencyLevel()))
// central runs lots of parallel async queries and is very spiky since all
// aggregates come in right after each minute marker
.withPoolingOptions(
new PoolingOptions().setMaxQueueSize(Session.MAX_CONCURRENT_QUERIES))
.withTimestampGenerator(defaultTimestampGenerator);
String cassandraUsername = centralConfig.cassandraUsername();
if (!cassandraUsername.isEmpty()) {
// empty password is strange but valid
builder.withCredentials(cassandraUsername, centralConfig.cassandraPassword());
}
return builder.build();
}
示例14: getReadPoolingOptions
import com.datastax.driver.core.PoolingOptions; //导入依赖的package包/类
private static PoolingOptions getReadPoolingOptions(Configuration conf)
{
Optional<Integer> coreConnections = getInputCoreConnections(conf);
Optional<Integer> maxConnections = getInputMaxConnections(conf);
Optional<Integer> maxSimultaneousRequests = getInputMaxSimultReqPerConnections(conf);
Optional<Integer> minSimultaneousRequests = getInputMinSimultReqPerConnections(conf);
PoolingOptions poolingOptions = new PoolingOptions();
if (coreConnections.isPresent())
poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, coreConnections.get());
if (maxConnections.isPresent())
poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnections.get());
if (maxSimultaneousRequests.isPresent())
poolingOptions.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, maxSimultaneousRequests.get());
if (minSimultaneousRequests.isPresent())
poolingOptions.setMinSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, minSimultaneousRequests.get());
poolingOptions.setCoreConnectionsPerHost(HostDistance.REMOTE, 0)
.setMaxConnectionsPerHost(HostDistance.REMOTE, 0)
.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.REMOTE, 0)
.setMinSimultaneousRequestsPerConnectionThreshold(HostDistance.REMOTE, 0);
return poolingOptions;
}
示例15: getCluster
import com.datastax.driver.core.PoolingOptions; //导入依赖的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;
}