Package org.jboss.as.cli

Examples of org.jboss.as.cli.CommandContext


        File file = new File(path);
        if (!file.exists() || !file.isFile()) {
            throw new IllegalArgumentException(path + " is not a valid CLI script file");
        }

        final CommandContext cmdCtx = CommandContextFactory
                                        .getInstance()
                                        .newCommandContext(
                                                HOST
                                                , PORT
                                                , USER
                                                , PASSWORD != null ? PASSWORD.toCharArray() : null
                                                , NO_LOCAL_AUTH
                                                , INIT_CONSOLE
                                                , CONNECTION_TIMEOUT);
        if (_logger.isDebugEnabled()) {
            cmdCtx.addEventListener(new CliEventListener() {
                @Override
                public void cliEvent(CliEvent event, CommandContext ctx) {
                    _logger.debug("CLI Event: " + event.toString());
                }
            });
        }
        cmdCtx.connectController();
       
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(file));
            _logger.info("Executing CLI script file: " + path);
            String line = reader.readLine();
            while (cmdCtx.getExitCode() == 0 && !cmdCtx.isTerminated() && line != null) {
                if (_logger.isDebugEnabled()) {
                    _logger.debug(">>> " + line.trim());
                }
                cmdCtx.handleSafe(line.trim());
                line = reader.readLine();
            }
        } finally {
            StreamUtils.safeClose(reader);
            cmdCtx.terminateSession();
            _logger.info("CLI session is terminated with exit code '" + cmdCtx.getExitCode() + "'");
        }
    }
View Full Code Here

TOP

Related Classes of org.jboss.as.cli.CommandContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.