• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PowerSource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中oshi.hardware.PowerSource的典型用法代码示例。如果您正苦于以下问题:Java PowerSource类的具体用法?Java PowerSource怎么用?Java PowerSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: getSystemHappyPath

import oshi.hardware.PowerSource; //导入依赖的package包/类
@Test
public void getSystemHappyPath() throws Exception {
    OperatingSystem operatingSystem = mock(OperatingSystem.class);
    CentralProcessor centralProcessor = mock(CentralProcessor.class);
    GlobalMemory globalMemory = mock(GlobalMemory.class);
    when(provider.systemInfo()).thenReturn(
            new com.krillsson.sysapi.core.domain.system.SystemInfo("theHost", PlatformEnum.LINUX, operatingSystem,
                    new CpuInfo(centralProcessor, 4, 80,
                            new CpuLoad(100, 0, 0, 0, 0, 0, 0, 0, 0),
                            new CpuHealth(new double[0], 120, 1000, 10)),
                    globalMemory,
                    new PowerSource[0]));

    final SystemInfo response = RESOURCES.getJerseyTest().target("/system")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .get(SystemInfo.class);
    assertNotNull(response);
    assertEquals(response.getCpuInfo().getCpuLoad().getCpuLoadCountingTicks(), 100, 0);
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:20,代码来源:SystemInfoResourceTest.java


示例2: printPowerSources

import oshi.hardware.PowerSource; //导入依赖的package包/类
/**
 * Prints the power sources.
 *
 * @param powerSources the power sources
 */
private static void printPowerSources(PowerSource[] powerSources) {
  StringBuilder sb = new StringBuilder("Power: ");
  if (powerSources.length == 0) {
    sb.append("Unknown");
  } else {
    double timeRemaining = powerSources[0].getTimeRemaining();
    if (timeRemaining < -1d) {
      sb.append("Charging");
    } else if (timeRemaining < 0d) {
      sb.append("Calculating time remaining");
    } else {
      sb.append(String.format("%d:%02d remaining", (int) (timeRemaining / 3600),
          (int) (timeRemaining / 60) % 60));
    }
  }
  for (PowerSource powerSource : powerSources) {
    sb.append(String.format("%n %s @ %.1f%%", powerSource.getName(),
        powerSource.getRemainingCapacity() * 100d));
  }
  oshi.add(sb.toString());
}
 
开发者ID:psi-probe,项目名称:psi-probe,代码行数:27,代码来源:OshiController.java


示例3: getPowerSourceMetric

import oshi.hardware.PowerSource; //导入依赖的package包/类
/**
 * Returns the given metric's value, or null if there is no power source with the given name.
 *
 * @param powerSourceName name of power source
 * @param metricToCollect the metric to collect
 * @return the value of the metric, or null if there is no power source with the given name
 */
public Double getPowerSourceMetric(String powerSourceName, ID metricToCollect) {

    Map<String, PowerSource> cache = getPowerSources();
    PowerSource powerSource = cache.get(powerSourceName);
    if (powerSource == null) {
        return null;
    }

    if (PlatformMetricType.POWER_SOURCE_REMAINING_CAPACITY.getMetricTypeId().equals(metricToCollect)) {
        return powerSource.getRemainingCapacity();
    } else if (PlatformMetricType.POWER_SOURCE_TIME_REMAINING.getMetricTypeId().equals(metricToCollect)) {
        return powerSource.getTimeRemaining();
    } else {
        throw new UnsupportedOperationException("Invalid power source metric to collect: " + metricToCollect);
    }
}
 
开发者ID:hawkular,项目名称:hawkular-agent,代码行数:24,代码来源:OshiPlatformCache.java


示例4: SystemInfo

import oshi.hardware.PowerSource; //导入依赖的package包/类
public SystemInfo(String hostName, PlatformEnum platformEnum, OperatingSystem operatingSystem, CpuInfo cpuInfo, GlobalMemory memory, PowerSource[] powerSources) {
    this.hostName = hostName;
    this.platformEnum = platformEnum;
    this.operatingSystem = operatingSystem;
    this.cpuInfo = cpuInfo;
    this.memory = memory;
    this.powerSources = powerSources;
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:9,代码来源:SystemInfo.java


示例5: getPowerSourceHappyPath

import oshi.hardware.PowerSource; //导入依赖的package包/类
@Test
public void getPowerSourceHappyPath() throws Exception {
    PowerSource powerSource = mock(PowerSource.class);
    when(powerSource.getName()).thenReturn("battery");
    when(powerSource.getRemainingCapacity()).thenReturn(0.1);
    when(powerSource.getTimeRemaining()).thenReturn(100.0);
    when(provider.powerSources()).thenReturn(new PowerSource[]{powerSource});

    final com.krillsson.sysapi.dto.power.PowerSource[] response = RESOURCES.getJerseyTest().target("/powersources")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .get(com.krillsson.sysapi.dto.power.PowerSource[].class);
    assertNotNull(response);
    assertEquals(1, response.length);
    assertEquals("battery", response[0].getName());
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:16,代码来源:PowerSourcesResourceTest.java


示例6: getPowerSources

import oshi.hardware.PowerSource; //导入依赖的package包/类
/**
 * @return information about all power sources (e.g. batteries) on the platform.
 */
@SuppressWarnings("unchecked")
public Map<String, PowerSource> getPowerSources() {
    Map<String, PowerSource> ret;

    wLock.lock();
    try {

        if (!sysInfoCache.containsKey(PlatformResourceType.POWER_SOURCE)) {
            HashMap<String, PowerSource> cache = new HashMap<>();
            PowerSource[] arr = sysInfo.getHardware().getPowerSources();
            if (arr != null) {
                for (PowerSource item : arr) {
                    cache.put(item.getName(), item);
                }
            }
            sysInfoCache.put(PlatformResourceType.POWER_SOURCE, cache);
        }
    } finally {
        // downgrade to a read-only lock since we just need it to read from the cache
        rLock.lock();
        try {
            wLock.unlock();
            ret = (Map<String, PowerSource>) sysInfoCache.get(PlatformResourceType.POWER_SOURCE);
        } finally {
            rLock.unlock();
        }
    }

    return ret;
}
 
开发者ID:hawkular,项目名称:hawkular-agent,代码行数:34,代码来源:OshiPlatformCache.java


示例7: getPowerSources

import oshi.hardware.PowerSource; //导入依赖的package包/类
@Test
public void getPowerSources() {
    OshiPlatformCache oshi = newOshiPlatformCache();
    Map<String, PowerSource> powersources = oshi.getPowerSources();
    Assert.assertNotNull(powersources);

    if (powersources.size() == 0) {
        print("===NO POWER SOURCES ON THIS MACHINE===");
    } else {
        int i = 0;
        for (PowerSource powersource : powersources.values()) {
            String name = powersource.getName();
            double remainingCapacity = powersource.getRemainingCapacity();
            double timeRemaining = powersource.getTimeRemaining();

            Assert.assertNotNull(name);

            print("===POWER SOURCE #%d ===", ++i);
            print("  Name=[%s]", name);
            print("  RemainingCapacity=[%.0f%%] (%.2f)", remainingCapacity * 100, remainingCapacity);
            long roundedTimeRemaining = Math.round(timeRemaining);
            if (roundedTimeRemaining == -1) {
                print("  TimeRemaining=[calculating] (%.1f)", timeRemaining);
            } else if (roundedTimeRemaining == -2) {
                print("  TimeRemaining=[unlimited] (%.1f)", timeRemaining);
            } else {
                print("  TimeRemaining=[%s] (%.1f)", FormatUtil.formatElapsedSecs(roundedTimeRemaining),
                        timeRemaining);
            }
            print("  toString=[%s]", powersource.toString());
        }
    }
}
 
开发者ID:hawkular,项目名称:hawkular-agent,代码行数:34,代码来源:OshiPlatformCacheTest.java


示例8: getBatteryRemainingTime

import oshi.hardware.PowerSource; //导入依赖的package包/类
@Override
public DecimalType getBatteryRemainingTime(int index) throws DeviceNotFoundException {
    // In the current OSHI version a new query is required for the battery data values to be updated
    // In OSHI 4.0.0. it is planned to change this mechanism - see https://github.com/oshi/oshi/issues/310
    powerSources = hal.getPowerSources();
    PowerSource powerSource = (PowerSource) getDevice(powerSources, index);
    double remainingTimeInSeconds = powerSource.getTimeRemaining();
    // The getTimeRemaining() method returns (-1.0) if is calculating or (-2.0) if the time is unlimited.
    BigDecimal remainingTime = getTimeInMinutes(remainingTimeInSeconds);
    return remainingTime.signum() == 1 ? new DecimalType(remainingTime) : null;
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:12,代码来源:OshiSysteminfo.java


示例9: getBatteryRemainingCapacity

import oshi.hardware.PowerSource; //导入依赖的package包/类
@Override
public DecimalType getBatteryRemainingCapacity(int index) throws DeviceNotFoundException {
    // In the current OSHI version a new query is required for the battery data values to be updated
    // In OSHI 4.0.0. it is planned to change this mechanism - see https://github.com/oshi/oshi/issues/310
    powerSources = hal.getPowerSources();
    PowerSource powerSource = (PowerSource) getDevice(powerSources, index);
    double remainingCapacity = powerSource.getRemainingCapacity();
    BigDecimal remainingCapacityPercents = getPercentsValue(remainingCapacity);
    return new DecimalType(remainingCapacityPercents);
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:11,代码来源:OshiSysteminfo.java


示例10: Battery

import oshi.hardware.PowerSource; //导入依赖的package包/类
public Battery(PowerSource battery) {
    dateFormat = new SimpleDateFormat("HH 'hours,' mm 'minutes and' ss 'seconds'");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    this.battery = battery;
}
 
开发者ID:ozankaraali,项目名称:SystemMonitor,代码行数:6,代码来源:Battery.java


示例11: getRoot

import oshi.hardware.PowerSource; //导入依赖的package包/类
@GET
@RolesAllowed(BasicAuthorizer.AUTHENTICATED_ROLE)
public com.krillsson.sysapi.dto.power.PowerSource[] getRoot(@Auth UserConfiguration user) {
    return PowerSourceMapper.INSTANCE.map(provider.powerSources());
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:6,代码来源:PowerSourcesResource.java


示例12: getPowerSources

import oshi.hardware.PowerSource; //导入依赖的package包/类
public PowerSource[] getPowerSources() {
    return powerSources;
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:4,代码来源:SystemInfo.java


示例13: printSystemInfo

import oshi.hardware.PowerSource; //导入依赖的package包/类
/**
 * Stalks your computer and prints the information about it using OSHI.
 *
 * <p>Just kidding, you don't need to call this, but it's helpful if you juset want to know.</p>
 */
public void printSystemInfo() {
    // Obtains
    // OS, java version, flags, CPU, disks, RAM, power
    System.out.println("System info:");

    String os = System.getProperty("os.name");
    String osVer = System.getProperty("os.version");
    String osArch = System.getProperty("os.arch");
    System.out.printf("Running %s version %s arch %s\n", os, osVer, osArch);

    String javaVer = System.getProperty("java.version");
    String vmVendor = System.getProperty("java.vendor");
    System.out.printf("Java version %s JVM %s\n", javaVer, vmVendor);

    System.out.print("Java flags: ");
    RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
    List<String> arguments = runtimeMxBean.getInputArguments();
    for (String string : arguments) {
        System.out.print(string + " ");
    }
    for (String arg : args) {
        System.out.print(arg + " ");
    }
    System.out.println();

    SystemInfo info = new SystemInfo();
    HardwareAbstractionLayer layer = info.getHardware();

    Memory memory = layer.getMemory();
    System.out.printf("Memory total %d bytes, usable %d bytes\n", memory.getTotal(), memory.getAvailable());

    Runtime runtime = Runtime.getRuntime();
    System.out.printf("VM memory free %d bytes, max %d bytes, total %d bytes\n", runtime.freeMemory(),
            runtime.maxMemory(), runtime.totalMemory());

    Processor[] procs = layer.getProcessors();
    System.out.println("CPUs (" + procs.length + "):");
    for (Processor p : procs) {
        System.out.printf("  %s\n", p.getName());
    }

    OSFileStore[] stores = layer.getFileStores();
    System.out.print("Disks (" + stores.length + "):\n");
    for (OSFileStore store : stores) {
        System.out.printf("  %s cap %d bytes, usable %d bytes\n",
                store.getName(), store.getTotalSpace(), store.getUsableSpace());
    }

    PowerSource[] sources = layer.getPowerSources();
    System.out.println("PSUs (" + sources.length + "):");
    for (PowerSource source : sources) {
        System.out.printf("  %s: remaining cap %f, time left %f\n", source.getName(), source.getRemainingCapacity(),
                source.getTimeRemaining());
    }
}
 
开发者ID:AgentTroll,项目名称:Fastest-Fing-Data-Structure-Java,代码行数:61,代码来源:Benchmark.java


示例14: getBatteryName

import oshi.hardware.PowerSource; //导入依赖的package包/类
@Override
public StringType getBatteryName(int index) throws DeviceNotFoundException {
    PowerSource powerSource = (PowerSource) getDevice(powerSources, index);
    String name = powerSource.getName();
    return new StringType(name);
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:7,代码来源:OshiSysteminfo.java


示例15: powerSources

import oshi.hardware.PowerSource; //导入依赖的package包/类
PowerSource[] powerSources(); 
开发者ID:Krillsson,项目名称:sys-api,代码行数:2,代码来源:InfoProvider.java



注:本文中的oshi.hardware.PowerSource类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PrepareBulkLoadRequest类代码示例发布时间:2022-05-22
下一篇:
Java Template类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap