Search in sources :

Example 1 with BrowseRequest

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

the class DataTypeDictionaryReader method browseNode.

private CompletableFuture<List<ReferenceDescription>> browseNode(BrowseDescription browseDescription) {
    RequestHeader requestHeader = stackClient.newRequestHeader(session.getAuthenticationToken(), stackClient.getConfig().getRequestTimeout());
    BrowseRequest browseRequest = new BrowseRequest(requestHeader, new ViewDescription(NodeId.NULL_VALUE, DateTime.MIN_VALUE, uint(0)), uint(0), new BrowseDescription[] { browseDescription });
    return stackClient.sendRequest(browseRequest).thenApply(BrowseResponse.class::cast).thenApply(r -> Objects.requireNonNull(r.getResults())[0]).thenCompose(result -> {
        List<ReferenceDescription> references = Collections.synchronizedList(new ArrayList<>());
        return maybeBrowseNext(result, references);
    });
}
Also used : BrowseResponse(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResponse) BrowseNextRequest(org.eclipse.milo.opcua.stack.core.types.structured.BrowseNextRequest) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ByteString(org.eclipse.milo.opcua.stack.core.types.builtin.ByteString) LoggerFactory(org.slf4j.LoggerFactory) ReadRequest(org.eclipse.milo.opcua.stack.core.types.structured.ReadRequest) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime) DictionaryDescription(org.eclipse.milo.opcua.binaryschema.parser.DictionaryDescription) Unpooled(io.netty.buffer.Unpooled) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) ByteArrayInputStream(java.io.ByteArrayInputStream) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) BrowseDescription(org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription) Map(java.util.Map) 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) BsdParser(org.eclipse.milo.opcua.binaryschema.parser.BsdParser) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) CodecDescription(org.eclipse.milo.opcua.binaryschema.parser.CodecDescription) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) Objects(java.util.Objects) CompositeByteBuf(io.netty.buffer.CompositeByteBuf) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) FutureUtils(org.eclipse.milo.opcua.stack.core.util.FutureUtils) ByteStreams(com.google.common.io.ByteStreams) Optional(java.util.Optional) StreamUtil.opt2stream(org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream) BrowseResponse(org.eclipse.milo.opcua.stack.core.types.structured.BrowseResponse) OpcUaSession(org.eclipse.milo.opcua.sdk.client.OpcUaSession) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) BrowseRequest(org.eclipse.milo.opcua.stack.core.types.structured.BrowseRequest) DataTypeDictionary(org.eclipse.milo.opcua.stack.core.types.DataTypeDictionary) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) OpcUaBinaryDataTypeDictionary(org.eclipse.milo.opcua.stack.core.types.OpcUaBinaryDataTypeDictionary) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) RequestHeader(org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader) Lists(com.google.common.collect.Lists) ByteBuf(io.netty.buffer.ByteBuf) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) ReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse) BrowseNextResponse(org.eclipse.milo.opcua.stack.core.types.structured.BrowseNextResponse) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) UaStackClient(org.eclipse.milo.opcua.stack.client.UaStackClient) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) IOException(java.io.IOException) Ints(com.google.common.primitives.Ints) ViewDescription(org.eclipse.milo.opcua.stack.core.types.structured.ViewDescription) BrowseResultMask(org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseResultMask) FutureUtils.failedFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedFuture) Preconditions(com.google.common.base.Preconditions) Collections(java.util.Collections) InputStream(java.io.InputStream) Namespaces(org.eclipse.milo.opcua.stack.core.util.Namespaces) ViewDescription(org.eclipse.milo.opcua.stack.core.types.structured.ViewDescription) ReferenceDescription(org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription) RequestHeader(org.eclipse.milo.opcua.stack.core.types.structured.RequestHeader) BrowseRequest(org.eclipse.milo.opcua.stack.core.types.structured.BrowseRequest)

Example 2 with BrowseRequest

use of org.eclipse.milo.opcua.stack.core.types.structured.BrowseRequest 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 3 with BrowseRequest

use of org.eclipse.milo.opcua.stack.core.types.structured.BrowseRequest 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)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)2 BrowseRequest (org.eclipse.milo.opcua.stack.core.types.structured.BrowseRequest)2 BrowseResult (org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult)2 Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ByteStreams (com.google.common.io.ByteStreams)1 Ints (com.google.common.primitives.Ints)1 ByteBuf (io.netty.buffer.ByteBuf)1 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)1 Unpooled (io.netty.buffer.Unpooled)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1