/* * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code 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 * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * Executes Diagnostic Commands on the target VM (specified by a host/port combination or a full JMX Service URL) using * the JMX interface. If the target is not the current VM, the JMX Remote interface must be enabled beforehand.
*/ publicclass JMXExecutor extends CommandExecutor {
privatefinal MBeanServerConnection mbs;
/** * Instantiates a new JMXExecutor targeting the current VM
*/ public JMXExecutor() { super();
mbs = ManagementFactory.getPlatformMBeanServer();
}
/** * Instantiates a new JMXExecutor targeting the VM indicated by the given host/port combination or a full JMX * Service URL * * @param target a host/port combination on the format "host:port" or a full JMX Service URL of the target VM
*/ public JMXExecutor(String target) {
String urlStr;
/* Failures on the "local" side, the one invoking the command. */ catch (ReflectionException e) {
Throwable cause = e.getCause(); if (cause instanceof NoSuchMethodException) { /* We want JMXExecutor to match the behavior of the other CommandExecutors */
String message = "Unknown diagnostic command: " + operation;
stderr = exceptionTraceAsString(new IllegalArgumentException(message, e));
} else {
rethrowExecutorException(operation, dcmdArgs, e);
}
}
/* Failures on the "local" side, the one invoking the command. */ catch (InstanceNotFoundException | IOException e) {
rethrowExecutorException(operation, dcmdArgs, e);
}
/* Failures on the remote side, the one executing the invoked command. */ catch (MBeanException e) {
stdout = exceptionTraceAsString(e);
}
/** * Convert from diagnostic command to MBean method name * * Examples: * help --> help * VM.version --> vmVersion * VM.command_line --> vmCommandLine
*/ privatestatic String commandToMethodName(String cmd) {
String operation = ""; boolean up = false; /* First letter is to be lower case */
/* * If a '.' or '_' is encountered it is not copied, * instead the next character will be converted to upper case
*/ for (char c : cmd.toCharArray()) { if (('.' == c) || ('_' == c)) {
up = true;
} elseif (up) {
operation = operation.concat(Character.toString(c).toUpperCase());
up = false;
} else {
operation = operation.concat(Character.toString(c).toLowerCase());
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.