Search in sources :

Example 1 with FutureUtils.failedUaFuture

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));
    });
}
Also used : ObjectNode(org.eclipse.milo.opcua.sdk.core.nodes.ObjectNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) UaMethod(org.eclipse.milo.opcua.sdk.client.methods.UaMethod) ByteString(org.eclipse.milo.opcua.stack.core.types.builtin.ByteString) CompletableFuture(java.util.concurrent.CompletableFuture) ObjectNodeProperties(org.eclipse.milo.opcua.sdk.core.nodes.ObjectNodeProperties) AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Argument(org.eclipse.milo.opcua.stack.core.types.structured.Argument) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) UShort(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) FutureUtils.failedUaFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) BrowseDirection(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection) UByte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) NamingRuleType(org.eclipse.milo.opcua.stack.core.types.enumerated.NamingRuleType) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) BrowseResultMask(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseResultMask) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) FutureUtils(org.eclipse.milo.opcua.stack.core.util.FutureUtils) FutureUtils.failedFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedFuture) UaException(org.eclipse.milo.opcua.stack.core.UaException) Optional(java.util.Optional) StreamUtil.opt2stream(org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) CompletableFuture(java.util.concurrent.CompletableFuture) Optional(java.util.Optional) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription)

Example 2 with FutureUtils.failedUaFuture

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));
    });
}
Also used : VariableNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) ByteString(org.eclipse.milo.opcua.stack.core.types.builtin.ByteString) CompletableFuture(java.util.concurrent.CompletableFuture) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) UShort(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription) VariableNodeProperties(org.eclipse.milo.opcua.sdk.core.nodes.VariableNodeProperties) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) FutureUtils.failedUaFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) BrowseDirection(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseDirection) UByte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) EUInformation(org.eclipse.milo.opcua.stack.core.types.structured.EUInformation) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) ExecutionException(java.util.concurrent.ExecutionException) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) BrowseResultMask(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseResultMask) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) TimeZoneDataType(org.eclipse.milo.opcua.stack.core.types.structured.TimeZoneDataType) FutureUtils(org.eclipse.milo.opcua.stack.core.util.FutureUtils) UaException(org.eclipse.milo.opcua.stack.core.UaException) Optional(java.util.Optional) StreamUtil.opt2stream(org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) CompletableFuture(java.util.concurrent.CompletableFuture) Optional(java.util.Optional) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription)

Aggregations

List (java.util.List)2 Optional (java.util.Optional)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 OpcUaClient (org.eclipse.milo.opcua.sdk.client.OpcUaClient)2 StreamUtil.opt2stream (org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream)2 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)2 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)2 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)2 UaException (org.eclipse.milo.opcua.stack.core.UaException)2 ByteString (org.eclipse.milo.opcua.stack.core.types.builtin.ByteString)2 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)2 LocalizedText (org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)2 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)2 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)2 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)2 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)2 UByte (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte)2 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)2 UShort (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort)2