Class WqlRequest
WinRMClient.wql(String).
Every option has a sensible default; execute() runs the query and returns the
complete result, stream() yields the rows lazily as they arrive.-
Method Summary
Modifier and TypeMethodDescriptionexecute()Execute the query and collect the complete result.Set the WMI namespace to query.pageSize(int pageSize) Set the enumeration batch size: how many rows the server may return per WSMan Enumerate/Pull response (MaxElements).pullTimeout(Duration pullTimeout) Set the maximum time the server may hold a single Pull request open before answering with the rows it has (MaxTime).stream()Execute the query and stream the rows lazily: each row is yielded as soon as it is parsed, and the next WS-Enumeration page is pulled from the server only as the stream advances — memory stays bounded by one page (pageSize(int)) instead of the whole result set.Set the timeout of this query.
-
Method Details
-
namespace
Set the WMI namespace to query. Default: the client's namespace (ROOT\CIMV2unless configured on the builder).- Parameters:
namespace- the WMI namespace, e.g.root\cimv2- Returns:
- this request
-
timeout
Set the timeout of this query. Forexecute()it is a wall-clock deadline covering every WSMan round trip and result collection; forstream()it is an inactivity timeout — the longest silence tolerated from the server between two responses, with no overall deadline. Default: the client's timeout.- Parameters:
timeout- the timeout (at least one millisecond)- Returns:
- this request
-
pageSize
Set the enumeration batch size: how many rows the server may return per WSMan Enumerate/Pull response (MaxElements). Default: 32000.- Parameters:
pageSize- the maximum number of rows per response (must be positive)- Returns:
- this request
-
pullTimeout
Set the maximum time the server may hold a single Pull request open before answering with the rows it has (MaxTime). Default: none — the server decides.- Parameters:
pullTimeout- the per-Pull timeout (at least one millisecond)- Returns:
- this request
-
execute
Execute the query and collect the complete result.- Returns:
- the query result: rows, columns in query order, and execution time
- Throws:
WqlSyntaxException- when the WQL query is invalidWinRMTimeoutException- when the timeout elapses firstWinRMAuthenticationException- when the credentials are rejectedWinRMFaultException- when the remote service answers with a WSMan faultWinRMClientException- for any other failure
-
stream
Execute the query and stream the rows lazily: each row is yielded as soon as it is parsed, and the next WS-Enumeration page is pulled from the server only as the stream advances — memory stays bounded by one page (pageSize(int)) instead of the whole result set.try (Stream<WqlRow> rows = client.wql("SELECT * FROM Win32_NTLogEvent").stream()) { rows.filter(row -> "Error".equals(row.string("Type"))).limit(100).forEach(this::process); }The stream must be closed (same contract as
Files.lines(java.nio.file.Path, java.nio.charset.Charset)) — use try-with-resources. It holds the client's serial connection while open: other operations on the same client block until it is closed or exhausted. Closing before the last row tells the server to release the enumeration immediately (WS-EnumerationRelease).The timeout acts as an inactivity timeout — the longest silence tolerated from the server between two responses — not an overall deadline: consuming a large result can take arbitrarily long as long as the server keeps answering. The initial request is sent here; later pages are fetched during consumption, so the exceptions below can also be thrown from the stream's operations while iterating.
- Returns:
- a lazy, sequential stream of rows, to use with try-with-resources
- Throws:
WqlSyntaxException- when the WQL query is invalidWinRMTimeoutException- when the inactivity timeout elapsesWinRMAuthenticationException- when the credentials are rejectedWinRMFaultException- when the remote service answers with a WSMan faultWinRMClientException- for any other failure
-