Class Win32ComputerSystemService
java.lang.Object
io.github.eggy03.ferrumx.windows.service.system.Win32ComputerSystemService
- All Implemented Interfaces:
OptionalCommonServiceInterface<Win32ComputerSystem>
public class Win32ComputerSystemService
extends Object
implements OptionalCommonServiceInterface<Win32ComputerSystem>
Service class for fetching the computer system information running Windows.
This class executes the Cimv2.WIN32_COMPUTER_SYSTEM PowerShell command
and maps the resulting JSON into an Optional Win32ComputerSystem object.
Usage examples
// Convenience API (creates its own short-lived session)
Win32ComputerSystemService service = new Win32ComputerSystemService();
Optional<Win32ComputerSystem> system = service.get();
// API with re-usable session (caller manages session lifecycle)
try (PowerShell session = PowerShell.openSession()) {
Win32ComputerSystemService service = new Win32ComputerSystemService();
Optional<Win32ComputerSystem> system = service.get(session);
}
// API with execution timeout (auto-created session is terminated if the timeout is exceeded)
Win32ComputerSystemService service = new Win32ComputerSystemService();
Optional<Win32ComputerSystem> system = service.get(10);
Execution models and concurrency
This service supports multiple PowerShell execution strategies:
-
jPowerShell-based execution via
get()andget(PowerShell):
These methods rely onjPowerShellsessions. Due to internal global configuration ofjPowerShell, the PowerShell sessions launched by it is not safe to use concurrently across multiple threads or executors. Running these methods in parallel may result in runtime exceptions. -
Isolated PowerShell execution via
get(long timeout):
This method doesn't rely onjPowerShelland instead, launches a standalone PowerShell process per invocation usingTerminalUtility. Each call is fully isolated and safe to use in multithreaded and executor-based environments.
For concurrent or executor-based workloads, prefer get(long timeout).
- Since:
- 3.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull Optional<Win32ComputerSystem> get()Retrieves anOptionalcontaining the computer system information.@NotNull Optional<Win32ComputerSystem> get(long timeout) Retrieves anOptionalcontaining the Computer System information using an isolated PowerShell process with a configurable timeout.@NotNull Optional<Win32ComputerSystem> get(@NonNull com.profesorfalken.jpowershell.PowerShell powerShell) Retrieves anOptionalcontaining the computer system information using the caller'sPowerShellsession.
-
Constructor Details
-
Win32ComputerSystemService
public Win32ComputerSystemService()
-
-
Method Details
-
get
Retrieves anOptionalcontaining the computer system information.Each invocation creates and uses a short-lived PowerShell session internally.
- Specified by:
getin interfaceOptionalCommonServiceInterface<Win32ComputerSystem>- Returns:
- an
OptionalofWin32ComputerSystemrepresenting the computer system. ReturnsOptional.empty()if no system information is detected. - Since:
- 3.0.0
-
get
@UsesJPowerShell @NotNull public @NotNull Optional<Win32ComputerSystem> get(@NonNull @NonNull com.profesorfalken.jpowershell.PowerShell powerShell) Retrieves anOptionalcontaining the computer system information using the caller'sPowerShellsession.- Specified by:
getin interfaceOptionalCommonServiceInterface<Win32ComputerSystem>- Parameters:
powerShell- an existing PowerShell session managed by the caller- Returns:
- an
OptionalofWin32ComputerSystemrepresenting the computer system. ReturnsOptional.empty()if no information is detected. - Since:
- 3.0.0
-
get
Retrieves anOptionalcontaining the Computer System information using an isolated PowerShell process with a configurable timeout.Each invocation creates an isolated PowerShell process, which is pre-maturely terminated if execution exceeds the specified timeout.
- Specified by:
getin interfaceOptionalCommonServiceInterface<Win32ComputerSystem>- Parameters:
timeout- the maximum time (in seconds) to wait for the PowerShell command to complete before terminating the process- Returns:
- an
OptionalofWin32ComputerSystemrepresenting the HWID. ReturnsOptional.empty()if no information is detected. - Since:
- 3.1.0
-