View Javadoc
1   /*
2    * Copyright 2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.demo.jmx.strategiesplatform;
6   
7   import oshi.SystemInfo;
8   import oshi.demo.jmx.api.StrategyRegistrationPlatformMBeans;
9   
10  import javax.management.MBeanServer;
11  import javax.management.NotCompliantMBeanException;
12  import javax.management.InstanceAlreadyExistsException;
13  import javax.management.MBeanRegistrationException;
14  import javax.management.MalformedObjectNameException;
15  import javax.management.ObjectName;
16  
17  import java.beans.IntrospectionException;
18  
19  public class WindowsStrategyRegistrattionPlatform implements StrategyRegistrationPlatformMBeans {
20      @Override
21      public void registerMBeans(SystemInfo systemInfo, MBeanServer mBeanServer)
22              throws NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanRegistrationException,
23              MalformedObjectNameException, IntrospectionException, javax.management.IntrospectionException {
24          // here we can register all the MBeans reletad to windows. for this sample we
25          // are only gonna register one MBean with two Attribute
26  
27          ObjectName objectName = new ObjectName("oshi:component=BaseBoard");
28          oshi.demo.jmx.mbeans.Baseboard baseBoardMBean = new oshi.demo.jmx.mbeans.Baseboard(
29                  systemInfo.getHardware().getComputerSystem().getBaseboard());
30  
31          mBeanServer.registerMBean(baseBoardMBean, objectName);
32      }
33  }