use of org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader in project milo by eclipse.
the class DataTypeDictionaryReader method browseNextAsync.
private CompletableFuture<List<ReferenceDescription>> browseNextAsync(ByteString continuationPoint, List<ReferenceDescription> references) {
RequestHeader requestHeader = stackClient.newRequestHeader(session.getAuthenticationToken(), stackClient.getConfig().getRequestTimeout());
BrowseNextRequest request = new BrowseNextRequest(requestHeader, false, new ByteString[] { continuationPoint });
return stackClient.sendRequest(request).thenApply(BrowseNextResponse.class::cast).thenCompose(response -> {
BrowseResult result = l(response.getResults()).get(0);
return maybeBrowseNext(result, references);
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader in project milo by eclipse.
the class DataTypeDictionaryReader method browseNode.
private CompletableFuture<List<ReferenceDescription>> browseNode(BrowseDescription browseDescription) {
RequestHeader requestHeader = stackClient.newRequestHeader(session.getAuthenticationToken(), stackClient.getConfig().getRequestTimeout());
BrowseRequest browseRequest = new BrowseRequest(requestHeader, new ViewDescription(NodeId.NULL_VALUE, DateTime.MIN_VALUE, uint(0)), uint(0), new BrowseDescription[] { browseDescription });
return stackClient.sendRequest(browseRequest).thenApply(BrowseResponse.class::cast).thenApply(r -> Objects.requireNonNull(r.getResults())[0]).thenCompose(result -> {
List<ReferenceDescription> references = Collections.synchronizedList(new ArrayList<>());
return maybeBrowseNext(result, references);
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader in project milo by eclipse.
the class OpcUaClient method readNamespaceTableAsync.
/**
* Read the server's NamespaceTable and update the local copy.
* <p>
* This call completes asynchronously.
*
* @return a {@link CompletableFuture} that completes successfully with the updated
* {@link NamespaceTable} or completes exceptionally if a service- or operation-level error
* occurs.
*/
public CompletableFuture<NamespaceTable> readNamespaceTableAsync() {
return getSession().thenCompose(session -> {
RequestHeader requestHeader = newRequestHeader(session.getAuthenticationToken());
ReadRequest readRequest = new ReadRequest(requestHeader, 0.0, TimestampsToReturn.Neither, new ReadValueId[] { new ReadValueId(Identifiers.Server_NamespaceArray, AttributeId.Value.uid(), null, QualifiedName.NULL_VALUE) });
CompletableFuture<String[]> namespaceArray = sendRequest(readRequest).thenApply(ReadResponse.class::cast).thenApply(response -> Objects.requireNonNull(response.getResults())).thenApply(results -> (String[]) results[0].getValue().getValue());
return namespaceArray.thenAccept(this::updateNamespaceTable).thenApply(v -> getNamespaceTable());
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader in project milo by eclipse.
the class AbstractTransport method scheduleRequestTimeout.
private void scheduleRequestTimeout(UaTransportRequest transportRequest) {
RequestHeader requestHeader = transportRequest.getRequest().getRequestHeader();
long timeoutHint = requestHeader.getTimeoutHint() != null ? requestHeader.getTimeoutHint().longValue() : 0L;
if (timeoutHint > 0) {
Timeout timeout = wheelTimer.newTimeout(t -> {
UaException exception = new UaException(StatusCodes.Bad_Timeout, String.format("requestId=%s timed out after %sms", requestHeader.getRequestHandle(), timeoutHint));
transportRequest.getFuture().completeExceptionally(exception);
}, timeoutHint, TimeUnit.MILLISECONDS);
transportRequest.setTimeout(timeout);
}
}
use of org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader in project milo by eclipse.
the class UaStackClient method sendRequest.
/**
* Send a {@link UaRequestMessage} to the connected server.
* <p>
* The {@link RequestHeader} of {@code request} must have a unique request handle. Use the
* {@code newRequestHeader} helper functions to create headers for {@link UaRequestMessage}s.
*
* @param request the {@link UaRequestMessage} to send.
* @return a {@link CompletableFuture} containing the eventual {@link UaResponseMessage} from the server.
* @see #newRequestHeader()
* @see #newRequestHeader(NodeId)
* @see #newRequestHeader(NodeId, UInteger)
*/
public CompletableFuture<UaResponseMessage> sendRequest(UaRequestMessage request) {
RequestHeader requestHeader = request.getRequestHeader();
UInteger requestHandle = requestHeader.getRequestHandle();
final CompletableFuture<UaResponseMessage> future = new CompletableFuture<>();
pending.put(requestHandle, future);
transport.sendRequest(request).whenComplete((response, ex) -> {
pending.remove(requestHandle);
deliverResponse(request, response, ex, future);
});
return future;
}
Aggregations