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 ca3fa8de20)
This commit is contained in:
Calle Wilund 2018-10-23 13:20:05 +00:00 committed by Avi Kivity
parent dbb3d44d69
commit 426b88b983
2 changed files with 43 additions and 6 deletions

View File

@ -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

View File

@ -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 {