Search in sources :

Example 1 with ReadContext

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);
    });
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) ReadContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext) ReadRequest(org.eclipse.milo.opcua.stack.core.types.structured.ReadRequest) Session(org.eclipse.milo.opcua.sdk.server.Session)

Example 2 with ReadContext

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;
    });
}
Also used : AttributeKey(io.netty.util.AttributeKey) MonitoringParameters(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters) ReadContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext) DeadbandType(org.eclipse.milo.opcua.stack.core.types.enumerated.DeadbandType) DataItem(org.eclipse.milo.opcua.sdk.server.api.DataItem) LoggerFactory(org.slf4j.LoggerFactory) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) PublishRequest(org.eclipse.milo.opcua.stack.core.types.structured.PublishRequest) MonitoredItemCreateRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemCreateRequest) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) Map(java.util.Map) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) CreateSubscriptionResponse(org.eclipse.milo.opcua.stack.core.types.structured.CreateSubscriptionResponse) ModifySubscriptionRequest(org.eclipse.milo.opcua.stack.core.types.structured.ModifySubscriptionRequest) EnumSet(java.util.EnumSet) Reference(org.eclipse.milo.opcua.sdk.core.Reference) EventItem(org.eclipse.milo.opcua.sdk.server.api.EventItem) DataChangeFilter(org.eclipse.milo.opcua.stack.core.types.structured.DataChangeFilter) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UByte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte) ModifyMonitoredItemsRequest(org.eclipse.milo.opcua.stack.core.types.structured.ModifyMonitoredItemsRequest) NumericRange(org.eclipse.milo.opcua.sdk.core.NumericRange) MonitoringFilter(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringFilter) RepublishResponse(org.eclipse.milo.opcua.stack.core.types.structured.RepublishResponse) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) SetPublishingModeResponse(org.eclipse.milo.opcua.stack.core.types.structured.SetPublishingModeResponse) SubscriptionAcknowledgement(org.eclipse.milo.opcua.stack.core.types.structured.SubscriptionAcknowledgement) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SetMonitoringModeRequest(org.eclipse.milo.opcua.stack.core.types.structured.SetMonitoringModeRequest) Stream(java.util.stream.Stream) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) StreamUtil.opt2stream(org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream) DeleteSubscriptionsResponse(org.eclipse.milo.opcua.stack.core.types.structured.DeleteSubscriptionsResponse) CreateSubscriptionRequest(org.eclipse.milo.opcua.stack.core.types.structured.CreateSubscriptionRequest) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) MonitoringMode(org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode) State(org.eclipse.milo.opcua.sdk.server.subscriptions.Subscription.State) SetMonitoringModeResponse(org.eclipse.milo.opcua.stack.core.types.structured.SetMonitoringModeResponse) EventFilter(org.eclipse.milo.opcua.stack.core.types.structured.EventFilter) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) NotificationMessage(org.eclipse.milo.opcua.stack.core.types.structured.NotificationMessage) MonitoredEventItem(org.eclipse.milo.opcua.sdk.server.items.MonitoredEventItem) CreateMonitoredItemsResponse(org.eclipse.milo.opcua.stack.core.types.structured.CreateMonitoredItemsResponse) RepublishRequest(org.eclipse.milo.opcua.stack.core.types.structured.RepublishRequest) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ModifyMonitoredItemsResponse(org.eclipse.milo.opcua.stack.core.types.structured.ModifyMonitoredItemsResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Session(org.eclipse.milo.opcua.sdk.server.Session) ArrayList(java.util.ArrayList) AccessLevel(org.eclipse.milo.opcua.sdk.core.AccessLevel) Lists(com.google.common.collect.Lists) MonitoredItemModifyRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyRequest) ServiceRequest(org.eclipse.milo.opcua.stack.server.services.ServiceRequest) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) DeleteSubscriptionsRequest(org.eclipse.milo.opcua.stack.core.types.structured.DeleteSubscriptionsRequest) SetTriggeringResponse(org.eclipse.milo.opcua.stack.core.types.structured.SetTriggeringResponse) DeleteMonitoredItemsRequest(org.eclipse.milo.opcua.stack.core.types.structured.DeleteMonitoredItemsRequest) DeleteMonitoredItemsResponse(org.eclipse.milo.opcua.stack.core.types.structured.DeleteMonitoredItemsResponse) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) Logger(org.slf4j.Logger) Lists.newArrayListWithCapacity(com.google.common.collect.Lists.newArrayListWithCapacity) Iterator(java.util.Iterator) MonitoredDataItem(org.eclipse.milo.opcua.sdk.server.items.MonitoredDataItem) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) MonitoredItemModifyResult(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyResult) UaSerializationException(org.eclipse.milo.opcua.stack.core.UaSerializationException) SetTriggeringRequest(org.eclipse.milo.opcua.stack.core.types.structured.SetTriggeringRequest) Maps(com.google.common.collect.Maps) Unsigned.ubyte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ubyte) MonitoredItemCreateResult(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemCreateResult) Consumer(java.util.function.Consumer) MonitoredItem(org.eclipse.milo.opcua.sdk.server.api.MonitoredItem) CreateMonitoredItemsRequest(org.eclipse.milo.opcua.stack.core.types.structured.CreateMonitoredItemsRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) BaseMonitoredItem(org.eclipse.milo.opcua.sdk.server.items.BaseMonitoredItem) SetPublishingModeRequest(org.eclipse.milo.opcua.stack.core.types.structured.SetPublishingModeRequest) Collectors.toList(java.util.stream.Collectors.toList) ModifySubscriptionResponse(org.eclipse.milo.opcua.stack.core.types.structured.ModifySubscriptionResponse) UaException(org.eclipse.milo.opcua.stack.core.UaException) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) Function(java.util.function.Function) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) HashMap(java.util.HashMap) ReadContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)

