kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 75c486da29ccb5a3ca9c524bc9ac7421d7df16547bce2d1b8c07957c507adb48 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-10-07 14:36 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-10-13 11:29 +02:00 |
| Parents | d0cf52e93999 |
5 files changed
modified changelog/README.md +1 −0
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | - [bug] Fix implementation of UserType.hashCode() (JAVA-942) |
| 7 | 7 | - [improvement] Don't delay UP/ADDED notifications if protocol version = V4 (JAVA-877) |
| 8 | 8 | - [improvement] Parse 'extensions' column in table metadata (JAVA-938) |
| 9 | +- [bug] Fix Configuration builder to allow disabled metrics (JAVA-900) | |
| 9 | 10 | |
| 10 | 11 | |
| 11 | 12 | ### 3.0.0-alpha3 |
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +5 −4
| @@ -396,8 +396,8 @@ | ||
| 396 | 396 | * The cluster metrics. |
| 397 | 397 | * |
| 398 | 398 | * @return the cluster metrics, or {@code null} if metrics collection has |
| 399 | - * been disabled (that is if {@link Configuration#getMetricsOptions} | |
| 400 | - * returns {@code null}). | |
| 399 | + * been disabled (that is if {@code cluster.getConfiguration().getMetricsOptions().isEnabled()} | |
| 400 | + * returns {@code false}). | |
| 401 | 401 | */ |
| 402 | 402 | public Metrics getMetrics() { |
| 403 | 403 | checkNotClosed(manager); |
| @@ -1202,7 +1202,8 @@ | ||
| 1202 | 1202 | public Configuration getConfiguration() { |
| 1203 | 1203 | ProtocolOptions protocolOptions = new ProtocolOptions(port, protocolVersion, maxSchemaAgreementWaitSeconds, sslOptions, authProvider) |
| 1204 | 1204 | .setCompression(compression); |
| 1205 | - MetricsOptions metricsOptions = metricsEnabled ? new MetricsOptions(jmxEnabled) : null; | |
| 1205 | + | |
| 1206 | + MetricsOptions metricsOptions = new MetricsOptions(metricsEnabled, jmxEnabled); | |
| 1206 | 1207 | |
| 1207 | 1208 | return configurationBuilder |
| 1208 | 1209 | .withProtocolOptions(protocolOptions) |
| @@ -1328,7 +1329,7 @@ | ||
| 1328 | 1329 | this.metadata = new Metadata(this); |
| 1329 | 1330 | this.connectionFactory = new Connection.Factory(this, configuration); |
| 1330 | 1331 | this.controlConnection = new ControlConnection(this); |
| 1331 | - this.metrics = configuration.getMetricsOptions() == null ? null : new Metrics(this); | |
| 1332 | + this.metrics = configuration.getMetricsOptions().isEnabled() ? new Metrics(this) : null; | |
| 1332 | 1333 | this.preparedQueries = new MapMaker().weakValues().makeMap(); |
| 1333 | 1334 | |
| 1334 | 1335 | // create debouncers - at this stage, they are not running yet |
modified driver-core/src/main/java/com/datastax/driver/core/Configuration.java +9 −0
| @@ -35,6 +35,9 @@ | ||
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Returns a builder to create a new {@code Configuration} object. |
| 38 | + * <p> | |
| 39 | + * You only need this if you are building the configuration yourself. If you | |
| 40 | + * use {@link Cluster#builder()}, it will be done under the hood for you. | |
| 38 | 41 | * |
| 39 | 42 | * @return the builder. |
| 40 | 43 | */ |
| @@ -209,6 +212,12 @@ | ||
| 209 | 212 | |
| 210 | 213 | /** |
| 211 | 214 | * Sets the metrics options for this cluster. |
| 215 | + * <p> | |
| 216 | + * If this method doesn't get called, the configuration will use the | |
| 217 | + * defaults: metrics enabled with JMX reporting enabled. | |
| 218 | + * To disable metrics, call this method with an instance where | |
| 219 | + * {@link MetricsOptions#isEnabled() isEnabled()} returns false. | |
| 220 | + * | |
| 212 | 221 | * @param metricsOptions the metrics options. |
| 213 | 222 | * @return this builder. |
| 214 | 223 | */ |
modified driver-core/src/main/java/com/datastax/driver/core/MetricsOptions.java +17 −9
| @@ -20,14 +20,14 @@ | ||
| 20 | 20 | */ |
| 21 | 21 | public class MetricsOptions { |
| 22 | 22 | |
| 23 | + private final boolean metricsEnabled; | |
| 23 | 24 | private final boolean jmxEnabled; |
| 24 | 25 | |
| 25 | 26 | /** |
| 26 | - * Creates a new {@code MetricsOptions} object with default values. | |
| 27 | + * Creates a new {@code MetricsOptions} object with default values (metrics enabled, JMX reporting enabled). | |
| 27 | 28 | */ |
| 28 | - public MetricsOptions() | |
| 29 | - { | |
| 30 | - this(true); | |
| 29 | + public MetricsOptions() { | |
| 30 | + this(true, true); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| @@ -35,18 +35,26 @@ | ||
| 35 | 35 | * |
| 36 | 36 | * @param jmxEnabled whether to enable JMX reporting or not. |
| 37 | 37 | */ |
| 38 | - public MetricsOptions(boolean jmxEnabled) | |
| 39 | - { | |
| 38 | + public MetricsOptions(boolean enabled, boolean jmxEnabled) { | |
| 39 | + this.metricsEnabled = enabled; | |
| 40 | 40 | this.jmxEnabled = jmxEnabled; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * Returns whether JMX reporting is enabled (the default). | |
| 44 | + * Returns whether metrics are enabled. | |
| 45 | + * | |
| 46 | + * @return whether metrics are enabled. | |
| 47 | + */ | |
| 48 | + public boolean isEnabled() { | |
| 49 | + return metricsEnabled; | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Returns whether JMX reporting is enabled. | |
| 45 | 54 | * |
| 46 | 55 | * @return whether JMX reporting is enabled. |
| 47 | 56 | */ |
| 48 | - public boolean isJMXReportingEnabled() | |
| 49 | - { | |
| 57 | + public boolean isJMXReportingEnabled() { | |
| 50 | 58 | return jmxEnabled; |
| 51 | 59 | } |
| 52 | 60 | } |
modified driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java +1 −1
| @@ -221,7 +221,7 @@ | ||
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | private boolean metricsEnabled() { |
| 224 | - return manager.configuration().getMetricsOptions() != null; | |
| 224 | + return manager.configuration().getMetricsOptions().isEnabled(); | |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | private Metrics metrics() { |