Class PhysicalMemoryService

java.lang.Object
io.github.eggy03.ferrumx.windows.service.memory.PhysicalMemoryService
All Implemented Interfaces:
CommonServiceInterface<PhysicalMemory>

public class PhysicalMemoryService extends Object implements CommonServiceInterface<PhysicalMemory>
Service class for fetching information about physical memory modules (RAM) in the system.

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

Thread safety

Methods of class are not thread safe.

Usage examples


 // Convenience API (creates its own short-lived session)
 PhysicalMemoryService memoryService = new PhysicalMemoryService();
 List<PhysicalMemory> memories = memoryService.get();

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

    • PhysicalMemoryService

      public PhysicalMemoryService()
  • Method Details

    • get

      @NotNull public @NotNull List<PhysicalMemory> get()
      Retrieves a list of physical memory modules present in the system.

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

      Specified by:
      get in interface CommonServiceInterface<PhysicalMemory>
      Returns:
      a list of PhysicalMemory objects representing the system's RAM. Returns an empty list if no memory modules are detected.
      Throws:
      com.google.gson.JsonSyntaxException - if there is an error executing the PowerShell command or parsing the output.
    • get

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