Example 3 with ReadContext

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()));
}
Also used : ReadContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) FutureUtils.sequence(org.eclipse.milo.opcua.stack.core.util.FutureUtils.sequence) CompletableFuture(java.util.concurrent.CompletableFuture) ConversionUtil.a(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.a) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) ServiceRequest(org.eclipse.milo.opcua.stack.server.services.ServiceRequest) BrowsePathTarget(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathTarget) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) TranslateBrowsePathsToNodeIdsRequest(org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsRequest) ServiceAttributes(org.eclipse.milo.opcua.sdk.server.services.ServiceAttributes) Reference(org.eclipse.milo.opcua.sdk.core.Reference) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) FutureUtils.failedUaFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture) Lists.newArrayListWithCapacity(com.google.common.collect.Lists.newArrayListWithCapacity) BrowsePath(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePath) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) RelativePathElement(org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) BrowsePathResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) RelativePath(org.eclipse.milo.opcua.stack.core.types.structured.RelativePath) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) AccessContext(org.eclipse.milo.opcua.sdk.server.api.AccessContext) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) UaException(org.eclipse.milo.opcua.stack.core.UaException) TranslateBrowsePathsToNodeIdsResponse(org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsResponse) Optional(java.util.Optional) BrowseContext(org.eclipse.milo.opcua.sdk.server.api.services.ViewServices.BrowseContext) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) Collections(java.util.Collections) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) CompletableFuture(java.util.concurrent.CompletableFuture) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) ReadContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList)

Aggregations

OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)3 ReadContext (org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext)3 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)3 DiagnosticInfo (org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo)3 ReadValueId (org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId)3 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)3 Lists.newArrayListWithCapacity (com.google.common.collect.Lists.newArrayListWithCapacity)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Collectors.toList (java.util.stream.Collectors.toList)2 Reference (org.eclipse.milo.opcua.sdk.core.Reference)2 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)2 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)2 UaException (org.eclipse.milo.opcua.stack.core.UaException)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 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)2 Unsigned.uint (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)2 TimestampsToReturn (org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn)2