当前位置: 首页>>代码示例>>Java>>正文


Java CommandSession.execute方法代码示例

本文整理汇总了Java中org.apache.felix.service.command.CommandSession.execute方法的典型用法代码示例。如果您正苦于以下问题:Java CommandSession.execute方法的具体用法?Java CommandSession.execute怎么用?Java CommandSession.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.felix.service.command.CommandSession的用法示例。


在下文中一共展示了CommandSession.execute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeCommandWithResponse

import org.apache.felix.service.command.CommandSession; //导入方法依赖的package包/类
public Object executeCommandWithResponse(String command) throws Exception {
	// Run some commands to make sure they are installed properly
	ByteArrayOutputStream outputError = new ByteArrayOutputStream();
	PrintStream psE = new PrintStream(outputError);
	ByteArrayOutputStream output = new ByteArrayOutputStream();
	PrintStream ps = new PrintStream(output);
	CommandSession cs = commandProcessor.createSession(System.in, ps, psE);
	Object commandOutput = null;
	try {
		commandOutput = cs.execute(command);
		return commandOutput;
	} catch (IllegalArgumentException e) {
		Assert.fail("Action should have thrown an exception because: " + e.toString());
	} catch (NoSuchMethodException a) {
		log.error("Method for command not found: " + a.getLocalizedMessage());
		Assert.fail("Method for command not found.");
	} finally {
		cs.close();
	}
	return commandOutput;
}
 
开发者ID:dana-i2cat,项目名称:opennaas-routing-nfv,代码行数:22,代码来源:ConnectionsKarafCommandsTest.java

示例2: perform

import org.apache.felix.service.command.CommandSession; //导入方法依赖的package包/类
private void perform(final String commandLine) throws Exception {
    if("shutdown".equals(commandLine)) {
        context.getBundle(0).stop();
        return;
    }

    ByteArrayOutputStream sysOut = new ByteArrayOutputStream();
    ByteArrayOutputStream sysErr = new ByteArrayOutputStream();

    final PrintStream printStreamOut = new PrintStream(sysOut);
    final PrintStream printErrOut = new PrintStream(sysErr);
    try {
        final CommandSession commandSession = commandProcessor.createSession(System.in, printStreamOut, printErrOut);
        Object result = commandSession.execute(commandLine);

        if(result != null) {
            printStreamOut.println(commandSession.format(result, Converter.INSPECT));
        }

        if(sysOut.size() > 0) {
            LOGGER.log(Level.INFO, new String(sysOut.toByteArray()));
        }

        if(sysErr.size() > 0) {
            LOGGER.log(Level.SEVERE, new String(sysErr.toByteArray()));
        }
    }
    catch(Throwable ex) {
        LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
    }
    finally {
        printStreamOut.close();
        printErrOut.close();
    }
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:36,代码来源:FelixDelegator.java

示例3: executeCommand

import org.apache.felix.service.command.CommandSession; //导入方法依赖的package包/类
protected List<String> executeCommand(String command, CommandProcessor cp) throws Exception
{
	boolean notfound;
	int notfoundCounter = 0;

	// Run some commands to make sure they are installed properly
	ByteArrayOutputStream outputError = new ByteArrayOutputStream();
	PrintStream psE = new PrintStream(outputError);
	ByteArrayOutputStream output = new ByteArrayOutputStream();
	PrintStream ps = new PrintStream(output);

	CommandSession cs = cp.createSession(System.in, ps, psE);

	ArrayList<String> outputs = new ArrayList<String>();

	do {
		try {
			cs.execute(command);
			outputs.add(output.toString());
			outputs.add(outputError.toString());
			cs.close();
			notfound = false;
		} catch (CommandNotFoundException nfe) {
			notfound = true;
			notfoundCounter++;
			if (notfoundCounter > 50) {
				throw nfe;
			}
			Thread.sleep(200);
		} catch (IllegalArgumentException e) {
			// throw new IllegalArgumentException("Action should have thrown an exception because: " + e.toString());
			notfound = true;
			notfoundCounter++;
			if (notfoundCounter > 50) {
				throw e;
			}
			Thread.sleep(200);
		} catch (NoSuchMethodException a) {
			// log.error("Method for command not found: " + a.getLocalizedMessage());
			throw new NoSuchMethodException("Method for command not found.");
		}
	} while (notfound);

	return outputs;
}
 
开发者ID:dana-i2cat,项目名称:opennaas-routing-nfv,代码行数:46,代码来源:AbstractKarafCommandTest.java


注:本文中的org.apache.felix.service.command.CommandSession.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。