Adding the APIMBeanServer
The APIMBeanServer is serve as a proxy for the MBeanServer. It intercept calls to the MBeanServer and check for the column family and stream registeration before they are perform. Current implementation override queryNames as it's the one that is being used by nodetool. Additional methods can be override in the future if needed. Signed-off-by: Amnon Heiman <amnon@scylladb.com>
This commit is contained in:
parent
645d04083c
commit
4e02c52aee
66
src/main/java/com/scylladb/jmx/utils/APIMBeanServer.java
Normal file
66
src/main/java/com/scylladb/jmx/utils/APIMBeanServer.java
Normal file
@ -0,0 +1,66 @@
|
||||
package com.scylladb.jmx.utils;
|
||||
|
||||
/**
|
||||
* Copyright 2016 ScyllaDB
|
||||
*/
|
||||
/*
|
||||
* This file is part of Scylla.
|
||||
*
|
||||
* Scylla is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Scylla is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
import javax.management.QueryExp;
|
||||
import org.apache.cassandra.db.ColumnFamilyStore;
|
||||
import org.apache.cassandra.metrics.StreamingMetrics;
|
||||
|
||||
import mx4j.server.ChainedMBeanServer;
|
||||
|
||||
public class APIMBeanServer extends ChainedMBeanServer {
|
||||
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
||||
.getLogger(APIMBeanServer.class.getName());
|
||||
|
||||
public static void log(String str) {
|
||||
logger.finest(str);
|
||||
}
|
||||
|
||||
public void setMBeanServer(MBeanServer server) {
|
||||
if (server != null) {
|
||||
try {
|
||||
Field f = server.getClass().getDeclaredField("introspector");
|
||||
f.setAccessible(true);
|
||||
f.set(server, new APIMBeanIntrospector());
|
||||
} catch (Exception e) {
|
||||
logger.warning(
|
||||
"Failed setting new interceptor" + e.getMessage());
|
||||
}
|
||||
}
|
||||
super.setMBeanServer(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {
|
||||
if (name.getCanonicalKeyPropertyListString()
|
||||
.contains("ColumnFamilies")) {
|
||||
ColumnFamilyStore.checkRegistration();
|
||||
} else if (name.getCanonicalKeyPropertyListString()
|
||||
.contains("Stream")) {
|
||||
StreamingMetrics.checkRegistration();
|
||||
}
|
||||
return super.queryNames(name, query);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user