Search in sources :

Example 1 with VmOption

use of com.shulie.instrument.simulator.module.model.vmoption.VmOption in project LinkAgent by shulieTech.

the class VMOptionModule method info.

@Command(value = "info", description = "查看虚拟机参数")
public CommandResponse info(final Map<String, String> args) {
    String name = args.get("name");
    try {
        HotSpotDiagnosticMXBean hotSpotDiagnosticMXBean = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
        if (StringUtils.isBlank(name)) {
            // show all options
            final List<VMOption> diagnosticOptions = hotSpotDiagnosticMXBean.getDiagnosticOptions();
            List<VmOption> vmOptions = new ArrayList<VmOption>();
            for (VMOption vmOption : diagnosticOptions) {
                vmOptions.add(new VmOption(vmOption));
            }
            return CommandResponse.success(vmOptions);
        } else {
            // view the specified option
            VMOption option = hotSpotDiagnosticMXBean.getVMOption(name);
            if (option == null) {
                return CommandResponse.failure("In order to change the system properties, you must specify the property value.");
            } else {
                List<VmOption> vmOptions = new ArrayList<VmOption>();
                vmOptions.add(new VmOption(option));
                return CommandResponse.success(vmOptions);
            }
        }
    } catch (Throwable t) {
        return CommandResponse.failure(t);
    }
}
Also used : VmOption(com.shulie.instrument.simulator.module.model.vmoption.VmOption) HotSpotDiagnosticMXBean(com.sun.management.HotSpotDiagnosticMXBean) VMOption(com.sun.management.VMOption) ArrayList(java.util.ArrayList) Command(com.shulie.instrument.simulator.api.annotation.Command)

Aggregations

Command (com.shulie.instrument.simulator.api.annotation.Command)1 VmOption (com.shulie.instrument.simulator.module.model.vmoption.VmOption)1 HotSpotDiagnosticMXBean (com.sun.management.HotSpotDiagnosticMXBean)1 VMOption (com.sun.management.VMOption)1 ArrayList (java.util.ArrayList)1