Search in sources :

Example 1 with BrowseResponse

use of org.eclipse.milo.opcua.stack.core.types.structured.BrowseResponse 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)1 DiagnosticsContext (org.eclipse.milo.opcua.sdk.server.DiagnosticsContext)1 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)1 Session (org.eclipse.milo.opcua.sdk.server.Session)1 DiagnosticInfo (org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo)1 BrowseDescription (org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription)1 BrowseRequest (org.eclipse.milo.opcua.stack.core.types.structured.BrowseRequest)1 BrowseResponse (org.eclipse.milo.opcua.stack.core.types.structured.BrowseResponse)1 BrowseResult (org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult)1 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)1