本文整理汇总了Java中oshi.software.os.OperatingSystem.ProcessSort方法的典型用法代码示例。如果您正苦于以下问题:Java OperatingSystem.ProcessSort方法的具体用法?Java OperatingSystem.ProcessSort怎么用?Java OperatingSystem.ProcessSort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oshi.software.os.OperatingSystem
的用法示例。
在下文中一共展示了OperatingSystem.ProcessSort方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRoot
import oshi.software.os.OperatingSystem; //导入方法依赖的package包/类
@GET
@RolesAllowed(BasicAuthorizer.AUTHENTICATED_ROLE)
public ProcessInfo getRoot(@Auth UserConfiguration user, @QueryParam("sortBy") Optional<String> processSort, @QueryParam("limit") Optional<Integer> limit) {
OperatingSystem.ProcessSort sortBy = OperatingSystem.ProcessSort.NAME;
if (processSort.isPresent()) {
String method = processSort.get().toUpperCase();
try {
sortBy = OperatingSystem.ProcessSort.valueOf(method);
} catch (IllegalArgumentException e) {
String validOptions = Arrays.stream(OperatingSystem.ProcessSort.values()).map(Enum::name).collect(Collectors.joining(", ", "Valid options are: ", "."));
LOGGER.error("No process sort method of type {} was found. {}", method, validOptions);
throw new WebApplicationException(String.format("No process sort method of type %s was found. %s", method, validOptions),
Response.Status.BAD_REQUEST);
}
}
Integer theLimit = limit.orElse(0);
if(theLimit < 0){
String message = String.format("limit cannot be negative (%d)", theLimit);
LOGGER.error(message);
throw new WebApplicationException(message, Response.Status.BAD_REQUEST);
}
ProcessesInfo value = provider.processesInfo(sortBy, theLimit);
return ProcessInfoMapper.INSTANCE.map(value);
}
示例2: getProcessesCorrectSortingMethod
import oshi.software.os.OperatingSystem; //导入方法依赖的package包/类
@Test
public void getProcessesCorrectSortingMethod() throws Exception {
ArgumentCaptor<OperatingSystem.ProcessSort> captor = ArgumentCaptor.forClass(OperatingSystem.ProcessSort.class);
when(provider.processesInfo(captor.capture(), anyInt()))
.thenReturn(new ProcessesInfo(mock(GlobalMemory.class), 0, 0, 0,
new Process[]{process}));
ProcessInfo processInfo = RESOURCES.getJerseyTest().target("/processes")
.queryParam("sortBy", "MEMORY")
.request(MediaType.APPLICATION_JSON_TYPE)
.get(ProcessInfo.class);
assertEquals(captor.getValue(), OperatingSystem.ProcessSort.MEMORY);
assertThat(processInfo.getProcesses()[0].getName(), is(equalToIgnoringCase("name")));
assertThat(processInfo.getProcesses()[0].getState(), is(equalToIgnoringCase(process.getState().name())));
}
示例3: setupDataUnix
import oshi.software.os.OperatingSystem; //导入方法依赖的package包/类
private void setupDataUnix(OperatingSystem.ProcessSort sort) {
OSProcess[] processes = services.processorService.getProcessesList(sort);
data = new String[processes.length][5];
for(int i = 0; i < processes.length; i++) {
// path, uptime, pid, name
data[i][0] = processes[i].getName();
data[i][1] = Integer.toString(processes[i].getProcessID());
data[i][2] = Long.toString(processes[i].getResidentSetSize() / (1024 * 1024)) + " MB";
}
}
示例4: processesInfo
import oshi.software.os.OperatingSystem; //导入方法依赖的package包/类
@Override
public ProcessesInfo processesInfo(OperatingSystem.ProcessSort sortBy, int limit) {
GlobalMemory memory = hal.getMemory();
Process[] processes = Arrays
.stream(operatingSystem.getProcesses(limit, sortBy))
.map(p -> Process.create(p, memory))
.collect(Collectors.toList())
.toArray(new Process[0]);
return new ProcessesInfo(memory, operatingSystem.getProcessId(), operatingSystem.getThreadCount(), operatingSystem.getProcessCount(), processes);
}
示例5: processesInfo
import oshi.software.os.OperatingSystem; //导入方法依赖的package包/类
ProcessesInfo processesInfo(OperatingSystem.ProcessSort sortBy, int limit);