use of org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext in project milo by eclipse.
the class DefaultAttributeServiceSet method onRead.
@Override
public void onRead(ServiceRequest service) {
ReadRequest request = (ReadRequest) service.getRequest();
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
List<ReadValueId> nodesToRead = l(request.getNodesToRead());
if (nodesToRead.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (nodesToRead.size() > server.getConfig().getLimits().getMaxNodesPerRead().longValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
if (request.getMaxAge() < 0d) {
service.setServiceFault(StatusCodes.Bad_MaxAgeInvalid);
return;
}
if (request.getTimestampsToReturn() == null) {
service.setServiceFault(StatusCodes.Bad_TimestampsToReturnInvalid);
return;
}
DiagnosticsContext<ReadValueId> diagnosticsContext = new DiagnosticsContext<>();
ReadContext context = new ReadContext(server, session, diagnosticsContext);
server.getAddressSpaceManager().read(context, request.getMaxAge(), request.getTimestampsToReturn(), nodesToRead);
context.getFuture().thenAccept(values -> {
ResponseHeader header = service.createResponseHeader();
DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(nodesToRead);
ReadResponse response = new ReadResponse(header, values.toArray(new DataValue[0]), diagnosticInfos);
service.setResponse(response);
});
}
use of org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext in project milo by eclipse.
the class SubscriptionManager method readMonitoringAttributes.
private CompletableFuture<Map<NodeId, AttributeGroup>> readMonitoringAttributes(List<NodeId> nodeIds) {
List<ReadValueId> attributesToRead = nodeIds.stream().flatMap(nodeId -> {
Function<AttributeId, ReadValueId> f = id -> new ReadValueId(nodeId, id.uid(), null, QualifiedName.NULL_VALUE);
return Stream.of(f.apply(AttributeId.AccessLevel), f.apply(AttributeId.UserAccessLevel), f.apply(AttributeId.EventNotifier), f.apply(AttributeId.MinimumSamplingInterval), f.apply(AttributeId.DataType));
}).collect(toList());
ReadContext context = new ReadContext(server, session);
server.getAddressSpaceManager().read(context, 0.0, TimestampsToReturn.Neither, attributesToRead);
return context.getFuture().thenApply(attributeValues -> {
Map<NodeId, AttributeGroup> monitoringAttributes = new HashMap<>();
for (int nodeIdx = 0, attrIdx = 0; nodeIdx < nodeIds.size(); nodeIdx++, attrIdx += 5) {
monitoringAttributes.put(nodeIds.get(nodeIdx), new AttributeGroup(attributeValues.get(attrIdx), attributeValues.get(attrIdx + 1), attributeValues.get(attrIdx + 2), attributeValues.get(attrIdx + 3), attributeValues.get(attrIdx + 4)));
}
return monitoringAttributes;
});
}
use of org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext in project milo by eclipse.
the class BrowsePathsHelper method readTargetBrowseNames.
private CompletableFuture<List<QualifiedName>> readTargetBrowseNames(List<ExpandedNodeId> targetNodeIds) {
List<CompletableFuture<List<DataValue>>> futures = newArrayListWithCapacity(targetNodeIds.size());
for (ExpandedNodeId xni : targetNodeIds) {
CompletableFuture<List<DataValue>> future = xni.toNodeId(server.getNamespaceTable()).map(nodeId -> {
ReadValueId readValueId = new ReadValueId(nodeId, AttributeId.BrowseName.uid(), null, QualifiedName.NULL_VALUE);
ReadContext context = new ReadContext(server, null);
server.getAddressSpaceManager().read(context, 0.0, TimestampsToReturn.Neither, newArrayList(readValueId));
return context.getFuture();
}).orElse(completedFuture(newArrayList(new DataValue(StatusCodes.Bad_NodeIdUnknown))));
futures.add(future);
}
return sequence(futures).thenApply(values -> values.stream().map(l -> {
DataValue v = l.get(0);
return (QualifiedName) v.getValue().getValue();
}).collect(toList()));
}
Aggregations