use of org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription 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.ReferenceDescription in project milo by eclipse.
the class AddressSpace method browseNodesAsync.
/**
* Browse from {@code nodeId} using {@code browseOptions}.
* <p>
* This call completes asynchronously.
*
* @param nodeId the {@link NodeId} to start the browse from.
* @param browseOptions the {@link BrowseOptions} to use.
* @return a CompletableFuture that completes successfully with a List of {@link UaNode}s
* referenced by {@code node} given the currently configured {@link BrowseOptions} or completes
* exceptionally if a service-level error occurs.
*/
public CompletableFuture<List<? extends UaNode>> browseNodesAsync(NodeId nodeId, BrowseOptions browseOptions) {
BrowseDescription browseDescription = new BrowseDescription(nodeId, browseOptions.getBrowseDirection(), browseOptions.getReferenceTypeId(), browseOptions.isIncludeSubtypes(), browseOptions.getNodeClassMask(), uint(BrowseResultMask.All.getValue()));
CompletableFuture<List<ReferenceDescription>> browse = BrowseHelper.browse(client, browseDescription, browseOptions.getMaxReferencesPerNode());
return browse.thenCompose(references -> {
List<CompletableFuture<? extends UaNode>> cfs = references.stream().map(reference -> {
NodeClass nodeClass = reference.getNodeClass();
ExpandedNodeId xNodeId = reference.getNodeId();
ExpandedNodeId xTypeDefinitionId = reference.getTypeDefinition();
switch(nodeClass) {
case Object:
case Variable:
{
CompletableFuture<CompletableFuture<? extends UaNode>> ff = toNodeIdAsync(xNodeId).thenCombine(toNodeIdAsync(xTypeDefinitionId), (targetNodeId, typeDefinitionId) -> {
if (nodeClass == NodeClass.Object) {
return getObjectNodeAsync(targetNodeId, typeDefinitionId);
} else {
return getVariableNodeAsync(targetNodeId, typeDefinitionId);
}
});
return unwrap(ff).exceptionally(ex -> {
logger.warn("Failed to create Node from Reference to {}", reference.getNodeId(), ex);
return null;
});
}
default:
{
// TODO specialized getNode for other NodeClasses?
return toNodeIdAsync(xNodeId).thenCompose(this::getNodeAsync).exceptionally(ex -> {
logger.warn("Failed to create Node from Reference to {}", reference.getNodeId(), ex);
return null;
});
}
}
}).collect(Collectors.toList());
return sequence(cfs);
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription in project milo by eclipse.
the class DataTypeTreeBuilder method addChildren.
private static CompletableFuture<Unit> addChildren(Tree<DataTypeTree.DataType> tree, UaStackClient client, OpcUaSession session, NamespaceTable namespaceTable) {
CompletableFuture<List<ReferenceDescription>> subtypes = browseSafe(client, session, new BrowseDescription(tree.getValue().getNodeId(), BrowseDirection.Forward, Identifiers.HasSubtype, false, uint(NodeClass.DataType.getValue()), uint(BrowseResultMask.All.getValue())));
CompletableFuture<List<DataTypeTree.DataType>> dataTypesFuture = subtypes.thenCompose(references -> {
Stream<CompletableFuture<DataTypeTree.DataType>> dataTypeFutures = references.stream().map(dataTypeReference -> {
NodeId dataTypeId = dataTypeReference.getNodeId().toNodeId(namespaceTable).orElse(NodeId.NULL_VALUE);
CompletableFuture<List<ReferenceDescription>> encodings = browseSafe(client, session, new BrowseDescription(dataTypeId, BrowseDirection.Forward, Identifiers.HasEncoding, false, uint(NodeClass.Object.getValue()), uint(BrowseResultMask.All.getValue())));
return encodings.thenApply(encodingReferences -> {
NodeId binaryEncodingId = null;
NodeId xmlEncodingId = null;
for (ReferenceDescription r : encodingReferences) {
if (r.getBrowseName().equals(OpcUaDefaultBinaryEncoding.ENCODING_NAME)) {
binaryEncodingId = r.getNodeId().toNodeId(namespaceTable).orElse(null);
} else if (r.getBrowseName().equals(OpcUaDefaultXmlEncoding.ENCODING_NAME)) {
xmlEncodingId = r.getNodeId().toNodeId(namespaceTable).orElse(null);
}
}
return new DataTypeTree.DataType(dataTypeReference.getBrowseName(), dataTypeId, binaryEncodingId, xmlEncodingId);
});
});
return FutureUtils.sequence(dataTypeFutures);
});
return dataTypesFuture.thenCompose(dataTypes -> {
Stream<CompletableFuture<Unit>> futures = dataTypes.stream().map(tree::addChild).map(childNode -> addChildren(childNode, client, session, namespaceTable));
return FutureUtils.sequence(futures);
}).thenApply(v -> Unit.VALUE);
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription in project milo by eclipse.
the class UaNode method getComponentAsync.
protected CompletableFuture<? extends UaNode> getComponentAsync(QualifiedName browseName, NodeClass nodeClass) {
UInteger nodeClassMask = uint(nodeClass.getValue());
UInteger resultMask = uint(BrowseResultMask.All.getValue());
CompletableFuture<BrowseResult> future = client.browse(new BrowseDescription(getNodeId(), BrowseDirection.Forward, Identifiers.HasComponent, false, nodeClassMask, resultMask));
return future.thenCompose(result -> {
List<ReferenceDescription> references = l(result.getReferences());
Optional<CompletableFuture<? extends UaNode>> node = references.stream().filter(r -> browseName.equals(r.getBrowseName())).flatMap(r -> {
Optional<CompletableFuture<? extends UaNode>> opt = r.getNodeId().toNodeId(client.getNamespaceTable()).map(id -> client.getAddressSpace().getNodeAsync(id));
return opt2stream(opt);
}).findFirst();
return node.orElse(failedUaFuture(StatusCodes.Bad_NotFound));
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription in project milo by eclipse.
the class DataTypeDictionaryReader method maybeBrowseNext.
private CompletionStage<List<ReferenceDescription>> maybeBrowseNext(BrowseResult result, List<ReferenceDescription> references) {
if (result.getStatusCode().isGood()) {
ReferenceDescription[] rds = result.getReferences();
if (rds != null)
Collections.addAll(references, rds);
ByteString continuationPoint = result.getContinuationPoint();
if (continuationPoint.isNotNull()) {
logger.debug("Continuation point was non-null; calling BrowseNext");
return browseNextAsync(continuationPoint, references);
} else {
logger.debug("Browse finished with {} references", references.size());
return completedFuture(references);
}
} else {
return completedFuture(references);
}
}
Aggregations