Elffuss BraidHub

kikocis/java-driver public

Fix Configuration builder to allow disabled metrics (JAVA-900).
Changeset75c486da29ccb5a3ca9c524bc9ac7421d7df16547bce2d1b8c07957c507adb48
Authorolim7t <omichallat+github@gmail.com> · 2015-10-07 14:36 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2015-10-13 11:29 +02:00
Parentsd0cf52e93999

Browse the files at this changeset

5 files changed

modified changelog/README.md +1 −0
@@ -6,6 +6,7 @@
66 - [bug] Fix implementation of UserType.hashCode() (JAVA-942)
77 - [improvement] Don't delay UP/ADDED notifications if protocol version = V4 (JAVA-877)
88 - [improvement] Parse 'extensions' column in table metadata (JAVA-938)
9+- [bug] Fix Configuration builder to allow disabled metrics (JAVA-900)
910
1011
1112 ### 3.0.0-alpha3
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +5 −4
@@ -396,8 +396,8 @@
396396 * The cluster metrics.
397397 *
398398 * @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}).
401401 */
402402 public Metrics getMetrics() {
403403 checkNotClosed(manager);
@@ -1202,7 +1202,8 @@
12021202 public Configuration getConfiguration() {
12031203 ProtocolOptions protocolOptions = new ProtocolOptions(port, protocolVersion, maxSchemaAgreementWaitSeconds, sslOptions, authProvider)
12041204 .setCompression(compression);
1205- MetricsOptions metricsOptions = metricsEnabled ? new MetricsOptions(jmxEnabled) : null;
1205+
1206+ MetricsOptions metricsOptions = new MetricsOptions(metricsEnabled, jmxEnabled);
12061207
12071208 return configurationBuilder
12081209 .withProtocolOptions(protocolOptions)
@@ -1328,7 +1329,7 @@
13281329 this.metadata = new Metadata(this);
13291330 this.connectionFactory = new Connection.Factory(this, configuration);
13301331 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;
13321333 this.preparedQueries = new MapMaker().weakValues().makeMap();
13331334
13341335 // 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 @@
3535
3636 /**
3737 * 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.
3841 *
3942 * @return the builder.
4043 */
@@ -209,6 +212,12 @@
209212
210213 /**
211214 * 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+ *
212221 * @param metricsOptions the metrics options.
213222 * @return this builder.
214223 */
modified driver-core/src/main/java/com/datastax/driver/core/MetricsOptions.java +17 −9
@@ -20,14 +20,14 @@
2020 */
2121 public class MetricsOptions {
2222
23+ private final boolean metricsEnabled;
2324 private final boolean jmxEnabled;
2425
2526 /**
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).
2728 */
28- public MetricsOptions()
29- {
30- this(true);
29+ public MetricsOptions() {
30+ this(true, true);
3131 }
3232
3333 /**
@@ -35,18 +35,26 @@
3535 *
3636 * @param jmxEnabled whether to enable JMX reporting or not.
3737 */
38- public MetricsOptions(boolean jmxEnabled)
39- {
38+ public MetricsOptions(boolean enabled, boolean jmxEnabled) {
39+ this.metricsEnabled = enabled;
4040 this.jmxEnabled = jmxEnabled;
4141 }
4242
4343 /**
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.
4554 *
4655 * @return whether JMX reporting is enabled.
4756 */
48- public boolean isJMXReportingEnabled()
49- {
57+ public boolean isJMXReportingEnabled() {
5058 return jmxEnabled;
5159 }
5260 }
modified driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java +1 −1
@@ -221,7 +221,7 @@
221221 }
222222
223223 private boolean metricsEnabled() {
224- return manager.configuration().getMetricsOptions() != null;
224+ return manager.configuration().getMetricsOptions().isEnabled();
225225 }
226226
227227 private Metrics metrics() {