Asynchronized query service.

@param commands
the StringCommand list.
@return
the ServiceDirectoryFuture.
326321
public ServiceDirectoryFuture asyncQueryService(List<StringCommand> commands){
        ProtocolHeader header = new ProtocolHeader();
        header.setType(ProtocolType.QueryService);

        List<QueryCommand> cs = new ArrayList<QueryCommand>();
        for(StringCommand c : commands){
            cs.add(c.getStringCommand());
        }

        QueryServiceProtocol p = new QueryServiceProtocol(cs);
        return connection.submitAsyncRequest(header, p, null);
    }
430027
public List<Command> getTopCommands(int count, String queueName)  {
        checkStarted();
        List<Command> res = new ArrayList<>();

        try(Session session = consumerConnection.createSession()) {
            Queue queue = (Queue) jmsServer.lookup(QUEUE_NAMESPACE + queueName);
            Enumeration messages = session.createBrowser(queue).getEnumeration();
            for(int i = 0; i < count && messages.hasMoreElements(); i++) {
                Command command;
                Message message = (Message) messages.nextElement();
                if(binaryMode){
                    command = Command.fromBytes(getBytes((BytesMessage) message));
                }else{
                    command = Command.fromXml(((TextMessage)message).getText());
                }
                command.setJMSMessageID(message.getJMSMessageID());
                res.add(command);
            }
            return res;
        } catch (Exception e) {
            throw new AsyncException("Could not lookup commands", e);
        }
    }
1050230
public Command findCommand(String name, ClassLoader cl) {
        synchronized (commandCache) {
            
            if (!commandCache.containsKey(name)) {
                
                try {
                    Command commandInstance = (Command) Class.forName(name, true, cl).newInstance();
                    commandCache.put(name, commandInstance);
                } catch (Exception ex) {
                    throw new IllegalArgumentException("Unknown Command implementation with name '" + name + "'");
                }
    
            } else {
                Command cmd = commandCache.get(name);
                if (!cmd.getClass().getClassLoader().equals(cl)) {
                    commandCache.remove(name);
                    try {
                        Command commandInstance = (Command) Class.forName(name, true, cl).newInstance();
                        commandCache.put(name, commandInstance);
                    } catch (Exception ex) {
                        throw new IllegalArgumentException("Unknown Command implementation with name '" + name + "'");
                    } 
                }
            }

       
        }
        return commandCache.get(name);
    }
855582
public void runPendingCommands() {
        List<Runnable> commandsToRun = commands;
        commands = new ArrayList<Runnable>();
    
        for (Runnable command: commandsToRun) {
            command.run();
        }
    }
546372
public CliCommandBuilder setCommands(final String... commands) {
        if (commands == null || commands.length == 0) {
            addCliArgument(CliArgument.COMMANDS, null);
            return this;
        }
        return setCommands(Arrays.asList(commands));
    }
702556
private OperationResult sequenceCommand(long index, long sequence, RaftSession session) {
    OperationResult result = session.getResult(sequence);
    if (result == null) {
      log.debug("Missing command result at index {}", index);
    }
    return result;
  }
1125285
private ServiceDirectoryCache<String, ModelService> getCache(){
        if(cache == null){
            synchronized (this) {
                if (this.cache == null) {
                    this.cache = new ServiceDirectoryCache<String, ModelService>();
                }
            }
        }
        return this.cache;
    }
585209
public List<CommandCallback> buildCommandCallback(CommandContext ctx, ClassLoader cl) {
        List<CommandCallback> callbackList = new ArrayList<CommandCallback>();
        if (ctx != null && ctx.getData("callbacks") != null) {
            logger.debug("Callback: {}", ctx.getData("callbacks"));
            String[] callbacksArray = ((String) ctx.getData("callbacks")).split(",");
            List<String> callbacks = (List<String>) Arrays.asList(callbacksArray);
            for (String callbackName : callbacks) {
                CommandCallback handler = findCommandCallback(callbackName.trim(), cl);
                callbackList.add(handler);
            }
        }
        return callbackList;
    }
698724
public static String exec(final String[] cmds, final long timeout) {
        try {
            final Process process = new ProcessBuilder(cmds).redirectErrorStream(true).start();
            final StringWriter writer = new StringWriter();
            new Thread(() -> {
                try {
                    IOUtils.copy(process.getInputStream(), writer, "UTF-8");
                } catch (final Exception e) {
                    LOGGER.log(Level.ERROR, "Reads input stream failed: " + e.getMessage());
                }
            }).start();

            if (!process.waitFor(timeout, TimeUnit.MILLISECONDS)) {
                LOGGER.log(Level.WARN, "Executes commands [" + Arrays.toString(cmds) + "] timeout");
                process.destroy();
            }

            return writer.toString();
        } catch (final Exception e) {
            LOGGER.log(Level.ERROR, "Executes commands [" + Arrays.toString(cmds) + "] failed", e);

            return null;
        }
    }
