Search in sources :

Example 1 with IConsoleCommand

use of de.janrufmonitor.framework.command.IConsoleCommand in project janrufmonitor by tbrandt77.

the class RunConsole method help.

public static void help() {
    System.out.println("Configuration must be done in janrufmonitor.properties.");
    System.out.println("");
    System.out.println("Help                - HELP + <ENTER>");
    String commands = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(RunConsole.NAMESPACE, "commands");
    StringTokenizer st = new StringTokenizer(commands, ",");
    while (st.hasMoreTokens()) {
        try {
            ICommand cmd = PIMRuntime.getInstance().getCommandFactory().getCommand(st.nextToken().trim());
            if (cmd != null && cmd instanceof IConsoleCommand && cmd.getLabel() != null) {
                System.out.println(cmd.getLabel());
            }
        } catch (NullPointerException e) {
        }
    }
    System.out.println("Re-start            - RESTART + <ENTER>");
    System.out.println("Quit                - QUIT + <ENTER>");
    System.out.println("");
}
Also used : StringTokenizer(java.util.StringTokenizer) ICommand(de.janrufmonitor.framework.command.ICommand) IConsoleCommand(de.janrufmonitor.framework.command.IConsoleCommand)

Example 2 with IConsoleCommand

use of de.janrufmonitor.framework.command.IConsoleCommand in project janrufmonitor by tbrandt77.

the class RunConsole method main.

public static void main(String[] args) {
    LoggingInitializer.run();
    Thread.currentThread().setContextClassLoader(JamCacheMasterClassLoader.getInstance());
    System.setProperty("jam.console", "true");
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Welcome to jAnrufmonitor 5 Console:");
    System.out.println("===================================");
    System.out.println("");
    try {
        start();
        help();
        prompt();
    } catch (NoClassDefFoundError e) {
        System.out.println("Updates have been installed. jAnrufmonitor needs to be restarted.");
        System.out.println("... have a nice day :-)");
        System.exit(0);
    }
    while (true) {
        try {
            String lineToBeSent = input.readLine();
            if (lineToBeSent.equalsIgnoreCase("quit")) {
                PIMRuntime.getInstance().shutdown();
                System.out.println("... have a nice day :-)");
                System.exit(0);
            } else if (lineToBeSent.toLowerCase().startsWith("help")) {
                help();
            } else if (lineToBeSent.toLowerCase().startsWith("restart")) {
                restart();
            } else {
                StringTokenizer st = new StringTokenizer(lineToBeSent, " ");
                if (st.countTokens() > 0) {
                    String command = st.nextToken().toLowerCase();
                    String[] arg = null;
                    if (st.hasMoreTokens()) {
                        int i = 0;
                        arg = new String[st.countTokens()];
                        while (st.hasMoreTokens()) {
                            arg[i] = st.nextToken();
                            i++;
                        }
                    }
                    ICommand cmd = PIMRuntime.getInstance().getCommandFactory().getCommand(command);
                    if (cmd != null && cmd instanceof IConsoleCommand) {
                        ((IConsoleCommand) cmd).setExecuteParams(arg);
                        if (cmd.isExecutable() && !cmd.isExecuting()) {
                            try {
                                cmd.execute();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        } else {
                            System.out.println("WARNING: Command " + lineToBeSent + " already executing. Please be patient.");
                        }
                    } else {
                        System.out.println("ERROR: Command " + lineToBeSent + " not found.");
                    }
                }
            }
            prompt();
        } catch (IOException ex) {
            System.out.println("ERROR: " + ex.getMessage());
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) InputStreamReader(java.io.InputStreamReader) ICommand(de.janrufmonitor.framework.command.ICommand) IConsoleCommand(de.janrufmonitor.framework.command.IConsoleCommand) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

ICommand (de.janrufmonitor.framework.command.ICommand)2 IConsoleCommand (de.janrufmonitor.framework.command.IConsoleCommand)2 StringTokenizer (java.util.StringTokenizer)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1