Search in sources :

Example 1 with ReadResponse

use of org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse in project milo by eclipse.

the class AddressSpace method createObjectNodeFromBaseAttributes.

private CompletableFuture<UaObjectNode> createObjectNodeFromBaseAttributes(NodeId nodeId, List<DataValue> baseAttributeValues) {
    Set<AttributeId> remainingAttributes = Sets.difference(AttributeId.OBJECT_ATTRIBUTES, AttributeId.BASE_ATTRIBUTES);
    CompletableFuture<ReadResponse> attributesFuture = readAttributes(nodeId, remainingAttributes);
    CompletableFuture<NodeId> typeDefinitionFuture = readTypeDefinition(nodeId);
    return CompletableFuture.allOf(attributesFuture, typeDefinitionFuture).thenCompose(ignored -> {
        ReadResponse response = attributesFuture.join();
        NodeId typeDefinitionId = typeDefinitionFuture.join();
        List<DataValue> attributeValues = new ArrayList<>(baseAttributeValues);
        Collections.addAll(attributeValues, response.getResults());
        try {
            UaObjectNode node = newObjectNode(nodeId, typeDefinitionId, attributeValues);
            nodeCache.put(node.getNodeId(), node);
            return completedFuture(node);
        } catch (UaException e) {
            return failedFuture(e);
        }
    });
}
Also used : UaObjectNode(org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode) ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) UaException(org.eclipse.milo.opcua.stack.core.UaException) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) ArrayList(java.util.ArrayList)

Example 2 with ReadResponse

use of org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse in project milo by eclipse.

the class AddressSpace method createViewNodeFromBaseAttributes.

private CompletableFuture<UaViewNode> createViewNodeFromBaseAttributes(NodeId nodeId, List<DataValue> baseAttributeValues) {
    Set<AttributeId> remainingAttributes = Sets.difference(AttributeId.VIEW_ATTRIBUTES, AttributeId.BASE_ATTRIBUTES);
    CompletableFuture<ReadResponse> attributesFuture = readAttributes(nodeId, remainingAttributes);
    return attributesFuture.thenCompose(response -> {
        List<DataValue> attributeValues = new ArrayList<>(baseAttributeValues);
        Collections.addAll(attributeValues, response.getResults());
        try {
            UaViewNode node = newViewNode(nodeId, attributeValues);
            nodeCache.put(node.getNodeId(), node);
            return completedFuture(node);
        } catch (UaException e) {
            return failedFuture(e);
        }
    });
}
Also used : ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) UaException(org.eclipse.milo.opcua.stack.core.UaException) ArrayList(java.util.ArrayList) UaViewNode(org.eclipse.milo.opcua.sdk.client.nodes.UaViewNode)

Example 3 with ReadResponse

use of org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse in project milo by eclipse.

the class AddressSpace method getVariableNodeAsync.

/**
 * Get a {@link UaVariableNode} instance for the VariableNode identified by {@code nodeId},
 * assuming the type definition identified by {@code typeDefinitionId}.
 * <p>
 * If this type definition is registered with the {@link VariableTypeManager} a
 * {@link UaVariableNode} of the appropriate subclass will be returned.
 * <p>
 * This call completes asynchronously.
 *
 * @param nodeId           the {@link NodeId} identifying the VariableNode to get.
 * @param typeDefinitionId the {@link NodeId} identifying the type definition.
 * @return a CompletableFuture that completes successfully with a {@link UaVariableNode}
 * instance for the VariableNode identified by {@code nodeId} or completes exceptionally if an
 * error occurs while creating the VariableNode.
 */
