sysmon/plugins/base/src/main/java/sysmon/plugins/base/BasePlugin.java

53 lines
1.3 KiB
Java

package sysmon.plugins.base;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.pf4j.Plugin;
import oshi.SystemInfo;
import oshi.hardware.HardwareAbstractionLayer;
public class BasePlugin extends Plugin {
private static final Logger log = LoggerFactory.getLogger(BasePlugin.class);
private static SystemInfo systemInfo;
private static HardwareAbstractionLayer hardwareAbstractionLayer;
public static HardwareAbstractionLayer getHardwareAbstractionLayer() {
try {
if(systemInfo == null) {
systemInfo = new SystemInfo();
}
if(hardwareAbstractionLayer == null) {
hardwareAbstractionLayer = systemInfo.getHardware();
}
} catch (UnsupportedOperationException e) {
log.warn("getHardwareAbstractionLayer() - {}", e.getMessage());
return null;
}
return hardwareAbstractionLayer;
}
public static SystemInfo getSystemInfo() {
try {
if(systemInfo == null) {
systemInfo = new SystemInfo();
}
systemInfo.getOperatingSystem();
} catch (UnsupportedOperationException e) {
log.warn("getSystemInfo() - {}", e.getMessage());
return null;
}
return systemInfo;
}
}