Search in sources :

Example 1 with BrowseResult

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

the class DataTypeDictionaryReader method browseNextAsync.

private CompletableFuture<List<ReferenceDescription>> browseNextAsync(ByteString continuationPoint, List<ReferenceDescription> references) {
    RequestHeader requestHeader = stackClient.newRequestHeader(session.getAuthenticationToken(), stackClient.getConfig().getRequestTimeout());
    BrowseNextRequest request = new BrowseNextRequest(requestHeader, false, new ByteString[] { continuationPoint });
    return stackClient.sendRequest(request).thenApply(BrowseNextResponse.class::cast).thenCompose(response -> {
        BrowseResult result = l(response.getResults()).get(0);
        return maybeBrowseNext(result, references);
    });
}
Also used : RequestHeader(org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader) BrowseNextRequest(org.eclipse.milo.opcua.stack.core.types.structured.BrowseNextRequest) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult)

Example 2 with BrowseResult

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

the class UaNode method getComponentAsync.

protected CompletableFuture<? extends UaNode> getComponentAsync(QualifiedName browseName, NodeClass nodeClass) {
    UInteger nodeClassMask = uint(nodeClass.getValue());
    UInteger resultMask = uint(BrowseResultMask.All.getValue());
    CompletableFuture<BrowseResult> future = client.browse(new BrowseDescription(getNodeId(), BrowseDirection.Forward, Identifiers.HasComponent, false, nodeClassMask, resultMask));
    return future.thenCompose(result -> {
        List<ReferenceDescription> references = l(result.getReferences());
        Optional<CompletableFuture<? extends UaNode>> node = references.stream().filter(r -> browseName.equals(r.getBrowseName())).flatMap(r -> {
            Optional<CompletableFuture<? extends UaNode>> opt = r.getNodeId().toNodeId(client.getNamespaceTable()).map(id -> client.getAddressSpace().getNodeAsync(id));
            return opt2stream(opt);
        }).findFirst();
        return node.orElse(failedUaFuture(StatusCodes.Bad_NotFound));
    });
}
Also used : QualifiedProperty(org.eclipse.milo.opcua.sdk.core.QualifiedProperty) Arrays(java.util.Arrays) Array(java.lang.reflect.Array) WriteValue(org.eclipse.milo.opcua.stack.core.types.structured.WriteValue) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) WriteResponse(org.eclipse.milo.opcua.stack.core.types.structured.WriteResponse) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) 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) BrowsePath(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePath) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) Set(java.util.Set) UaEnumeration(org.eclipse.milo.opcua.stack.core.serialization.UaEnumeration) Collectors(java.util.stream.Collectors) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) 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) Optional(java.util.Optional) Node(org.eclipse.milo.opcua.sdk.core.nodes.Node) StreamUtil.opt2stream(org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) BrowseOptions(org.eclipse.milo.opcua.sdk.client.AddressSpace.BrowseOptions) UaStructure(org.eclipse.milo.opcua.stack.core.serialization.UaStructure) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) UShort(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort) ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) FutureUtils.failedUaFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture) Iterator(java.util.Iterator) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) RelativePathElement(org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement) PropertyTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.variables.PropertyTypeNode) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) BrowsePathResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult) RelativePath(org.eclipse.milo.opcua.stack.core.types.structured.RelativePath) BrowseResultMask(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseResultMask) FutureUtils.failedFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedFuture) UaException(org.eclipse.milo.opcua.stack.core.UaException) 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 3 with BrowseResult

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

the class BrowseHelper method browse.

public static CompletableFuture<List<ReferenceDescription>> browse(UaStackClient client, OpcUaSession session, BrowseDescription browseDescription, UInteger maxReferencesPerNode) {
    BrowseRequest browseRequest = new BrowseRequest(client.newRequestHeader(session.getAuthenticationToken(), client.getConfig().getRequestTimeout()), new ViewDescription(NodeId.NULL_VALUE, DateTime.MIN_VALUE, uint(0)), maxReferencesPerNode, new BrowseDescription[] { browseDescription });
    return client.sendRequest(browseRequest).thenApply(BrowseResponse.class::cast).thenCompose(response -> {
        BrowseResult result = response.getResults()[0];
        List<ReferenceDescription> references = Collections.synchronizedList(new ArrayList<>());
        return maybeBrowseNext(client, session, references, result);
    });
}
Also used : ViewDescription(org.eclipse.milo.opcua.stack.core.types.structured.ViewDescription) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) BrowseRequest(org.eclipse.milo.opcua.stack.core.types.structured.BrowseRequest) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult)

Example 4 with BrowseResult

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

the class DefaultViewServiceSet method onBrowse.

