Class WmiQueryHandlerFFM

java.lang.Object
oshi.util.platform.windows.WmiQueryHandlerFFM

@ThreadSafe public class WmiQueryHandlerFFM extends Object
FFM-based utility to handle WMI Queries. Designed to mirror the JNA WmiQueryHandler API.
  • Constructor Details

    • WmiQueryHandlerFFM

      protected WmiQueryHandlerFFM()
  • Method Details

    • createInstance

      public static WmiQueryHandlerFFM createInstance()
      Factory method to create an instance of this class. To override this class, use setInstanceClass(Class) to define a subclass which extends WmiQueryHandlerFFM.
      Returns:
      An instance of this class or a class defined by setInstanceClass(Class)
    • setInstanceClass

      public static void setInstanceClass(Class<? extends WmiQueryHandlerFFM> instanceClass)
      Define a subclass to be instantiated by createInstance(). The class must extend WmiQueryHandlerFFM.
      Parameters:
      instanceClass - The class to instantiate with createInstance().
    • queryWMI

      public <T extends Enum<T>> WbemcliUtilFFM.WmiResult<T> queryWMI(WbemcliUtilFFM.WmiQuery<T> query)
      Query WMI for values. Makes no assumptions on whether the user has previously initialized COM.
      Type Parameters:
      T - WMI queries use an Enum to identify the fields to query, and use the enum values as keys to retrieve the results.
      Parameters:
      query - A WmiQuery object encapsulating the namespace, class, and properties
      Returns:
      a WmiResult object containing the query results, wrapping an EnumMap
    • queryWMI

      public <T extends Enum<T>> WbemcliUtilFFM.WmiResult<T> queryWMI(WbemcliUtilFFM.WmiQuery<T> query, boolean initCom)
      Query WMI for values.
      Type Parameters:
      T - WMI queries use an Enum to identify the fields to query, and use the enum values as keys to retrieve the results.
      Parameters:
      query - A WmiQuery object encapsulating the namespace, class, and properties
      initCom - Whether to initialize COM. If true, initializes COM before the query and uninitializes after. If false, assumes the caller has already called initCOM() and will call unInitCOM() when done. This can improve WMI query performance.
      Returns:
      a WmiResult object containing the query results, wrapping an EnumMap
    • queryWMI

      public <T> List<T> queryWMI(String wmiClassName, String whereClause, Supplier<T> resultFactory, WmiQueryHandlerFFM.TriConsumer<MemorySegment, Arena, T> rowProcessor)
      Executes a WMI query in the default namespace, processing each result row with a custom processor.
      Type Parameters:
      T - the type of result object
      Parameters:
      wmiClassName - the WMI class name
      whereClause - optional WHERE clause (null for none)
      resultFactory - factory to create result objects per row
      rowProcessor - processor to populate result object from WMI row
      Returns:
      list of result objects, empty list if query fails
    • queryWMI

      public <T> List<T> queryWMI(String namespace, String wmiClassName, String whereClause, Supplier<T> resultFactory, WmiQueryHandlerFFM.TriConsumer<MemorySegment, Arena, T> rowProcessor)
      Executes a WMI query, processing each result row with a custom processor.
      Type Parameters:
      T - the type of result object
      Parameters:
      namespace - the WMI namespace
      wmiClassName - the WMI class name
      whereClause - optional WHERE clause (null for none)
      resultFactory - factory to create result objects per row
      rowProcessor - processor to populate result object from WMI row
      Returns:
      list of result objects, empty list if query fails
    • handleComException

      protected void handleComException(WbemcliUtilFFM.WmiQuery<?> query, FfmComException ex)
      COM Exception handler. Logs at debug level for known-optional classes, otherwise warns.
      Parameters:
      query - a WmiQuery object
      ex - a FfmComException object
    • initCOM

      public boolean initCOM()
      Initializes COM library and sets security to impersonate the local user.
      Returns:
      True if COM was initialized and needs to be uninitialized, false otherwise
    • initCOM

      protected boolean initCOM(int coInitThreading)
      Initializes COM with a specific threading model.
      Parameters:
      coInitThreading - The threading model
      Returns:
      True if COM was initialized and needs to be uninitialized, false otherwise
    • unInitCOM

      public void unInitCOM()
      UnInitializes COM library.
    • getComThreading

      public int getComThreading()
      Returns the current threading model for COM initialization.
      Returns:
      The current threading model
    • switchComThreading

      public int switchComThreading()
      Switches the current threading model for COM initialization.
      Returns:
      The new threading model after switching
    • switchComThreadingFrom

      public int switchComThreadingFrom(int expected)
      Switches the current threading model only if it still matches the expected value.
      Parameters:
      expected - the threading model observed before the failed initCOM attempt
      Returns:
      the new threading model if switched, or the current value if already switched by another thread
    • isSecurityInitialized

      public boolean isSecurityInitialized()
      Security only needs to be initialized once.
      Returns:
      Returns the securityInitialized.
    • getWmiTimeout

      public int getWmiTimeout()
      Gets the current WMI timeout.
      Returns:
      Returns the current value of wmiTimeout.
    • setWmiTimeout

      public void setWmiTimeout(int wmiTimeout)
      Sets the WMI timeout.
      Parameters:
      wmiTimeout - The wmiTimeout to set, in milliseconds. To disable timeouts, set timeout as -1 (infinite).