Package org.apache.felix.service.command

Examples of org.apache.felix.service.command.CommandSession


                                   wrap(out),
                                   wrap(err),
                                   terminal,
                                   encoding,
                                   callback);
        CommandSession session = console.getSession();
        session.put("USER", user);
        session.put("APPLICATION", System.getProperty("karaf.name", "root"));
        session.put("#LINES", new Function() {
            public Object execute(CommandSession session, List<Object> arguments) throws Exception {
                return Integer.toString(terminal.getHeight());
            }
        });
        session.put("#COLUMNS", new Function() {
            public Object execute(CommandSession session, List<Object> arguments) throws Exception {
                return Integer.toString(terminal.getWidth());
            }
        });
        if (ctype != null) {
            session.put("LC_CTYPE", ctype);
        }
        session.put(".jline.terminal", terminal);
        session.put(SshAgent.SSH_AUTHSOCKET_ENV_NAME, agentId);
        session.put("pid", getPid());

        boolean delayconsole = Boolean.parseBoolean(System.getProperty("karaf.delay.console"));
        if (delayconsole) {
            new DelayedStarted(this.console, bundleContext, unwrappedIn).start();
        } else {
View Full Code Here


        public String printHelp(String format, boolean includeHelpOption) throws Exception {
            PrintStream oldout = System.out;
            try {
                Action action = actionClass.newInstance();
                CommandSession session = new DummyCommandSession();
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                PrintStream newout = new PrintStream(baos);
                System.setOut(newout);
                ActionPreparator preparator;
                if (FORMAT_DOCBX.equals(format)) {
View Full Code Here

    protected String executeCommand(final String command, final Long timeout, final Boolean silent) {
            String response;
            final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            final PrintStream printStream = new PrintStream(byteArrayOutputStream);
            final CommandSession commandSession = commandProcessor.createSession(System.in, printStream, printStream);
            commandSession.put("APPLICATION", System.getProperty("karaf.name", "root"));
            commandSession.put("USER", USER);
            FutureTask<String> commandFuture = new FutureTask<String>(
                    new Callable<String>() {
                        public String call() {
                            try {
                                if (!silent) {
                                    System.out.println(command);
                                    System.out.flush();
                                }
                                commandSession.execute(command);
                            } catch (Exception e) {
                                e.printStackTrace(System.err);
                            }
                            printStream.flush();
                            return byteArrayOutputStream.toString();
View Full Code Here

                CommandProcessor cp = (CommandProcessor) shell;
                if(sessionOp == null) {
                    if("asadmin-osgi-shell".equals(cmdName)) {
                        out.println("gogo");
                    } else {
                        CommandSession session = cp.createSession(in, out, err);
                        session.execute(cmd);
                        session.close();
                    }
                } else if("new".equals(sessionOp)) {
                    CommandSession session = cp.createSession(null, null, null);
                    RemoteCommandSession remote = new RemoteCommandSession(session);

                    log.log(Level.FINE, "Remote session established: {0}",
                            remote.getId());

                    sessions.put(remote.getId(), remote);
                    out.println(remote.getId());
                } else if("list".equals(sessionOp)) {
                    for(String id : sessions.keySet()) {
                        out.println(id);
                    }
                } else if("execute".equals(sessionOp)) {
                    RemoteCommandSession remote = sessions.get(sessionId);
                    CommandSession session = remote.attach(in, out, err);
                    session.execute(cmd);
                    remote.detach();
                } else if("stop".equals(sessionOp)) {
                    RemoteCommandSession remote = sessions.remove(sessionId);
                    CommandSession session = remote.attach(in, out, err);
                    session.close();

                    log.log(Level.FINE, "Remote session closed: {0}",
                            remote.getId());
                }
            }
View Full Code Here

    private static final String ALIAS = "--pid";

    private ConfigurationAdmin configAdmin;

    public int complete(final String buffer, final int cursor, final List candidates) {
        CommandSession session = CommandSessionHolder.getSession();
        if (session != null) {
            String pid = getPid(session);
            Set<String> propertyNames = getPropertyNames(pid);
            delegate.getStrings().clear();
            if (propertyNames != null && !propertyNames.isEmpty()) {
View Full Code Here

        ArgumentList list = delimit(buffer, cursor);
        int argpos = list.getArgumentPosition();
        int argIndex = list.getCursorArgumentIndex();

        //Store the argument list so that it can be used by completers.
        CommandSession commandSession = CommandSessionHolder.getSession();
        if(commandSession != null) {
            commandSession.put(ARGUMENTS_LIST,list);
        }

        Completer comp = null;
        String[] args = list.getArguments();
        int index = 0;
View Full Code Here

        String script = scriptDefinition.get(SCRIPT_KEY);
        if (script == null) {
            throw new IllegalArgumentException("Script definition *must* define at least a 'script' property!");
        }

        CommandSession session = m_processor.createSession(System.in, System.out, System.err);
        try {
            Object scriptResult = session.execute(script);
            m_logger.log(LogService.LOG_DEBUG, "Script output:\n" + scriptResult);
        }
        finally {
            session.close();
        }
    }
View Full Code Here

        }
    }

    @Descriptor("executes a script definition")
    public void execute(CommandSession session, @Descriptor("the script to execute, multiple commands should be separated by semicolons") String script) throws Exception {
        CommandSession newSession = m_processor.createSession(session.getKeyboard(), session.getConsole(), System.err);
        try {
            newSession.execute(script);
        }
        finally {
            newSession.close();
        }
    }
View Full Code Here

            m_scriptPath = scriptPath;
        }

        @Override
        public void run() {
            CommandSession session = null;
            BufferedReader reader = null;
            String line;

            try {
                reader = new BufferedReader(new FileReader(new File(m_scriptPath)));
                StringBuilder builder = new StringBuilder();
                while ((line = reader.readLine()) != null)
                    builder.append(line).append("\n");

                session = m_processor.createSession(System.in, System.out, System.err);
                session.execute(builder.toString());
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            finally {
                if (session != null) {
                    session.close();
                }
                if (reader != null) {
                    try {
                        reader.close();
                    }
View Full Code Here

    @Override
    @SuppressWarnings({
        "rawtypes", "unchecked"
    })
    public int complete(String buffer, int cursor, List candidates) {
        CommandSession session = CommandSessionHolder.getSession();
        ArgumentCompleter.ArgumentList list = (ArgumentCompleter.ArgumentList)session.get(ArgumentCompleter.ARGUMENTS_LIST);
        switch (list.getCursorArgumentIndex()) {
        case 1:
            synchronized (getStrings()) {
                getStrings().clear();
                getStrings().addAll(slt.getServiceNames(true));
View Full Code Here

TOP

Related Classes of org.apache.felix.service.command.CommandSession

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.