use of org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture in project milo by eclipse.
the class UaObjectNode method getTypeDefinitionAsync.
public CompletableFuture<? extends UaObjectTypeNode> getTypeDefinitionAsync() {
UInteger nodeClassMask = uint(NodeClass.ObjectType.getValue());
UInteger resultMask = uint(BrowseResultMask.All.getValue());
CompletableFuture<BrowseResult> future = client.browse(new BrowseDescription(getNodeId(), BrowseDirection.Forward, Identifiers.HasTypeDefinition, false, nodeClassMask, resultMask));
return future.thenCompose(result -> {
List<ReferenceDescription> references = l(result.getReferences());
Optional<CompletableFuture<UaObjectTypeNode>> node = references.stream().flatMap(r -> {
Optional<CompletableFuture<UaObjectTypeNode>> opt = r.getNodeId().toNodeId(client.getNamespaceTable()).map(id -> client.getAddressSpace().getNodeAsync(id).thenApply(n -> (UaObjectTypeNode) n));
return opt2stream(opt);
}).findFirst();
return node.orElse(FutureUtils.failedUaFuture(StatusCodes.Bad_NotFound));
});
}
use of org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture in project milo by eclipse.
the class UaVariableNode method getTypeDefinitionAsync.
public CompletableFuture<? extends UaVariableTypeNode> getTypeDefinitionAsync() {
UInteger nodeClassMask = uint(NodeClass.VariableType.getValue());
UInteger resultMask = uint(BrowseResultMask.All.getValue());
CompletableFuture<BrowseResult> future = client.browse(new BrowseDescription(getNodeId(), BrowseDirection.Forward, Identifiers.HasTypeDefinition, false, nodeClassMask, resultMask));
return future.thenCompose(result -> {
List<ReferenceDescription> references = l(result.getReferences());
Optional<CompletableFuture<UaVariableTypeNode>> node = references.stream().flatMap(r -> {
Optional<CompletableFuture<UaVariableTypeNode>> opt = r.getNodeId().toNodeId(client.getNamespaceTable()).map(id -> client.getAddressSpace().getNodeAsync(id).thenApply(n -> (UaVariableTypeNode) n));
return opt2stream(opt);
}).findFirst();
return node.orElse(FutureUtils.failedUaFuture(StatusCodes.Bad_NotFound));
});
}
Aggregations