use of org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse in project milo by eclipse.
the class AddressSpace method createVariableNodeFromBaseAttributes.
private CompletableFuture<UaVariableNode> createVariableNodeFromBaseAttributes(NodeId nodeId, List<DataValue> baseAttributeValues) {
Set<AttributeId> remainingAttributes = Sets.difference(AttributeId.VARIABLE_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 {
UaVariableNode node = newVariableNode(nodeId, typeDefinitionId, attributeValues);
nodeCache.put(node.getNodeId(), node);
return completedFuture(node);
} catch (UaException e) {
return failedFuture(e);
}
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse in project milo by eclipse.
the class AddressSpace method getObjectNodeAsync.
/**
* Get a {@link UaObjectNode} instance for the ObjectNode identified by {@code nodeId},
* assuming the type definition identified by {@code typeDefinitionId}.
* <p>
* If this type definition is registered with the {@link ObjectTypeManager} a
* {@link UaObjectNode} of the appropriate subclass will be returned.
* <p>
* This call completes asynchronously.
*
* @param nodeId the {@link NodeId} identifying the ObjectNode to get.
* @param typeDefinitionId the {@link NodeId} identifying the type definition.
* @return a CompletableFuture that completes successfully with a {@link UaObjectNode} instance
* for the ObjectNode identified by {@code nodeId} or completes exceptionally if an error
* occurs creating the ObjectNode.
*/
public CompletableFuture<UaObjectNode> getObjectNodeAsync(NodeId nodeId, NodeId typeDefinitionId) {
UaNode cachedNode = nodeCache.getIfPresent(nodeId);
if (cachedNode instanceof UaObjectNode) {
return completedFuture((UaObjectNode) cachedNode);
} else {
CompletableFuture<ReadResponse> future = readAttributes(nodeId, AttributeId.OBJECT_ATTRIBUTES);
return future.thenCompose(response -> {
List<DataValue> attributeValues = l(response.getResults());
try {
UaObjectNode node = newObjectNode(nodeId, typeDefinitionId, attributeValues);
nodeCache.put(node.getNodeId(), node);
return completedFuture(node);
} catch (UaException e) {
return failedFuture(e);
}
});
}
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse in project milo by eclipse.
the class AddressSpace method createReferenceTypeNodeFromBaseAttributes.
private CompletableFuture<UaReferenceTypeNode> createReferenceTypeNodeFromBaseAttributes(NodeId nodeId, List<DataValue> baseAttributeValues) {
Set<AttributeId> remainingAttributes = Sets.difference(AttributeId.REFERENCE_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 {
UaReferenceTypeNode node = newReferenceTypeNode(nodeId, attributeValues);
nodeCache.put(node.getNodeId(), node);
return completedFuture(node);
} catch (UaException e) {
return failedFuture(e);
}
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse in project milo by eclipse.
the class AddressSpace method createObjectTypeNodeFromBaseAttributes.
private CompletableFuture<UaObjectTypeNode> createObjectTypeNodeFromBaseAttributes(NodeId nodeId, List<DataValue> baseAttributeValues) {
Set<AttributeId> remainingAttributes = Sets.difference(AttributeId.OBJECT_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 {
UaObjectTypeNode node = newObjectTypeNode(nodeId, attributeValues);
nodeCache.put(node.getNodeId(), node);
return completedFuture(node);
} catch (UaException e) {
return failedFuture(e);
}
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse in project milo by eclipse.
the class ClientServerTest method setReadRequestHandler.
private void setReadRequestHandler(Variant variant) {
server.addServiceHandler("/test", ReadRequest.TYPE_ID, service -> {
ReadRequest request = (ReadRequest) service.getRequest();
ResponseHeader header = new ResponseHeader(DateTime.now(), request.getRequestHeader().getRequestHandle(), StatusCode.GOOD, null, null, null);
List<ReadValueId> nodesToRead = l(request.getNodesToRead());
List<DataValue> results = Collections.nCopies(nodesToRead.size(), new DataValue(variant));
ReadResponse response = new ReadResponse(header, a(results, DataValue.class), null);
service.setResponse(response);
});
}
Aggregations