Search in sources :

Example 1 with ICombinedContext

use of com.ibm.jvm.dtfjview.spi.ICombinedContext in project openj9 by eclipse.

the class Session method runInteractive.

// run in interactive mode with a prompt etc.
private void runInteractive() {
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    String input = "";
    String quit = "";
    out.println("For a list of commands, type \"help\"; " + "for how to use \"help\", type \"help help\"");
    while (quit == null || !quit.equals("on")) {
        if (ctxmgr.hasChanged()) {
            // a change means that a context has been added or closed
            if (currentContext instanceof CombinedContext) {
                int id = ((ICombinedContext) currentContext).getID();
                if (ctxmgr.getContext(id) == null) {
                    // the context that was previously the current one has been closed
                    findAndSetContextWithJVM();
                }
            } else {
                findAndSetContextWithJVM();
            }
            showContexts(true);
            setPrompt();
        }
        out.printPrompt(prompt);
        try {
            input = stdin.readLine();
        } catch (IOException e) {
            out.print("IOException encountered while reading input; exiting program...");
            break;
        }
        if (null == input) {
            out.print("End of input stream has been reached; exiting program...");
            break;
        }
        try {
            ToolsRegistry.recordAndExecute(input);
        } catch (com.ibm.jvm.dtfjview.tools.CommandException e) {
            out.println(e.getMessage());
        }
        quit = (String) currentContext.getProperties().get("quit");
    }
    // "out" MUST be closed here, otherwise the file deletions in the below
    // code block will not work
    out.close();
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ICombinedContext(com.ibm.jvm.dtfjview.spi.ICombinedContext) ICombinedContext(com.ibm.jvm.dtfjview.spi.ICombinedContext) IOException(java.io.IOException)

Example 2 with ICombinedContext

use of com.ibm.jvm.dtfjview.spi.ICombinedContext in project openj9 by eclipse.

the class Session method showContexts.

/* (non-Javadoc)
	 * @see com.ibm.jvm.dtfjview.spi.ISession#showContexts(boolean)
	 */
public void showContexts(boolean shortFormat) {
    out.println("Available contexts (* = currently selected context) : ");
    Map<URI, ArrayList<ICombinedContext>> contexts = ctxmgr.getContexts();
    if (contexts.size() == 0) {
        out.println("\n\tWARNING : no contexts were found");
        return;
    }
    URI currentSource = null;
    for (URI source : contexts.keySet()) {
        if (!source.equals(currentSource)) {
            out.println("\nSource : " + source.getScheme() + "://" + source.getPath() + (source.getFragment() != null ? "#" + source.getFragment() : ""));
            currentSource = source;
        }
        for (ICombinedContext context : contexts.get(source)) {
            if (context == currentContext) {
                out.print("\t*");
            } else {
                out.print("\t ");
            }
            context.displayContext(out, shortFormat);
        }
    }
    out.print("\n");
}
Also used : ArrayList(java.util.ArrayList) ICombinedContext(com.ibm.jvm.dtfjview.spi.ICombinedContext) URI(java.net.URI)

Example 3 with ICombinedContext

use of com.ibm.jvm.dtfjview.spi.ICombinedContext 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);
}
Also used : ICombinedContext(com.ibm.jvm.dtfjview.spi.ICombinedContext) CommandException(com.ibm.java.diagnostics.utils.commands.CommandException)

Example 4 with ICombinedContext

use of com.ibm.jvm.dtfjview.spi.ICombinedContext 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");
    }
}
Also used : ArrayList(java.util.ArrayList) ICombinedContext(com.ibm.jvm.dtfjview.spi.ICombinedContext) CommandException(com.ibm.java.diagnostics.utils.commands.CommandException)

Example 5 with ICombinedContext

use of com.ibm.jvm.dtfjview.spi.ICombinedContext in project openj9 by eclipse.

the class JdmpviewContextManager method removeContexts.

/* (non-Javadoc)
	 * @see com.ibm.jvm.dtfjview.spi.ISessionContextManager#removeContexts(java.net.URI)
	 */
public void removeContexts(URI source) {
    if (contextTracker.containsKey(source)) {
        for (ICombinedContext context : contextTracker.get(source)) {
            context.getImage().close();
        }
        contextTracker.remove(source);
        hasChanged = true;
    }
}
Also used : ICombinedContext(com.ibm.jvm.dtfjview.spi.ICombinedContext)

Aggregations

ICombinedContext (com.ibm.jvm.dtfjview.spi.ICombinedContext)7 CommandException (com.ibm.java.diagnostics.utils.commands.CommandException)2 ArrayList (java.util.ArrayList)2 Session (com.ibm.jvm.dtfjview.Session)1 ISession (com.ibm.jvm.dtfjview.spi.ISession)1 ISessionContextManager (com.ibm.jvm.dtfjview.spi.ISessionContextManager)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 URI (java.net.URI)1