kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 13ff5c33b0a068591df0f79b4f2fe6201cc63e9ea09284984d4febb22ecf7b0f |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2016-02-23 17:46 +01:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2016-02-23 17:46 +01:00 |
| Parents | 4358932e3bd3, 31fb7af28bd6 |
2 files changed
modified changelog/README.md +1 −0
| @@ -12,6 +12,7 @@ | ||
| 12 | 12 | - [bug] JAVA-1039: Minor bugs in Event Debouncer. |
| 13 | 13 | - [improvement] JAVA-843: Disable frozen checks in mapper. |
| 14 | 14 | - [improvement] JAVA-833: Improve message when a nested type can't be serialized. |
| 15 | +- [improvement] JAVA-1011: Expose PoolingOptions default values. | |
| 15 | 16 | |
| 16 | 17 | Merged from 2.0 branch: |
| 17 | 18 |
modified driver-core/src/main/java/com/datastax/driver/core/PoolingOptions.java +83 −34
| @@ -66,33 +66,76 @@ | ||
| 66 | 66 | */ |
| 67 | 67 | public static final int UNSET = Integer.MIN_VALUE; |
| 68 | 68 | |
| 69 | - private static final Map<ProtocolVersion, Map<String, Integer>> DEFAULTS = ImmutableMap.<ProtocolVersion, Map<String, Integer>>of( | |
| 70 | - ProtocolVersion.V2, ImmutableMap.<String, Integer>builder() | |
| 71 | - .put("corePoolLocal", 2) | |
| 72 | - .put("maxPoolLocal", 8) | |
| 73 | - .put("corePoolRemote", 1) | |
| 74 | - .put("maxPoolRemote", 2) | |
| 75 | - .put("newConnectionThresholdLocal", 100) | |
| 76 | - .put("newConnectionThresholdRemote", 100) | |
| 77 | - .put("maxRequestsPerConnectionLocal", 128) | |
| 78 | - .put("maxRequestsPerConnectionRemote", 128) | |
| 69 | + public static final String CORE_POOL_LOCAL_KEY = "corePoolLocal"; | |
| 70 | + public static final String MAX_POOL_LOCAL_KEY = "maxPoolLocal"; | |
| 71 | + public static final String CORE_POOL_REMOTE_KEY = "corePoolRemote"; | |
| 72 | + public static final String MAX_POOL_REMOTE_KEY = "maxPoolRemote"; | |
| 73 | + public static final String NEW_CONNECTION_THRESHOLD_LOCAL_KEY = "newConnectionThresholdLocal"; | |
| 74 | + public static final String NEW_CONNECTION_THRESHOLD_REMOTE_KEY = "newConnectionThresholdRemote"; | |
| 75 | + public static final String MAX_REQUESTS_PER_CONNECTION_LOCAL_KEY = "maxRequestsPerConnectionLocal"; | |
| 76 | + public static final String MAX_REQUESTS_PER_CONNECTION_REMOTE_KEY = "maxRequestsPerConnectionRemote"; | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * The default values for connection options, that depend on the native protocol version. | |
| 80 | + * <p/> | |
| 81 | + * The map stores protocol versions in ascending order, and only the versions that introduced a change are present. | |
| 82 | + * To find the defaults for a particular version, look for the highest key that is less than or equal to that | |
| 83 | + * version, in other words: | |
| 84 | + * <pre>{@code | |
| 85 | + * ProtocolVersion referenceVersion = null; | |
| 86 | + * for (ProtocolVersion key : DEFAULTS.keySet()) { | |
| 87 | + * if (key.compareTo(actualVersion) > 0) | |
| 88 | + * break; | |
| 89 | + * else | |
| 90 | + * referenceVersion = key; | |
| 91 | + * } | |
| 92 | + * Map<String, Integer> defaults = DEFAULTS.get(referenceVersion); | |
| 93 | + * }</pre> | |
| 94 | + * Once you've extracted the underlying map, use the keys {@code CORE_POOL_LOCAL_KEY}, | |
| 95 | + * {@code MAX_POOL_LOCAL_KEY}, {@code CORE_POOL_REMOTE_KEY}, {@code MAX_POOL_REMOTE_KEY}, | |
| 96 | + * {@code NEW_CONNECTION_THRESHOLD_LOCAL_KEY}, {@code NEW_CONNECTION_THRESHOLD_REMOTE_KEY}, | |
| 97 | + * {@code MAX_REQUESTS_PER_CONNECTION_LOCAL_KEY} and {@code MAX_REQUESTS_PER_CONNECTION_REMOTE_KEY}. | |
| 98 | + * | |
| 99 | + * @see #UNSET | |
| 100 | + */ | |
| 101 | + public static final Map<ProtocolVersion, Map<String, Integer>> DEFAULTS = ImmutableMap.<ProtocolVersion, Map<String, Integer>>of( | |
| 102 | + ProtocolVersion.V1, ImmutableMap.<String, Integer>builder() | |
| 103 | + .put(CORE_POOL_LOCAL_KEY, 2) | |
| 104 | + .put(MAX_POOL_LOCAL_KEY, 8) | |
| 105 | + .put(CORE_POOL_REMOTE_KEY, 1) | |
| 106 | + .put(MAX_POOL_REMOTE_KEY, 2) | |
| 107 | + .put(NEW_CONNECTION_THRESHOLD_LOCAL_KEY, 100) | |
| 108 | + .put(NEW_CONNECTION_THRESHOLD_REMOTE_KEY, 100) | |
| 109 | + .put(MAX_REQUESTS_PER_CONNECTION_LOCAL_KEY, 128) | |
| 110 | + .put(MAX_REQUESTS_PER_CONNECTION_REMOTE_KEY, 128) | |
| 79 | 111 | .build(), |
| 80 | 112 | |
| 81 | 113 | ProtocolVersion.V3, ImmutableMap.<String, Integer>builder() |
| 82 | - .put("corePoolLocal", 1) | |
| 83 | - .put("maxPoolLocal", 1) | |
| 84 | - .put("corePoolRemote", 1) | |
| 85 | - .put("maxPoolRemote", 1) | |
| 86 | - .put("newConnectionThresholdLocal", 800) | |
| 87 | - .put("newConnectionThresholdRemote", 200) | |
| 88 | - .put("maxRequestsPerConnectionLocal", 1024) | |
| 89 | - .put("maxRequestsPerConnectionRemote", 256) | |
| 114 | + .put(CORE_POOL_LOCAL_KEY, 1) | |
| 115 | + .put(MAX_POOL_LOCAL_KEY, 1) | |
| 116 | + .put(CORE_POOL_REMOTE_KEY, 1) | |
| 117 | + .put(MAX_POOL_REMOTE_KEY, 1) | |
| 118 | + .put(NEW_CONNECTION_THRESHOLD_LOCAL_KEY, 800) | |
| 119 | + .put(NEW_CONNECTION_THRESHOLD_REMOTE_KEY, 200) | |
| 120 | + .put(MAX_REQUESTS_PER_CONNECTION_LOCAL_KEY, 1024) | |
| 121 | + .put(MAX_REQUESTS_PER_CONNECTION_REMOTE_KEY, 256) | |
| 90 | 122 | .build() |
| 91 | 123 | ); |
| 92 | 124 | |
| 93 | - private static final int DEFAULT_IDLE_TIMEOUT_SECONDS = 120; | |
| 94 | - private static final int DEFAULT_POOL_TIMEOUT_MILLIS = 5000; | |
| 95 | - private static final int DEFAULT_HEARTBEAT_INTERVAL_SECONDS = 30; | |
| 125 | + /** | |
| 126 | + * The default value for {@link #getIdleTimeoutSeconds()} ({@value}). | |
| 127 | + */ | |
| 128 | + public static final int DEFAULT_IDLE_TIMEOUT_SECONDS = 120; | |
| 129 | + | |
| 130 | + /** | |
| 131 | + * The default value for {@link #getPoolTimeoutMillis()} ({@value}). | |
| 132 | + */ | |
| 133 | + public static final int DEFAULT_POOL_TIMEOUT_MILLIS = 5000; | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * The default value for {@link #getHeartbeatIntervalSeconds()} ({@value}). | |
| 137 | + */ | |
| 138 | + public static final int DEFAULT_HEARTBEAT_INTERVAL_SECONDS = 30; | |
| 96 | 139 | |
| 97 | 140 | private static final Executor DEFAULT_INITIALIZATION_EXECUTOR = MoreExecutors.sameThreadExecutor(); |
| 98 | 141 | |
| @@ -450,40 +493,46 @@ | ||
| 450 | 493 | return this; |
| 451 | 494 | } |
| 452 | 495 | |
| 453 | - synchronized void setProtocolVersion(ProtocolVersion protocolVersion) { | |
| 454 | - this.protocolVersion = protocolVersion; | |
| 496 | + synchronized void setProtocolVersion(ProtocolVersion actualVersion) { | |
| 497 | + this.protocolVersion = actualVersion; | |
| 498 | + | |
| 499 | + ProtocolVersion referenceVersion = null; | |
| 500 | + for (ProtocolVersion key : DEFAULTS.keySet()) { | |
| 501 | + if (key.compareTo(actualVersion) > 0) | |
| 502 | + break; | |
| 503 | + else | |
| 504 | + referenceVersion = key; | |
| 505 | + } | |
| 506 | + assert referenceVersion != null; // will not happen since V1 is a key | |
| 455 | 507 | |
| 456 | - ProtocolVersion referenceVersion = (protocolVersion.compareTo(ProtocolVersion.V2) <= 0) | |
| 457 | - ? ProtocolVersion.V2 | |
| 458 | - : ProtocolVersion.V3; | |
| 459 | 508 | Map<String, Integer> defaults = DEFAULTS.get(referenceVersion); |
| 460 | 509 | |
| 461 | 510 | if (coreConnections[LOCAL.ordinal()] == UNSET) |
| 462 | - coreConnections[LOCAL.ordinal()] = defaults.get("corePoolLocal"); | |
| 511 | + coreConnections[LOCAL.ordinal()] = defaults.get(CORE_POOL_LOCAL_KEY); | |
| 463 | 512 | if (maxConnections[LOCAL.ordinal()] == UNSET) |
| 464 | - maxConnections[LOCAL.ordinal()] = defaults.get("maxPoolLocal"); | |
| 513 | + maxConnections[LOCAL.ordinal()] = defaults.get(MAX_POOL_LOCAL_KEY); | |
| 465 | 514 | checkConnectionsPerHostOrder(coreConnections[LOCAL.ordinal()], maxConnections[LOCAL.ordinal()], LOCAL); |
| 466 | 515 | |
| 467 | 516 | if (coreConnections[REMOTE.ordinal()] == UNSET) |
| 468 | - coreConnections[REMOTE.ordinal()] = defaults.get("corePoolRemote"); | |
| 517 | + coreConnections[REMOTE.ordinal()] = defaults.get(CORE_POOL_REMOTE_KEY); | |
| 469 | 518 | if (maxConnections[REMOTE.ordinal()] == UNSET) |
| 470 | - maxConnections[REMOTE.ordinal()] = defaults.get("maxPoolRemote"); | |
| 519 | + maxConnections[REMOTE.ordinal()] = defaults.get(MAX_POOL_REMOTE_KEY); | |
| 471 | 520 | checkConnectionsPerHostOrder(coreConnections[REMOTE.ordinal()], maxConnections[REMOTE.ordinal()], REMOTE); |
| 472 | 521 | |
| 473 | 522 | if (newConnectionThreshold[LOCAL.ordinal()] == UNSET) |
| 474 | - newConnectionThreshold[LOCAL.ordinal()] = defaults.get("newConnectionThresholdLocal"); | |
| 523 | + newConnectionThreshold[LOCAL.ordinal()] = defaults.get(NEW_CONNECTION_THRESHOLD_LOCAL_KEY); | |
| 475 | 524 | checkRequestsPerConnectionRange(newConnectionThreshold[LOCAL.ordinal()], "New connection threshold", LOCAL); |
| 476 | 525 | |
| 477 | 526 | if (newConnectionThreshold[REMOTE.ordinal()] == UNSET) |
| 478 | - newConnectionThreshold[REMOTE.ordinal()] = defaults.get("newConnectionThresholdRemote"); | |
| 527 | + newConnectionThreshold[REMOTE.ordinal()] = defaults.get(NEW_CONNECTION_THRESHOLD_REMOTE_KEY); | |
| 479 | 528 | checkRequestsPerConnectionRange(newConnectionThreshold[REMOTE.ordinal()], "New connection threshold", REMOTE); |
| 480 | 529 | |
| 481 | 530 | if (maxRequestsPerConnectionLocal == UNSET) |
| 482 | - maxRequestsPerConnectionLocal = defaults.get("maxRequestsPerConnectionLocal"); | |
| 531 | + maxRequestsPerConnectionLocal = defaults.get(MAX_REQUESTS_PER_CONNECTION_LOCAL_KEY); | |
| 483 | 532 | checkRequestsPerConnectionRange(maxRequestsPerConnectionLocal, "Max requests per connection", LOCAL); |
| 484 | 533 | |
| 485 | 534 | if (maxRequestsPerConnectionRemote == UNSET) |
| 486 | - maxRequestsPerConnectionRemote = defaults.get("maxRequestsPerConnectionRemote"); | |
| 535 | + maxRequestsPerConnectionRemote = defaults.get(MAX_REQUESTS_PER_CONNECTION_REMOTE_KEY); | |
| 487 | 536 | checkRequestsPerConnectionRange(maxRequestsPerConnectionRemote, "Max requests per connection", REMOTE); |
| 488 | 537 | } |
| 489 | 538 |