use of org.eclipse.milo.opcua.sdk.server.OpcUaServer 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);
});
}
use of org.eclipse.milo.opcua.sdk.server.OpcUaServer in project milo by eclipse.
the class BrowsePathsHelper method onTranslateBrowsePaths.
public void onTranslateBrowsePaths(ServiceRequest service) {
TranslateBrowsePathsToNodeIdsRequest request = (TranslateBrowsePathsToNodeIdsRequest) service.getRequest();
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
List<BrowsePath> browsePaths = l(request.getBrowsePaths());
if (browsePaths.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (browsePaths.size() > server.getConfig().getLimits().getMaxNodesPerTranslateBrowsePathsToNodeIds().intValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
List<CompletableFuture<BrowsePathResult>> futures = newArrayListWithCapacity(browsePaths.size());
for (BrowsePath browsePath : browsePaths) {
futures.add(translate(browsePath));
}
sequence(futures).thenAcceptAsync(results -> {
ResponseHeader header = service.createResponseHeader();
TranslateBrowsePathsToNodeIdsResponse response = new TranslateBrowsePathsToNodeIdsResponse(header, a(results, BrowsePathResult.class), new DiagnosticInfo[0]);
service.setResponse(response);
}, server.getExecutorService());
}
use of org.eclipse.milo.opcua.sdk.server.OpcUaServer in project milo by eclipse.
the class DefaultNodeManagementServiceSet method onAddNodes.
@Override
public void onAddNodes(ServiceRequest service) {
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
AddNodesRequest request = (AddNodesRequest) service.getRequest();
List<AddNodesItem> nodesToAdd = l(request.getNodesToAdd());
if (nodesToAdd.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (nodesToAdd.size() > server.getConfig().getLimits().getMaxNodesPerNodeManagement().longValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
AddNodesContext context = new AddNodesContext(server, session, new DiagnosticsContext<>());
server.getAddressSpaceManager().addNodes(context, nodesToAdd);
context.getFuture().thenAccept(results -> {
ResponseHeader header = service.createResponseHeader();
AddNodesResponse response = new AddNodesResponse(header, a(results, AddNodesResult.class), new DiagnosticInfo[0]);
service.setResponse(response);
});
}
use of org.eclipse.milo.opcua.sdk.server.OpcUaServer in project milo by eclipse.
the class DefaultNodeManagementServiceSet method onDeleteNodes.
@Override
public void onDeleteNodes(ServiceRequest service) {
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
DeleteNodesRequest request = (DeleteNodesRequest) service.getRequest();
List<DeleteNodesItem> nodesToDelete = l(request.getNodesToDelete());
if (nodesToDelete.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (nodesToDelete.size() > server.getConfig().getLimits().getMaxNodesPerNodeManagement().longValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
DeleteNodesContext context = new DeleteNodesContext(server, session, new DiagnosticsContext<>());
server.getAddressSpaceManager().deleteNodes(context, nodesToDelete);
context.getFuture().thenAccept(results -> {
ResponseHeader header = service.createResponseHeader();
DeleteNodesResponse response = new DeleteNodesResponse(header, a(results, StatusCode.class), new DiagnosticInfo[0]);
service.setResponse(response);
});
}
Aggregations