Skip to content

Commit a2cd659

Browse files
committed
Add PoolingOptions method to set both core and max connections (JAVA-662)
1 parent 64ed3ca commit a2cd659

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

changelog/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
- [improvement] Create values() function for Insert builder using List (JAVA-225)
1616
- [improvement] Warn when ReplicationStrategy encounters invalid
1717
replication factors (JAVA-702)
18+
- [improvement] Add PoolingOptions method to set both core and max
19+
connections (JAVA-662).
1820

1921
Merged from 2.0.10_fixes branch:
2022

driver-core/src/main/java/com/datastax/driver/core/PoolingOptions.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,30 @@ public synchronized PoolingOptions setMaxConnectionsPerHost(HostDistance distanc
230230
return this;
231231
}
232232

233+
/**
234+
* Sets the core and maximum number of connections per host in one call.
235+
* <p>
236+
* This is a convenience method that is equivalent to calling {@link #setCoreConnectionsPerHost(HostDistance, int)}
237+
* and {@link #setMaxConnectionsPerHost(HostDistance, int)}.
238+
*
239+
* @param distance the {@code HostDistance} for which to set these threshold.
240+
* @param core the core number of connections.
241+
* @param max the max number of connections.
242+
* @return this {@code PoolingOptions}.
243+
*
244+
* @throws IllegalArgumentException if {@code distance == HostDistance.IGNORED},
245+
* or if {@code core} > {@code max}.
246+
*/
247+
public synchronized PoolingOptions setConnectionsPerHost(HostDistance distance, int core, int max) {
248+
if (distance == HostDistance.IGNORED)
249+
throw new IllegalArgumentException("Cannot set connections per host for " + distance + " hosts");
250+
251+
checkConnectionsPerHostOrder(core, max, distance);
252+
coreConnections[distance.ordinal()] = core;
253+
maxConnections[distance.ordinal()] = max;
254+
return this;
255+
}
256+
233257
/**
234258
* Returns the timeout before an idle connection is removed.
235259
*

0 commit comments

Comments
 (0)