331740
public final synchronized String process(final IoSession session, final String... args) {
		if (this.message == null) {
			final StringBuffer strb = new StringBuffer();
			// Get all available Commands and get its usage
			final TcpCommand[] cmds = TcpIpCommands.getCommands().values().toArray(new TcpCommand[]{});
			Arrays.sort(cmds);
			for (TcpCommand cmd : cmds) {
				final String help = cmd.getHelp(); 
				if (help!=null && help.length()>0) {
					strb.append(help).append(TcpIpHandlerAdapter.ENDLINE);
				}
//				String usage = cmd.getUsage(); 
//				if (usage!=null && usage.length()>0) {
//					strb.append(usage).append(TcpIpHandlerAdapter.ENDLINE);
//				}
			}
			this.message=strb.toString();
		}
		return this.message;
	}
930898
public ProcessExecutor command(Iterable<String> command) {
    List<String> list = new ArrayList<String>();
    Iterator<String> it = command.iterator();
    while (it.hasNext()) {
      list.add(it.next());
    }
    return command(list);
  }
936842
public static List<String> execForLines(String... cmds) throws IORuntimeException {
		return execForLines(CharsetUtil.systemCharset(), cmds);
	}
504161
public synchronized ModelNode doCommand(String command) throws CommandFormatException, IOException {
        ModelNode request = cmdCtx.buildRequest(command);
        return execute(request, isSlowCommand(command)).getResponseNode();
    }
930040
public static CommandResult execCommand(List<String> commands, boolean isRoot, boolean isNeedResultMsg) {
        return execCommand(commands == null ? null : commands.toArray(new String[]{}), isRoot, isNeedResultMsg);
    }
678896
public static void exec(final boolean wait, final String command, final String... parms)
            throws IOException
   {
      String[] commandTokens = parms == null ? new String[1] : new String[parms.length + 1];
      commandTokens[0] = command;

      if (commandTokens.length > 1)
      {
         System.arraycopy(parms, 0, commandTokens, 1, parms.length);
      }

      Runtime.getRuntime().exec(commandTokens, null);
   }
751967
public void runCommands(final String[] commands) throws IOException {
		doLines(0, new LineReader() {
			private int commandC = 0;

			@Override
			public String getNextLine(String prompt) {
				if (commandC >= commands.length) {
					return null;
				} else {
					return commands[commandC++];
				}
			}
		}, true);
	}
515633
public DevCmdInfo_2 command_query_2(final String command) throws DevFailed, SystemException {
	Util.out4.println("Device_2Impl.command_query_2(" + command + ") arrived");

	// Retrieve number of command and allocate memory to send back info
	final int nb_cmd = device_class.get_command_list().size();
	Util.out4.println(nb_cmd + " command(s) for device");
	DevCmdInfo_2 back = null;
	for (int i = 0; i < nb_cmd; i++) {
	    final Command cmd = (Command) device_class.get_command_list().elementAt(i);
	    if (cmd.get_name().toLowerCase().equals(command.toLowerCase())) {
		final DevCmdInfo_2 tmp = new DevCmdInfo_2();
		tmp.cmd_name = cmd.get_name();
		tmp.cmd_tag = cmd.get_tag();
		tmp.level = cmd.get_disp_level();
		tmp.in_type = cmd.get_in_type();
		tmp.out_type = cmd.get_out_type();
		final String str_in = cmd.get_in_type_desc();
		if (str_in.length() != 0) {
		    tmp.in_type_desc = str_in;
		} else {
		    tmp.in_type_desc = Tango_DescNotSet;
		}
		final String str_out = cmd.get_out_type_desc();
		if (str_out.length() != 0) {
		    tmp.out_type_desc = str_out;
		} else {
		    tmp.out_type_desc = Tango_DescNotSet;
		}
		back = tmp;
	    }
	}

	// throw an exception to client if command not found
	if (back == null) {
	    Except.throw_exception("API_CommandNotFound", "Command " + command + " not found",
		    "Device_2Impl.command_query_2");
	}

	// Record operation request in black box
	blackbox.insert_op(Op_Command_list_2);

	Util.out4.println("Device_2Impl.command_list_query_2 exiting");
	return back;

    }