Class MonitorService

java.lang.Object
io.github.eggy03.ferrumx.windows.service.display.MonitorService
All Implemented Interfaces:
CommonServiceInterface<Monitor>

public class MonitorService extends Object implements CommonServiceInterface<Monitor>
Service class for fetching monitor information from the system.

This class executes the CimQuery.MONITOR_QUERY PowerShell command and maps the resulting JSON into a list of Monitor objects.

Thread safety

Methods of class are not thread safe.

Usage examples


 // Convenience API (creates its own short-lived session)
 MonitorService monitorService = new MonitorService();
 List<Monitor> monitors = monitorService.get();

 // API with re-usable session (caller manages session lifecycle)
 try (PowerShell session = PowerShell.openSession()) {
     List<Monitor> monitors = monitorService.get(session);
 }
 
Since:
2.0.0
Author:
Egg-03
  • Constructor Details

    • MonitorService

      public MonitorService()
  • Method Details

    • get

      @NonNull public @NonNull List<Monitor> get()
      Retrieves a list of monitors connected to the system.

      Each invocation creates and uses a short-lived PowerShell session internally.

      Specified by:
      get in interface CommonServiceInterface<Monitor>
      Returns:
      a list of Monitor objects representing connected monitors. Returns an empty list if no monitors are detected.
      Throws:
      com.google.gson.JsonSyntaxException - if there is an error executing the PowerShell command or parsing the output.
    • get

      @NonNull public @NonNull List<Monitor> get(com.profesorfalken.jpowershell.PowerShell powerShell)
      Retrieves a list of monitors connected to the system using the caller's PowerShell session.
      Specified by:
      get in interface CommonServiceInterface<Monitor>
      Parameters:
      powerShell - an existing PowerShell session managed by the caller
      Returns:
      a list of Monitor objects representing connected monitors. Returns an empty list if no monitors are detected.
      Throws:
      com.google.gson.JsonSyntaxException - if there is an error executing the PowerShell command or parsing the output.