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; }
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(); }
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(); }
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(); }
@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(); } } }
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; }
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(); }
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); }
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; }
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; }
@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); }
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; }
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; }
private Cluster doCreateCluster(CassandraProperties properties) { Cluster cluster = Cluster.builder() .withClusterName(properties.getCluster()) .withPort(properties.getPort()) .addContactPoints(properties.getContactPoints()) .withTimestampGenerator(getTimestampGenerator()) .withPoolingOptions( //TODO some default options - move to config new PoolingOptions() .setConnectionsPerHost(HostDistance.LOCAL, 4, 4) .setConnectionsPerHost(HostDistance.REMOTE, 2, 2) .setMaxRequestsPerConnection(HostDistance.LOCAL, 1024) .setMaxRequestsPerConnection(HostDistance.REMOTE, 256) ) .build(); //almost all queries are idempotent except counter updates, so it's easier to mark them as idempotent cluster.getConfiguration().getQueryOptions().setDefaultIdempotence(true); CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); TupleType tupleType = cluster.getMetadata() .newTupleType(DataType.timestamp(), DataType.varchar()); codecRegistry.register(new ZonedDateTimeCodec(tupleType)); QueryLogger queryLogger = QueryLogger.builder() .withConstantThreshold(100) .withMaxQueryStringLength(200) .build(); cluster.register(queryLogger); return cluster; }
public Cluster getCluster() { InetSocketAddress address = new InetSocketAddress(getContainerIpAddress(), getMappedPort(9042)); return Cluster.builder() .addContactPointsWithPorts(address) .withPoolingOptions(new PoolingOptions().setMaxConnectionsPerHost(HostDistance.LOCAL, 1)) .build(); }
@Test public void loadBalancing_defaultsToRoundRobin() { RoundRobinPolicy policy = toRoundRobinPolicy(Cassandra3Storage.builder().build()); Host foo = mock(Host.class); when(foo.getDatacenter()).thenReturn("foo"); Host bar = mock(Host.class); when(bar.getDatacenter()).thenReturn("bar"); policy.init(mock(Cluster.class), asList(foo, bar)); assertThat(policy.distance(foo)).isEqualTo(HostDistance.LOCAL); assertThat(policy.distance(bar)).isEqualTo(HostDistance.LOCAL); }
@Test public void loadBalancing_settingLocalDcIgnoresOtherDatacenters() { DCAwareRoundRobinPolicy policy = toDCAwareRoundRobinPolicy( Cassandra3Storage.builder().localDc("bar").build()); Host foo = mock(Host.class); when(foo.getDatacenter()).thenReturn("foo"); Host bar = mock(Host.class); when(bar.getDatacenter()).thenReturn("bar"); policy.init(mock(Cluster.class), asList(foo, bar)); assertThat(policy.distance(foo)).isEqualTo(HostDistance.IGNORED); assertThat(policy.distance(bar)).isEqualTo(HostDistance.LOCAL); }
@Test public void maxConnections_defaultsTo8() { PoolingOptions poolingOptions = buildCluster(Cassandra3Storage.builder().build()) .getConfiguration().getPoolingOptions(); assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(8); }
@Test public void maxConnections_setsMaxConnectionsPerDatacenterLocalHost() { PoolingOptions poolingOptions = buildCluster(Cassandra3Storage.builder().maxConnections(16).build()) .getConfiguration().getPoolingOptions(); assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(16); }
@Test public void loadBalancing_defaultsToRoundRobin() { RoundRobinPolicy policy = toRoundRobinPolicy(CassandraStorage.builder().build()); Host foo = mock(Host.class); when(foo.getDatacenter()).thenReturn("foo"); Host bar = mock(Host.class); when(bar.getDatacenter()).thenReturn("bar"); policy.init(mock(Cluster.class), asList(foo, bar)); assertThat(policy.distance(foo)).isEqualTo(HostDistance.LOCAL); assertThat(policy.distance(bar)).isEqualTo(HostDistance.LOCAL); }
@Test public void loadBalancing_settingLocalDcIgnoresOtherDatacenters() { DCAwareRoundRobinPolicy policy = toDCAwareRoundRobinPolicy( CassandraStorage.builder().localDc("bar").build()); Host foo = mock(Host.class); when(foo.getDatacenter()).thenReturn("foo"); Host bar = mock(Host.class); when(bar.getDatacenter()).thenReturn("bar"); policy.init(mock(Cluster.class), asList(foo, bar)); assertThat(policy.distance(foo)).isEqualTo(HostDistance.IGNORED); assertThat(policy.distance(bar)).isEqualTo(HostDistance.LOCAL); }
@Test public void maxConnections_defaultsTo8() { PoolingOptions poolingOptions = buildCluster(CassandraStorage.builder().build()) .getConfiguration().getPoolingOptions(); assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(8); }
@Test public void maxConnections_setsMaxConnectionsPerDatacenterLocalHost() { PoolingOptions poolingOptions = buildCluster(CassandraStorage.builder().maxConnections(16).build()) .getConfiguration().getPoolingOptions(); assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(16); }
public HostDistance distance(Host host) { if(host == primaryHost){ return HostDistance.LOCAL; }else if (remainingNodes.contains(host)){ return HostDistance.REMOTE; }else{ return HostDistance.IGNORED; } }
@Override public HostDistance distance(Host host) { if (isLocalHost(host)) { return HostDistance.LOCAL; } else { return HostDistance.REMOTE; } }
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); }
static Cluster getCluster(InetSocketAddress contactPoint) { return Cluster.builder() .addContactPointsWithPorts(contactPoint) .withRetryPolicy(ZipkinRetryPolicy.INSTANCE) .withPoolingOptions(new PoolingOptions().setMaxConnectionsPerHost(HostDistance.LOCAL, 1)) .build(); }
private Cluster getCluster() { HostAndPort hap = HostAndPort.fromParts(getContainerIpAddress(), getMappedPort(9042)); InetSocketAddress address = new InetSocketAddress(hap.getHostText(), hap.getPort()); return Cluster.builder() .addContactPointsWithPorts(address) .withRetryPolicy(ZipkinRetryPolicy.INSTANCE) .withPoolingOptions(new PoolingOptions().setMaxConnectionsPerHost(HostDistance.LOCAL, 1)) .build(); }
private void setPoolingOptions(PoolingOptions poolingOptions, HostDistance hostDistance, HostDistanceOptions options) { if (options.getCoreConnections() != null) { poolingOptions.setCoreConnectionsPerHost(hostDistance, options.getCoreConnections()); } if (options.getMaxConnections() != null) { poolingOptions.setMaxConnectionsPerHost(hostDistance, options.getMaxConnections()); } if (options.getMaxRequestsPerConnection() != null) { poolingOptions.setMaxRequestsPerConnection(hostDistance, options.getMaxRequestsPerConnection()); } if (options.getNewConnectionThreshold() != null) { poolingOptions.setNewConnectionThreshold(hostDistance, options.getNewConnectionThreshold()); } }
@Test public void buildsPoolingOptionsWithDefaultValues() throws Exception { final PoolingOptionsFactory factory = new PoolingOptionsFactory(); final PoolingOptions defaultPoolingOptions = new PoolingOptions(); final PoolingOptions poolingOptions = factory.build(); assertThat(poolingOptions.getHeartbeatIntervalSeconds()).isEqualTo(defaultPoolingOptions.getHeartbeatIntervalSeconds()); assertThat(poolingOptions.getPoolTimeoutMillis()).isEqualTo(defaultPoolingOptions.getPoolTimeoutMillis()); verifySamePoolingOptions(poolingOptions, defaultPoolingOptions, HostDistance.LOCAL); verifySamePoolingOptions(poolingOptions, defaultPoolingOptions, HostDistance.REMOTE); }
private void verifySamePoolingOptions(PoolingOptions poolingOptions, PoolingOptions defaultPoolingOptions, HostDistance hostDistance) { assertThat(poolingOptions.getCoreConnectionsPerHost(hostDistance)) .isEqualTo(defaultPoolingOptions.getCoreConnectionsPerHost(hostDistance)); assertThat(poolingOptions.getMaxConnectionsPerHost(hostDistance)) .isEqualTo(defaultPoolingOptions.getMaxConnectionsPerHost(hostDistance)); assertThat(poolingOptions.getMaxRequestsPerConnection(hostDistance)) .isEqualTo(defaultPoolingOptions.getMaxRequestsPerConnection(hostDistance)); assertThat(poolingOptions.getNewConnectionThreshold(hostDistance)) .isEqualTo(defaultPoolingOptions.getNewConnectionThreshold(hostDistance)); }
@Override public Session createSession() { Cluster.Builder clusterBuilder = new Cluster.Builder() .withPort(9042) .withoutJMXReporting() .withPoolingOptions(new PoolingOptions() .setMaxConnectionsPerHost(HostDistance.LOCAL, 1024) .setCoreConnectionsPerHost(HostDistance.LOCAL, 1024) .setMaxConnectionsPerHost(HostDistance.REMOTE, 1024) .setCoreConnectionsPerHost(HostDistance.REMOTE, 1024) .setMaxRequestsPerConnection(HostDistance.LOCAL, 1024) .setMaxRequestsPerConnection(HostDistance.REMOTE, 1024) .setMaxQueueSize(1024)); Arrays.stream(nodes.split(",")).forEach(clusterBuilder::addContactPoints); cluster = clusterBuilder.build(); cluster.init(); try { session = cluster.connect("system"); return session; } finally { if (session == null) { cluster.close(); } } }
private Gauge<Integer> createMaxLoad(String hostname) { return () -> { Session.State state = session.getState(); return getHost(state, hostname).map((host) -> { Configuration configuration = session.getCluster().getConfiguration(); PoolingOptions poolingOptions = configuration.getPoolingOptions(); HostDistance distance = configuration.getPolicies().getLoadBalancingPolicy().distance(host); int connections = state.getOpenConnections(host); return connections * poolingOptions.getMaxRequestsPerConnection(distance); }).orElse(0); }; }
public RxSessionImpl(Session session) { this.session = session; this.loadBalancingPolicy = session.getCluster().getConfiguration().getPolicies().getLoadBalancingPolicy(); PoolingOptions poolingOptions = session.getCluster().getConfiguration().getPoolingOptions(); maxInFlightLocal = poolingOptions.getCoreConnectionsPerHost(HostDistance.LOCAL) * poolingOptions.getMaxRequestsPerConnection(HostDistance.LOCAL); maxInFlightRemote = poolingOptions.getCoreConnectionsPerHost(HostDistance.REMOTE) * poolingOptions.getMaxRequestsPerConnection(HostDistance.REMOTE); }
private Cluster.Builder populatePoolingSettings(Properties properties, Cluster.Builder builder) { String localCoreConnectionsPerHost = properties.getProperty(CassandraStoreParameters.LOCAL_CORE_CONNECTIONS_PER_HOST); String remoteCoreConnectionsPerHost = properties.getProperty(CassandraStoreParameters.REMOTE_CORE_CONNECTIONS_PER_HOST); String localMaxConnectionsPerHost = properties.getProperty(CassandraStoreParameters.LOCAL_MAX_CONNECTIONS_PER_HOST); String remoteMaxConnectionsPerHost = properties.getProperty(CassandraStoreParameters.REMOTE_MAX_CONNECTIONS_PER_HOST); String localNewConnectionThreshold = properties.getProperty(CassandraStoreParameters.LOCAL_NEW_CONNECTION_THRESHOLD); String remoteNewConnectionThreshold = properties.getProperty(CassandraStoreParameters.REMOTE_NEW_CONNECTION_THRESHOLD); String localMaxRequestsPerConnection = properties.getProperty(CassandraStoreParameters.LOCAL_MAX_REQUESTS_PER_CONNECTION); String remoteMaxRequestsPerConnection = properties.getProperty(CassandraStoreParameters.REMOTE_MAX_REQUESTS_PER_CONNECTION); PoolingOptions options = new PoolingOptions(); if (localCoreConnectionsPerHost != null) { options.setCoreConnectionsPerHost(HostDistance.LOCAL, Integer.parseInt(localCoreConnectionsPerHost)); } if (remoteCoreConnectionsPerHost != null) { options.setCoreConnectionsPerHost(HostDistance.REMOTE, Integer.parseInt(remoteCoreConnectionsPerHost)); } if (localMaxConnectionsPerHost != null) { options.setMaxConnectionsPerHost(HostDistance.LOCAL, Integer.parseInt(localMaxConnectionsPerHost)); } if (remoteMaxConnectionsPerHost != null) { options.setMaxConnectionsPerHost(HostDistance.REMOTE, Integer.parseInt(remoteMaxConnectionsPerHost)); } if (localNewConnectionThreshold != null) { options.setNewConnectionThreshold(HostDistance.LOCAL, Integer.parseInt(localNewConnectionThreshold)); } if (remoteNewConnectionThreshold != null) { options.setNewConnectionThreshold(HostDistance.REMOTE, Integer.parseInt(remoteNewConnectionThreshold)); } if (localMaxRequestsPerConnection != null) { options.setMaxRequestsPerConnection(HostDistance.LOCAL, Integer.parseInt(localMaxRequestsPerConnection)); } if (remoteMaxRequestsPerConnection != null) { options.setMaxRequestsPerConnection(HostDistance.REMOTE, Integer.parseInt(remoteMaxRequestsPerConnection)); } builder = builder.withPoolingOptions(options); return builder; }