poolOps.setHeartbeatIntervalSeconds(cassandraConf.getHeartbeatIntervalSeconds()); poolOps.setIdleTimeoutSeconds(cassandraConf.getIdleTimeoutSeconds()); poolOps.setMaxRequestsPerConnection(HostDistance.LOCAL, cassandraConf.getMaxRequestPerConnectionLocal()); poolOps.setMaxRequestsPerConnection(HostDistance.REMOTE, cassandraConf.getMaxRequestPerConnectionRemote()); cluster.withPoolingOptions(poolOps);
.setConnectionsPerHost(HostDistance.REMOTE, m_clusterConfiguration.getConnectionsRemoteCore(), m_clusterConfiguration.getConnectionsRemoteMax()) .setMaxRequestsPerConnection(HostDistance.LOCAL, m_clusterConfiguration.getRequestsPerConnectionLocal()) .setMaxRequestsPerConnection(HostDistance.REMOTE, m_clusterConfiguration.getRequestsPerConnectionRemote()) .setMaxQueueSize(m_clusterConfiguration.getMaxQueueSize())) .withReconnectionPolicy(new ExponentialReconnectionPolicy(100, 5 * 1000))
options.setMaxRequestsPerConnection(hostDist, new Integer(maxRequestsPerConnection));
public JavaDriverConfigBuilder withMaxRequestsPerConnection(HostDistance distance, int maxRequests) { this.poolingOptions.setMaxRequestsPerConnection(distance, maxRequests); return this; }
.getConfiguration() .getPoolingOptions() .setMaxRequestsPerConnection(HostDistance.LOCAL, maxRequests);
private HostConnectionPool createPool(Cluster cluster, int coreConnections, int maxConnections) { cluster .getConfiguration() .getPoolingOptions() .setNewConnectionThreshold(HostDistance.LOCAL, 100) .setMaxRequestsPerConnection(HostDistance.LOCAL, 128) .setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnections) .setCoreConnectionsPerHost(HostDistance.LOCAL, coreConnections); Session session = cluster.connect(); Host host = TestUtils.findHost(cluster, 1); // Replace the existing pool with a spy pool and return it. SessionManager sm = ((SessionManager) session); return sm.pools.get(host); }
@Test(groups = "unit") public void should_enforce_invariants_once_protocol_version_known() { // OK for v2 (default max = 8) PoolingOptions options = new PoolingOptions().setCoreConnectionsPerHost(LOCAL, 3); options.setCoreConnectionsPerHost(LOCAL, 3); options.setProtocolVersion(ProtocolVersion.V2); assertThat(options.getCoreConnectionsPerHost(LOCAL)).isEqualTo(3); assertThat(options.getMaxConnectionsPerHost(LOCAL)).isEqualTo(8); // KO for v3 (default max = 1) options = new PoolingOptions().setCoreConnectionsPerHost(LOCAL, 3); try { options.setProtocolVersion(ProtocolVersion.V3); fail("Expected an IllegalArgumentException"); } catch (IllegalArgumentException e) { /*expected*/ } // OK for v3 (up to 32K stream ids) options = new PoolingOptions().setMaxRequestsPerConnection(LOCAL, 5000); options.setProtocolVersion(ProtocolVersion.V3); assertThat(options.getMaxRequestsPerConnection(LOCAL)).isEqualTo(5000); // KO for v2 (up to 128) options = new PoolingOptions().setMaxRequestsPerConnection(LOCAL, 5000); try { options.setProtocolVersion(ProtocolVersion.V2); fail("Expected an IllegalArgumentException"); } catch (IllegalArgumentException e) { /*expected*/ } }
.getConfiguration() .getPoolingOptions() .setMaxRequestsPerConnection(HostDistance.LOCAL, 100); int maxQueueSize = 256;
void setMaxRequestsPerConnection(PoolingOptions poolingOptions) { if (maxRequestsPerConnection != null) { poolingOptions.setMaxRequestsPerConnection(getHostDistance(), maxRequestsPerConnection); } }
PoolingOptions setMaxRequestsPerConnection(PoolingOptions poolingOptions) { if (maxRequestsPerConnection != null) { poolingOptions.setMaxRequestsPerConnection(getHostDistance(), maxRequestsPerConnection); } return poolingOptions; }
options.setMaxRequestsPerConnection(LOCAL, -1); fail("expected an IllegalArgumentException"); } catch (IllegalArgumentException e) {
getConfiguration().getCoreConnectionsPerHostRemote(), getConfiguration().getMaxConnectionsPerHostRemote()) .setMaxRequestsPerConnection(HostDistance.LOCAL, .setMaxRequestsPerConnection(HostDistance.REMOTE, getConfiguration().getMaxRequestPerConnectionRemote()) .setNewConnectionThreshold(HostDistance.LOCAL,
private void init() { Cluster.Builder clusterBuilder = Cluster.builder(); clusterBuilder.addContactPoint(contactpoints).withPort(Integer.valueOf(port)); if (username != null && password != null) { clusterBuilder.withCredentials(username, password); } cluster = clusterBuilder.build(); PoolingOptions poolingOptions = cluster.getConfiguration().getPoolingOptions(); poolingOptions.setConnectionsPerHost(HostDistance.LOCAL, 5, 12) .setConnectionsPerHost(HostDistance.REMOTE, 2, 4); poolingOptions.setMaxRequestsPerConnection(HostDistance.LOCAL, 2048) .setMaxRequestsPerConnection(HostDistance.REMOTE, 512); session = cluster.connect(keyspace); mappingManager = new MappingManager(session, getProtocolVersion()); }
@Override public void initialize(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.start(monitor); // Verify that contact points were specified. String[] contactPoints = getContactPoints().getValue().split(","); if (contactPoints.length == 0) { throw new SiteWhereException("No contact points specified for Cassandra cluster."); } Cluster.Builder builder = Cluster.builder(); for (String contactPoint : contactPoints) { builder.addContactPoint(contactPoint.trim()); } PoolingOptions pooling = new PoolingOptions(); pooling.setMaxRequestsPerConnection(HostDistance.LOCAL, 32768); pooling.setMaxRequestsPerConnection(HostDistance.REMOTE, 32768); pooling.setMaxQueueSize(32768); builder.withPoolingOptions(pooling); this.cluster = builder.build(); this.session = getCluster().connect(); }
private void init() { Cluster.Builder clusterBuilder = Cluster.builder(); clusterBuilder.addContactPoint(contactpoints).withPort(Integer.valueOf(port)); if (username != null && password != null) { clusterBuilder.withCredentials(username, password); } cluster = clusterBuilder.build(); PoolingOptions poolingOptions = cluster.getConfiguration().getPoolingOptions(); poolingOptions.setConnectionsPerHost(HostDistance.LOCAL, 5, 12) .setConnectionsPerHost(HostDistance.REMOTE, 2, 4); poolingOptions.setMaxRequestsPerConnection(HostDistance.LOCAL, 2048) .setMaxRequestsPerConnection(HostDistance.REMOTE, 512); session = cluster.connect(keyspace); mappingManager = new MappingManager(session, getProtocolVersion()); }
private HostConnectionPool createPool(Cluster cluster, int coreConnections, int maxConnections) { cluster .getConfiguration() .getPoolingOptions() .setNewConnectionThreshold(HostDistance.LOCAL, 100) .setMaxRequestsPerConnection(HostDistance.LOCAL, 128) .setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnections) .setCoreConnectionsPerHost(HostDistance.LOCAL, coreConnections); Session session = cluster.connect(); Host host = TestUtils.findHost(cluster, 1); // Replace the existing pool with a spy pool and return it. SessionManager sm = ((SessionManager) session); return sm.pools.get(host); }
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()); } }
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()); } }
@Override public Cluster registerCluster(String clName, String contactPoint, int connections, int port, String username, String password) { PoolingOptions poolingOpts = new PoolingOptions() .setConnectionsPerHost(HostDistance.LOCAL, connections, connections) .setMaxRequestsPerConnection(HostDistance.LOCAL, 32768); Cluster.Builder clusterBuilder = Cluster.builder() .withClusterName(clName) .addContactPoint(contactPoint) .withPoolingOptions(poolingOpts) .withPort(port) .withLoadBalancingPolicy( new TokenAwarePolicy( new RoundRobinPolicy() ) ); if ((username != null) && (password != null)) { clusterBuilder = clusterBuilder.withCredentials(username, password); } cluster = clusterBuilder.build(); return cluster; }
@Override public Cluster registerCluster(String clName, String contactPoint, int connections, int port, String username, String password) { PoolingOptions poolingOpts = new PoolingOptions() .setConnectionsPerHost(HostDistance.LOCAL, connections, connections) .setMaxRequestsPerConnection(HostDistance.LOCAL, 32768); Cluster.Builder clusterBuilder = Cluster.builder() .withClusterName(clName) .addContactPoint(contactPoint) .withPoolingOptions(poolingOpts) .withPort(port) .withLoadBalancingPolicy( new TokenAwarePolicy( new RoundRobinPolicy() ) ); if ((username != null) && (password != null)) { clusterBuilder = clusterBuilder.withCredentials(username, password); } cluster = clusterBuilder.build(); return cluster; }