Class WmiQueryHandlerFFM
java.lang.Object
oshi.util.platform.windows.WmiQueryHandlerFFM
FFM-based utility to handle WMI Queries.
This class provides a high-level API for executing WMI queries using the Foreign Function and Memory API.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for processing WMI rows with three parameters. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic WmiQueryHandlerFFMFactory method to create an instance of this class.intReturns the current threading model for COM initialization, as OSHI is required to match if an external program has COM initialized already.intGets the current WMI timeout in milliseconds.booleaninitCOM()Initializes COM library.<T> List<T> queryWMI(String namespace, String wmiClassName, String whereClause, Supplier<T> resultFactory, WmiQueryHandlerFFM.TriConsumer<MemorySegment, Arena, T> rowProcessor) Executes a WMI query and processes each result row.<T> List<T> queryWMI(String wmiClassName, String whereClause, Supplier<T> resultFactory, WmiQueryHandlerFFM.TriConsumer<MemorySegment, Arena, T> rowProcessor) Executes a WMI query in the default CIMV2 namespace.static voidsetInstanceClass(Class<? extends WmiQueryHandlerFFM> instanceClass) Define a subclass to be instantiated bycreateInstance().voidsetWmiTimeout(int wmiTimeout) Sets the WMI timeout in milliseconds.intSwitches the current threading model for COM initialization, as OSHI is required to match if an external program has COM initialized already.intswitchComThreadingFrom(int expected) Switches the COM threading model only if it still matches the expected value.voidUninitializes COM library.
-
Constructor Details
-
WmiQueryHandlerFFM
protected WmiQueryHandlerFFM()
-
-
Method Details
-
createInstance
Factory method to create an instance of this class. To override this class, usesetInstanceClass(Class)to define a subclass which extendsWmiQueryHandlerFFM.- Returns:
- an instance of this class or a class defined by
setInstanceClass(Class)
-
setInstanceClass
Define a subclass to be instantiated bycreateInstance(). The class must extendWmiQueryHandlerFFM.- Parameters:
instanceClass- the class to instantiate withcreateInstance()
-
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 and processes each result row.- Type Parameters:
T- the type of result object- Parameters:
namespace- the WMI namespace (e.g., "ROOT\\CIMV2")wmiClassName- the WMI class name (e.g., "Win32_LogicalDisk")whereClause- optional WHERE clause (null for none)resultFactory- factory to create result objectsrowProcessor- 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 wmiClassName, String whereClause, Supplier<T> resultFactory, WmiQueryHandlerFFM.TriConsumer<MemorySegment, Arena, T> rowProcessor) Executes a WMI query in the default CIMV2 namespace.- Type Parameters:
T- the type of result object- Parameters:
wmiClassName- the WMI class namewhereClause- optional WHERE clauseresultFactory- factory to create result objectsrowProcessor- processor to populate result object from WMI row- Returns:
- list of result objects
-
initCOM
public boolean initCOM()Initializes COM library.- Returns:
- true if COM was initialized and needs to be uninitialized
- Throws:
FfmComException- if COM initialization fails with an unexpected error
-
unInitCOM
public void unInitCOM()Uninitializes COM library. -
switchComThreadingFrom
public int switchComThreadingFrom(int expected) Switches the COM threading model only if it still matches the expected value.- Parameters:
expected- the threading model we observed before the failed initCOM attempt- Returns:
- the new threading model if switched, or the current value if already switched by another thread
-
getComThreading
public int getComThreading()Returns the current threading model for COM initialization, as OSHI is required to match if an external program has COM initialized already.- Returns:
- the current threading model
-
switchComThreading
public int switchComThreading()Switches the current threading model for COM initialization, as OSHI is required to match if an external program has COM initialized already.- Returns:
- the new threading model after switching
-
getWmiTimeout
public int getWmiTimeout()Gets the current WMI timeout in milliseconds.- Returns:
- the current timeout (-1 for infinite)
-
setWmiTimeout
public void setWmiTimeout(int wmiTimeout) Sets the WMI timeout in milliseconds.- Parameters:
wmiTimeout- the timeout to set (-1 for infinite)
-