use of com.ibm.java.diagnostics.utils.commands.CommandException in project openj9 by eclipse.
the class DTFJContext method refresh.
/**
* Refresh this context.
*/
public void refresh() {
// used to detect command name clashes
ArrayList<String> names = new ArrayList<String>();
commands.clear();
loadedPlugins.clear();
failedPlugins.clear();
// these are the only hardwired commands that are always available within any context
addGlobalCommandsToContext();
PluginManager pluginManager = PluginManagerLocator.getManager();
DTFJPluginManager manager = new DTFJPluginManager(pluginManager);
try {
pluginManager.refreshSearchPath();
pluginManager.scanForClassFiles();
} catch (CommandException e) {
// may catch a CommandException when loading plugins
logger.log(Level.FINE, "Problem loading DTFJ View plugins: " + e.getMessage());
logger.log(Level.FINEST, "Problem loading DTFJ View plugins: ", e);
}
ClassLoader thisloader = this.getClass().getClassLoader();
if (thisloader == null) {
thisloader = ClassLoader.getSystemClassLoader();
}
LocalPriorityClassloader loader = new LocalPriorityClassloader(pluginManager.getClasspath(), thisloader);
for (PluginConfig config : manager.getPlugins(apiLevel, hasImage, (rt != null))) {
try {
ICommand cmd = config.newInstance(loader);
loadedPlugins.add(config);
for (String cmdname : cmd.getCommandNames()) {
// check for a name space clash i.e. two plugins could potentially be invoked by a single command
if (names.contains(cmdname)) {
logger.fine("Name space clash detected for " + config.getClassName() + ". The command name " + cmdname + " is already in use");
} else {
names.add(cmdname);
}
}
commands.add(cmd);
} catch (CommandException e) {
failedPlugins.add(config);
logger.log(Level.FINE, "Failed to create a new plugin instance for " + config.getClassName());
logger.log(Level.FINEST, "Failed to create a new plugin instance: ", e);
}
}
}
use of com.ibm.java.diagnostics.utils.commands.CommandException in project openj9 by eclipse.
the class PluginConfig method newInstance.
public ICommand newInstance(ClassLoader loader) throws CommandException {
ClassInfo info = entry.getData();
try {
Class<?> clazz = Class.forName(info.getClassname(), true, loader);
Object instance = clazz.newInstance();
if (instance instanceof BaseCommand) {
((BaseCommand) instance).setConfig(this);
}
return (ICommand) instance;
} catch (Throwable e) {
// have to use Throwable here to catch things like class not found errors
t = e;
throw new CommandException("Failed to create a new instance of command " + info.getClassname(), e);
}
}
use of com.ibm.java.diagnostics.utils.commands.CommandException in project openj9 by eclipse.
the class CombinedContext method initJdmpviewCommand.
/*
* Commands / plugins that inherit from the BaseJdmpviewCommand class need to have
* their initialisation methods fired, which validates the context type and sets
* up various instance level fields. Commands that directly implement the DTFJ
* plugin interfaces will be ignored.
*/
private boolean initJdmpviewCommand(CommandParser parser, PrintStream out) throws CommandException {
for (ICommand command : commands) {
if (command.recognises(parser.getCommand(), this)) {
try {
/*
* This work-around is needed because the BaseJdmpviewCommand is loaded in both the
* CombinedContext classloader and in the classloader which is running the command. This
* means that a simple instanceof check will not work
* i.e. (command instanceof BaseJdmpviewCommand) fails as it's comparing the base command from
* two different classloaders. Solution is to use the same classloader as the command
* to get the BaseJdmpviewCommand class and then use reflection to invoke it.
*/
Class<?> base = command.getClass().getClassLoader().loadClass(BaseJdmpviewCommand.class.getName());
if (base.isAssignableFrom(command.getClass())) {
Method method = base.getMethod("initCommand", new Class<?>[] { String.class, String[].class, IContext.class, PrintStream.class });
Object result = method.invoke(command, parser.getCommand(), parser.getArguments(), this, out);
return (Boolean) result;
}
} catch (Exception e) {
out.println("Error initialising command : " + parser.getOriginalLine() + " (" + e.getMessage() + ")");
logger.log(Level.FINE, "Error initialising command : " + parser.getOriginalLine(), e);
}
}
}
return false;
}
use of com.ibm.java.diagnostics.utils.commands.CommandException in project openj9 by eclipse.
the class Session method setContext.
/* (non-Javadoc)
* @see com.ibm.jvm.dtfjview.spi.ISession#setContext(int)
*/
public void setContext(int id) throws CommandException {
ICombinedContext switchTo = ctxmgr.getContext(id);
if (switchTo == null) {
throw new CommandException("The specified context ID of " + id + " is not valid. Execute \"" + CMD_CONTEXT + "\" to see the list of valid IDs.");
}
setContext(switchTo);
}
use of com.ibm.java.diagnostics.utils.commands.CommandException in project openj9 by eclipse.
the class Session method findAndSetContextWithJVM.
/* (non-Javadoc)
* @see com.ibm.jvm.dtfjview.spi.ISession#findAndSetContextWithJVM()
*/
public void findAndSetContextWithJVM() {
try {
// try and set the starting context as the first one with a JVM in it
Collection<ArrayList<ICombinedContext>> sources = ctxmgr.getContexts().values();
if (sources.size() == 0) {
// there are no sources or contexts available so set to the root context
// failed to find a context with a runtime in so set to the root
currentContext = ctxroot;
return;
}
// this is what the context will be set to if none of the remaining ones contain a jvm
ICombinedContext defaultContext = null;
for (ArrayList<ICombinedContext> contexts : sources) {
for (ICombinedContext context : contexts) {
if (defaultContext == null) {
defaultContext = context;
}
if (context.getRuntime() != null) {
setContext(context);
return;
}
}
}
setContext(defaultContext);
} catch (CommandException e) {
out.print("ERROR : Unable to set current context");
}
}
Aggregations