@Override
public void onBrowse(ServiceRequest service) {
    browseCounter.record(service);
    BrowseRequest request = (BrowseRequest) service.getRequest();
    DiagnosticsContext<BrowseDescription> diagnosticsContext = new DiagnosticsContext<>();
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    List<BrowseDescription> nodesToBrowse = l(request.getNodesToBrowse());
    if (nodesToBrowse.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (nodesToBrowse.size() > server.getConfig().getLimits().getMaxNodesPerBrowse().intValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    Stream<CompletableFuture<BrowseResult>> futures = nodesToBrowse.stream().map(browseDescription -> browseHelper.browse(() -> Optional.of(session), server, request.getView(), request.getRequestedMaxReferencesPerNode(), browseDescription));
    FutureUtils.sequence(futures).thenAccept(results -> {
        ResponseHeader header = service.createResponseHeader();
        DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(nodesToBrowse);
        BrowseResponse response = new BrowseResponse(header, a(results, BrowseResult.class), diagnosticInfos);
        service.setResponse(response);
    });
}
Also used : BrowseResponse(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResponse) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) BrowseRequest(org.eclipse.milo.opcua.stack.core.types.structured.BrowseRequest) CompletableFuture(java.util.concurrent.CompletableFuture) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) BrowseResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription) Session(org.eclipse.milo.opcua.sdk.server.Session)

Example 5 with BrowseResult

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

the class UaNode method getPropertyNodeAsync.

protected CompletableFuture<PropertyTypeNode> getPropertyNodeAsync(QualifiedName browseName) {
    UInteger nodeClassMask = uint(NodeClass.Variable.getValue());
    UInteger resultMask = uint(BrowseResultMask.BrowseName.getValue());
    CompletableFuture<BrowseResult> future = client.browse(new BrowseDescription(getNodeId(), BrowseDirection.Forward, Identifiers.HasProperty, false, nodeClassMask, resultMask));
    return future.thenCompose(result -> {
        List<ReferenceDescription> references = l(result.getReferences());
        Optional<CompletableFuture<PropertyTypeNode>> node = references.stream().filter(r -> browseName.equals(r.getBrowseName())).flatMap(r -> {
            Optional<CompletableFuture<PropertyTypeNode>> opt = r.getNodeId().toNodeId(client.getNamespaceTable()).map(id -> client.getAddressSpace().getNodeAsync(id).thenApply(n -> (PropertyTypeNode) n));
            return opt2stream(opt);
        }).findFirst();
        return node.orElse(failedUaFuture(StatusCodes.Bad_NotFound));
    });
}
Also used : QualifiedProperty(org.eclipse.milo.opcua.sdk.core.QualifiedProperty) Arrays(java.util.Arrays) Array(java.lang.reflect.Array) WriteValue(org.eclipse.milo.opcua.stack.core.types.structured.WriteValue) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) AddressSpace(org.eclipse.milo.opcua.sdk.client.AddressSpace) WriteResponse(org.eclipse.milo.opcua.stack.core.types.structured.WriteResponse) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) 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) BrowsePath(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePath) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) Set(java.util.Set) UaEnumeration(org.eclipse.milo.opcua.stack.core.serialization.UaEnumeration) Collectors(java.util.stream.Collectors) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) 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) Optional(java.util.Optional) Node(org.eclipse.milo.opcua.sdk.core.nodes.Node) StreamUtil.opt2stream(org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) BrowseOptions(org.eclipse.milo.opcua.sdk.client.AddressSpace.BrowseOptions) UaStructure(org.eclipse.milo.opcua.stack.core.serialization.UaStructure) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) UShort(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort) ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) FutureUtils.failedUaFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture) Iterator(java.util.Iterator) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) RelativePathElement(org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement) PropertyTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.variables.PropertyTypeNode) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) BrowsePathResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult) RelativePath(org.eclipse.milo.opcua.stack.core.types.structured.RelativePath) BrowseResultMask(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseResultMask) FutureUtils.failedFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedFuture) UaException(org.eclipse.milo.opcua.stack.core.UaException) 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) PropertyTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.variables.PropertyTypeNode) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription)

Aggregations

BrowseResult (org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult)9 CompletableFuture (java.util.concurrent.CompletableFuture)6 ExecutionException (java.util.concurrent.ExecutionException)6 BrowseDescription (org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription)6 ReferenceDescription (org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription)6 List (java.util.List)5 Optional (java.util.Optional)5 OpcUaClient (org.eclipse.milo.opcua.sdk.client.OpcUaClient)5 StreamUtil.opt2stream (org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream)5 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)5 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)5 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)5 UaException (org.eclipse.milo.opcua.stack.core.UaException)5 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)5 LocalizedText (org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)5 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)5 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)5 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)5 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)5 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)5