Class MsftDnsClientServerAddressService
java.lang.Object
io.github.eggy03.ferrumx.windows.service.network.MsftDnsClientServerAddressService
- All Implemented Interfaces:
CommonServiceInterface<MsftDnsClientServerAddress>
public class MsftDnsClientServerAddressService
extends Object
implements CommonServiceInterface<MsftDnsClientServerAddress>
Service class for fetching DNS Client and Server information for a network adapter.
This class executes the StandardCimv2.MSFT_NET_DNS_CLIENT_SERVER_ADDRESS PowerShell command
and maps the resulting JSON into an immutable list of MsftDnsClientServerAddress objects.
Usage examples
// Convenience API (creates its own short-lived session)
MsftDnsClientServerAddressService service = new MsftDnsClientServerAddressService();
List<MsftDnsClientServerAddress> dns = service.get();
// API with re-usable session (caller manages session lifecycle)
try (PowerShell session = PowerShell.openSession()) {
MsftDnsClientServerAddressService service = new MsftDnsClientServerAddressService();
List<MsftDnsClientServerAddress> dns = service.get(session);
}
// API with execution timeout (auto-created session is terminated if the timeout is exceeded)
MsftDnsClientServerAddressService service = new MsftDnsClientServerAddressService();
List<MsftDnsClientServerAddress> dns = 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 @Unmodifiable List<MsftDnsClientServerAddress> get()Retrieves an immutable list of DNS Server and Client configuration for all network adapters present in the system.@NotNull @Unmodifiable List<MsftDnsClientServerAddress> get(long timeout) Retrieves an immutable list of DNS Server and Client configuration for all network adapters present in the system using an isolated PowerShell process with a configurable timeout.@NotNull @Unmodifiable List<MsftDnsClientServerAddress> get(@NonNull com.profesorfalken.jpowershell.PowerShell powerShell) Retrieves an immutable list of DNS Server and Client configuration for all network adapters present in the system using the caller'sPowerShellsession.
-
Constructor Details
-
MsftDnsClientServerAddressService
public MsftDnsClientServerAddressService()
-
-
Method Details
-
get
Retrieves an immutable list of DNS Server and Client configuration for all network adapters present in the system.Each invocation creates and uses a short-lived PowerShell session internally.
- Specified by:
getin interfaceCommonServiceInterface<MsftDnsClientServerAddress>- Returns:
- an immutable list of
MsftDnsClientServerAddressobjects representing the DNS configs. Returns an empty list if no configs are detected. - Since:
- 3.0.0
-
get
@UsesJPowerShell @NotNull public @NotNull @Unmodifiable List<MsftDnsClientServerAddress> get(@NonNull @NonNull com.profesorfalken.jpowershell.PowerShell powerShell) Retrieves an immutable list of DNS Server and Client configuration for all network adapters present in the system using the caller'sPowerShellsession.- Specified by:
getin interfaceCommonServiceInterface<MsftDnsClientServerAddress>- Parameters:
powerShell- an existing PowerShell session managed by the caller- Returns:
- an immutable list of
MsftDnsClientServerAddressobjects representing the DNS configs. Returns an empty list if no configs are detected. - Since:
- 3.0.0
-
get
@IsolatedPowerShell @NotNull public @NotNull @Unmodifiable List<MsftDnsClientServerAddress> get(long timeout) Retrieves an immutable list of DNS Server and Client configuration for all network adapters present in the system 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 interfaceCommonServiceInterface<MsftDnsClientServerAddress>- Parameters:
timeout- the maximum time (in seconds) to wait for the PowerShell command to complete before terminating the process- Returns:
- an immutable list of
MsftDnsClientServerAddressobjects representing the DNS configs. Returns an empty list if no configs are detected. - Since:
- 3.1.0
-