From 426b88b9831a227296d89c9f3948fec2cdcf2669 Mon Sep 17 00:00:00 2001 From: Calle Wilund Date: Tue, 23 Oct 2018 13:20:05 +0000 Subject: [PATCH] scylla-jmx: Fix tablemetricsobjectname breakage Fixes #57 The usage of TableMetricsObjectName-yada-yada relies on translating the "fake" objectname to a canonical one on remote publication/serialization. However, the implementation of ObjectName.getInstance has changed in JDK (micro) updates so it no longer applies overridable methods -> wrong name published. Fix by doing explicit ObjectName instansiation. Message-Id: <20181023132005.23099-1-calle@scylladb.com> (cherry picked from commit ca3fa8de208f6b39a06a6c6f74fd3a542d4cfaaa) --- .../scylladb/jmx/utils/APIMBeanServer.java | 11 +++++- .../cassandra/metrics/TableMetrics.java | 38 ++++++++++++++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/scylladb/jmx/utils/APIMBeanServer.java b/src/main/java/com/scylladb/jmx/utils/APIMBeanServer.java index ff84101..7e8b781 100644 --- a/src/main/java/com/scylladb/jmx/utils/APIMBeanServer.java +++ b/src/main/java/com/scylladb/jmx/utils/APIMBeanServer.java @@ -53,7 +53,16 @@ public class APIMBeanServer implements MBeanServer { } private static ObjectName prepareForRemote(final ObjectName n) { - return ObjectName.getInstance(n); + /* + * ObjectName.getInstance has changed in JDK (micro) updates so it no longer applies + * overridable methods -> wrong name published. + * Fix by doing explicit ObjectName instansiation. + */ + try { + return new ObjectName(n.getCanonicalName()); + } catch (MalformedObjectNameException e) { + throw new IllegalArgumentException(n.toString()); + } } @Override diff --git a/src/main/java/org/apache/cassandra/metrics/TableMetrics.java b/src/main/java/org/apache/cassandra/metrics/TableMetrics.java index 8bdd489..00af96c 100644 --- a/src/main/java/org/apache/cassandra/metrics/TableMetrics.java +++ b/src/main/java/org/apache/cassandra/metrics/TableMetrics.java @@ -297,17 +297,16 @@ public class TableMetrics implements Metrics { @SuppressWarnings("serial") static class TableMetricObjectName extends javax.management.ObjectName { - private static final String FAKE_NAME = "a:a=a"; - private final TableMetricStringNameFactory factory; private final String metricName; public TableMetricObjectName(TableMetricStringNameFactory factory, String metricName) throws MalformedObjectNameException { - super(FAKE_NAME); + super(""); this.factory = factory; this.metricName = metricName; } + @Override public boolean isPropertyValuePattern(String property) { return false; @@ -356,8 +355,7 @@ public class TableMetrics implements Metrics { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof TableMetricObjectName)) return false; - return getCanonicalName().equals(((TableMetricObjectName) o).getCanonicalName()); + return getCanonicalName().equals(((ObjectName) o).getCanonicalName()); } @Override @@ -372,6 +370,36 @@ public class TableMetrics implements Metrics { } return getCanonicalName().equals(name.getCanonicalName()); } + + + @Override + public boolean isPattern() { + return false; + } + + + @Override + public boolean isDomainPattern() { + return false; + } + + + @Override + public boolean isPropertyPattern() { + return false; + } + + + @Override + public boolean isPropertyListPattern() { + return false; + } + + + @Override + public boolean isPropertyValuePattern() { + return false; + } } static interface TableMetricStringNameFactory {