本文整理汇总了Java中org.apache.felix.service.command.CommandSession类的典型用法代码示例。如果您正苦于以下问题:Java CommandSession类的具体用法?Java CommandSession怎么用?Java CommandSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommandSession类属于org.apache.felix.service.command包,在下文中一共展示了CommandSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getType
import org.apache.felix.service.command.CommandSession; //导入依赖的package包/类
private UsesArtifactCommand.SearchType getType() {
final CommandSession session = CommandSessionHolder.getSession();
if (session == null) {
return null;
}
final ArgumentCompleter.ArgumentList argList = (ArgumentCompleter.ArgumentList) session
.get(ArgumentCompleter.ARGUMENTS_LIST);
if (argList == null || argList.getArguments() == null || argList.getArguments().length == 0) {
return null;
}
final List<String> arguments = Arrays.asList(argList.getArguments());
int argumentOffset = 1; // command is first argument
for (int index = 0, count = arguments.size(); index < count; ++index) {
if (arguments.get(index).startsWith("-")) {
argumentOffset = index;
}
}
// XXX: assuming the last option does not accept a value here
if (argumentOffset < arguments.size()) {
return UsesArtifactCommand.SearchType.valueOf(arguments.get(argumentOffset));
}
return null;
}
示例2: getType
import org.apache.felix.service.command.CommandSession; //导入依赖的package包/类
private ShowMetricsCommand.SearchType getType() {
final CommandSession session = CommandSessionHolder.getSession();
if (session == null) {
return null;
}
final ArgumentCompleter.ArgumentList argList = (ArgumentCompleter.ArgumentList) session
.get(ArgumentCompleter.ARGUMENTS_LIST);
if (argList == null || argList.getArguments() == null || argList.getArguments().length == 0) {
return null;
}
final List<String> arguments = Arrays.asList(argList.getArguments());
int argumentOffset = 1; // command is first argument
for (int index = 0, count = arguments.size(); index < count; ++index) {
if (arguments.get(index).startsWith("-")) {
argumentOffset = index;
}
}
if (argumentOffset < arguments.size()) {
return ShowMetricsCommand.SearchType.valueOf(arguments.get(argumentOffset));
}
return null;
}
示例3: getType
import org.apache.felix.service.command.CommandSession; //导入依赖的package包/类
private ResetMetricsCommand.SearchType getType() {
final CommandSession session = CommandSessionHolder.getSession();
if (session == null) {
return null;
}
final ArgumentCompleter.ArgumentList argList = (ArgumentCompleter.ArgumentList) session
.get(ArgumentCompleter.ARGUMENTS_LIST);
if (argList == null || argList.getArguments() == null || argList.getArguments().length == 0) {
return null;
}
final List<String> arguments = Arrays.asList(argList.getArguments());
int argumentOffset = 1; // command is first argument
for (int index = 0, count = arguments.size(); index < count; ++index) {
if (arguments.get(index).startsWith("-")) {
argumentOffset = index;
}
}
if (argumentOffset < arguments.size()) {
return ResetMetricsCommand.SearchType.valueOf(arguments.get(argumentOffset));
}
return null;
}
示例4: filter
import org.apache.felix.service.command.CommandSession; //导入依赖的package包/类
@Descriptor("Apply a filter on a set of Resource")
public void filter(@Descriptor("automatically supplied shell session") CommandSession session,
@Descriptor("request for the filter creation") String request
) {
System.out.println("Request " + request);
ListResourceContainer listResourceContainer = (ListResourceContainer) session.get(LISTRESOURCE);
if ( listResourceContainer == null){
System.out.println(" NO ENTRY TO FILTER ");
return;
}
try{
QueryFilter parserQuery = new QueryFilter(request,m_everestClient.getM_everest());
ResourceFilter resourceFilter = parserQuery.input();
ListResourceContainer filterResourceList = listResourceContainer.filter(resourceFilter);
printResource(filterResourceList);
session.put(LISTRESOURCE,filterResourceList);
}catch (Exception e){
e.printStackTrace();
}
}
示例5: testNoProcessesRunning
import org.apache.felix.service.command.CommandSession; //导入依赖的package包/类
@Test
public void testNoProcessesRunning() throws Exception {
final ProcessEngine processEngine = newProcessEngineMock(Collections.<ProcessInstance>emptyList());
ListPoolsCommand command = new ListPoolsCommand(processEngine);
command.setOut(out);
CommandSession session = mock(CommandSession.class);
command.execute(session);
out.flush();
assertThat(outputStream.toString()).containsIgnoringCase("no active pools found");
outputStream.reset();
command.setKey("dummy");
command.execute(session);
out.flush();
assertThat(outputStream.toString()).containsIgnoringCase("no active pools found");
}
示例6: testListServices
import org.apache.felix.service.command.CommandSession; //导入依赖的package包/类
@Test
public void testListServices() throws Exception {
List<Provisionr> services = ImmutableList.of(
newProvisionrMockWithId("p1"),
newProvisionrMockWithId("p2")
);
ListServicesCommand command = new ListServicesCommand(services);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream out = new PrintStream(outputStream);
command.setOut(out);
CommandSession session = mock(CommandSession.class);
command.execute(session);
out.close();
for (Provisionr service : services) {
verify(service).getId();
}
assertThat(outputStream.toString()).isEqualTo("Services: p1, p2\n");
}
示例7: 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;
}
示例8: execute
import org.apache.felix.service.command.CommandSession; //导入依赖的package包/类
@Override
public Object execute( final CommandSession session ) throws Exception
{
try
{
Command command = this.getClass().getAnnotation( Command.class );
log.debug( String.format( "Executing command: %s:%s", command.scope(), command.name() ) );
return doExecute();
}
finally
{
ungetServices();
}
}
示例9: 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();
}
}
示例10: canDoExecute
import org.apache.felix.service.command.CommandSession; //导入依赖的package包/类
@Test
public void canDoExecute() throws Exception {
FabricService service = Mockito.mock(FabricService.class);
Action action = new ContainerStatusAction(service);
action.execute(Mockito.mock(CommandSession.class));
}
示例11: logt
import org.apache.felix.service.command.CommandSession; //导入依赖的package包/类
@Descriptor("Trace the log")
public void logt(CommandSession session) throws IOException {
PrintStream console = session.getConsole();
logTracker.addConsole(console);
try {
session.getKeyboard().read();
} finally {
logTracker.removeConsole(console);
}
}
示例12: execute
import org.apache.felix.service.command.CommandSession; //导入依赖的package包/类
public Object execute(CommandSession session) throws Exception {
List<DataPoint> dps = dpService.getAll();
for (DataPoint dp : dps) {
System.out.println(dp.getId() + ", " + dp.getName());
}
return null;
}
示例13: execute
import org.apache.felix.service.command.CommandSession; //导入依赖的package包/类
public Object execute(CommandSession session) throws Exception {
Map<Number, DefaultRevisionEntity> revisions = dpService.getRevisions(Long.valueOf( id ));
for (Number revisionNum : revisions.keySet()) {
DefaultRevisionEntity dre = revisions.get( revisionNum );
System.out.println(revisionNum + ": " + dre.getId() + ", " + dre.getTimestamp());
}
return null;
}
示例14: relation
import org.apache.felix.service.command.CommandSession; //导入依赖的package包/类
@Descriptor("Get Resource target by relation/relations of a resource")
public void relation( @Descriptor("automatically supplied shell session") CommandSession session,
@Descriptor("create") String... handleId
) {
String bufferOut = new String();
try {
String path;
if (handleId.length == 0) {
bufferOut = bufferOut + "Error : Must have at least 1 argument \n";
} else if (handleId.length == 1) {
path = handleId[0];
List<Resource> resources = m_everestClient.read(path).relations().retrieve();
session.put(LISTRESOURCE,m_everestClient.read(path).relations());
printResource(resources);
} else {
path = handleId[0];
for (String currentString : handleId) {
if (!(currentString.equalsIgnoreCase(handleId[0]))) {
Resource resource = m_everestClient.read(path).relation(currentString).retrieve();
printResource(resource);
} else {
bufferOut = bufferOut + "\nNo relation named :\"" + currentString + "\"\n";
}
}
}
} catch (Exception e) {
System.out.println(bufferOut);
e.printStackTrace();
bufferOut = null;
}
System.out.println(bufferOut);
}
示例15: testProvisioningServiceNotFound
import org.apache.felix.service.command.CommandSession; //导入依赖的package包/类
@Test(expected = NoSuchElementException.class)
public void testProvisioningServiceNotFound() throws Exception {
CreatePoolCommand command = new CreatePoolCommand(Collections.<Provisionr>emptyList(),
Collections.<PoolTemplate>emptyList(), PATH_TO_PUBLIC_KEY, PATH_TO_PRIVATE_KEY);
command.setId("dummy");
CommandSession session = mock(CommandSession.class);
command.execute(session);
}