public CompletableFuture<UaVariableNode> getVariableNodeAsync(NodeId nodeId, NodeId typeDefinitionId) {
    UaNode cachedNode = nodeCache.getIfPresent(nodeId);
    if (cachedNode instanceof UaVariableNode) {
        return completedFuture((UaVariableNode) cachedNode);
    } else {
        CompletableFuture<ReadResponse> future = readAttributes(nodeId, AttributeId.VARIABLE_ATTRIBUTES);
        return future.thenCompose(response -> {
            List<DataValue> attributeValues = l(response.getResults());
            try {
                UaVariableNode node = newVariableNode(nodeId, typeDefinitionId, attributeValues);
                nodeCache.put(node.getNodeId(), node);
                return completedFuture(node);
            } catch (UaException e) {
                return failedFuture(e);
            }
        });
    }
}
Also used : UaVariableNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode) ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaException(org.eclipse.milo.opcua.stack.core.UaException) UaNode(org.eclipse.milo.opcua.sdk.client.nodes.UaNode)

Example 4 with ReadResponse

use of org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse in project milo by eclipse.

the class AddressSpace method createDataTypeNodeFromBaseAttributes.

private CompletableFuture<UaDataTypeNode> createDataTypeNodeFromBaseAttributes(NodeId nodeId, List<DataValue> baseAttributeValues) {
    Set<AttributeId> remainingAttributes = Sets.difference(AttributeId.DATA_TYPE_ATTRIBUTES, AttributeId.BASE_ATTRIBUTES);
    CompletableFuture<ReadResponse> attributesFuture = readAttributes(nodeId, remainingAttributes);
    return attributesFuture.thenCompose(response -> {
        List<DataValue> attributeValues = new ArrayList<>(baseAttributeValues);
        Collections.addAll(attributeValues, response.getResults());
        try {
            UaDataTypeNode node = newDataTypeNode(nodeId, attributeValues);
            nodeCache.put(node.getNodeId(), node);
            return completedFuture(node);
        } catch (UaException e) {
            return failedFuture(e);
        }
    });
}
Also used : ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) UaException(org.eclipse.milo.opcua.stack.core.UaException) ArrayList(java.util.ArrayList) UaDataTypeNode(org.eclipse.milo.opcua.sdk.client.nodes.UaDataTypeNode)

Example 5 with ReadResponse

use of org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse in project milo by eclipse.

the class AddressSpace method createMethodNodeFromBaseAttributes.

private CompletableFuture<UaMethodNode> createMethodNodeFromBaseAttributes(NodeId nodeId, List<DataValue> baseAttributeValues) {
    Set<AttributeId> remainingAttributes = Sets.difference(AttributeId.METHOD_ATTRIBUTES, AttributeId.BASE_ATTRIBUTES);
    CompletableFuture<ReadResponse> attributesFuture = readAttributes(nodeId, remainingAttributes);
    return attributesFuture.thenCompose(response -> {
        List<DataValue> attributeValues = new ArrayList<>(baseAttributeValues);
        Collections.addAll(attributeValues, response.getResults());
        try {
            UaMethodNode node = newMethodNode(nodeId, attributeValues);
            nodeCache.put(node.getNodeId(), node);
            return completedFuture(node);
        } catch (UaException e) {
            return failedFuture(e);
        }
    });
}
Also used : UaMethodNode(org.eclipse.milo.opcua.sdk.client.nodes.UaMethodNode) ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) UaException(org.eclipse.milo.opcua.stack.core.UaException) ArrayList(java.util.ArrayList)

Aggregations

ReadResponse (org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse)15 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)14 UaException (org.eclipse.milo.opcua.stack.core.UaException)12 ArrayList (java.util.ArrayList)9 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)9 ReadValueId (org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId)5 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)3 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)3 UaNode (org.eclipse.milo.opcua.sdk.client.nodes.UaNode)2 UaObjectNode (org.eclipse.milo.opcua.sdk.client.nodes.UaObjectNode)2 UaVariableNode (org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode)2 ReadRequest (org.eclipse.milo.opcua.stack.core.types.structured.ReadRequest)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Array (java.lang.reflect.Array)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Arrays (java.util.Arrays)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1