use of org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader in project milo by eclipse.
the class SubscriptionManager method modifyMonitoredItems.
public void modifyMonitoredItems(ServiceRequest service) throws UaException {
ModifyMonitoredItemsRequest request = (ModifyMonitoredItemsRequest) service.getRequest();
UInteger subscriptionId = request.getSubscriptionId();
Subscription subscription = subscriptions.get(subscriptionId);
TimestampsToReturn timestamps = request.getTimestampsToReturn();
List<MonitoredItemModifyRequest> itemsToModify = l(request.getItemsToModify());
if (subscription == null) {
throw new UaException(StatusCodes.Bad_SubscriptionIdInvalid);
}
if (timestamps == null) {
throw new UaException(StatusCodes.Bad_TimestampsToReturnInvalid);
}
if (itemsToModify.isEmpty()) {
throw new UaException(StatusCodes.Bad_NothingToDo);
}
List<NodeId> distinctNodeIds = itemsToModify.stream().map(item -> {
UInteger itemId = item.getMonitoredItemId();
BaseMonitoredItem<?> monitoredItem = subscription.getMonitoredItems().get(itemId);
return monitoredItem != null ? monitoredItem.getReadValueId().getNodeId() : NodeId.NULL_VALUE;
}).filter(NodeId::isNotNull).distinct().collect(toList());
CompletableFuture<Map<NodeId, AttributeGroup>> attributesFuture = readMonitoringAttributes(distinctNodeIds);
attributesFuture.thenAccept(attributeGroups -> {
MonitoredItemModifyResult[] modifyResults = new MonitoredItemModifyResult[itemsToModify.size()];
List<BaseMonitoredItem<?>> monitoredItems = new ArrayList<>();
for (int i = 0; i < itemsToModify.size(); i++) {
MonitoredItemModifyRequest modifyRequest = itemsToModify.get(i);
try {
BaseMonitoredItem<?> monitoredItem = modifyMonitoredItem(modifyRequest, timestamps, subscription, attributeGroups);
monitoredItems.add(monitoredItem);
modifyResults[i] = new MonitoredItemModifyResult(StatusCode.GOOD, monitoredItem.getSamplingInterval(), uint(monitoredItem.getQueueSize()), monitoredItem.getFilterResult());
} catch (UaException e) {
modifyResults[i] = new MonitoredItemModifyResult(e.getStatusCode(), 0.0, UInteger.MIN, null);
}
}
subscription.resetLifetimeCounter();
/*
* Notify AddressSpaces of the items we just modified.
*/
byMonitoredItemType(monitoredItems, dataItems -> server.getAddressSpaceManager().onDataItemsModified(dataItems), eventItems -> server.getAddressSpaceManager().onEventItemsModified(eventItems));
/*
* AddressSpaces have been notified; send response.
*/
ResponseHeader header = service.createResponseHeader();
ModifyMonitoredItemsResponse response = new ModifyMonitoredItemsResponse(header, modifyResults, new DiagnosticInfo[0]);
service.setResponse(response);
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader in project milo by eclipse.
the class SubscriptionManager method modifySubscription.
public void modifySubscription(ServiceRequest service) throws UaException {
ModifySubscriptionRequest request = (ModifySubscriptionRequest) service.getRequest();
UInteger subscriptionId = request.getSubscriptionId();
Subscription subscription = subscriptions.get(subscriptionId);
if (subscription == null) {
throw new UaException(StatusCodes.Bad_SubscriptionIdInvalid);
}
subscription.modifySubscription(request);
ResponseHeader header = service.createResponseHeader();
ModifySubscriptionResponse response = new ModifySubscriptionResponse(header, subscription.getPublishingInterval(), uint(subscription.getLifetimeCount()), uint(subscription.getMaxKeepAliveCount()));
service.setResponse(response);
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader in project milo by eclipse.
the class DefaultNodeManagementServiceSet method onDeleteReferences.
@Override
public void onDeleteReferences(ServiceRequest service) {
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
DeleteReferencesRequest request = (DeleteReferencesRequest) service.getRequest();
List<DeleteReferencesItem> referencesToDelete = l(request.getReferencesToDelete());
if (referencesToDelete.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (referencesToDelete.size() > server.getConfig().getLimits().getMaxNodesPerNodeManagement().longValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
DeleteReferencesContext context = new DeleteReferencesContext(server, session, new DiagnosticsContext<>());
server.getAddressSpaceManager().deleteReferences(context, referencesToDelete);
context.getFuture().thenAccept(results -> {
ResponseHeader header = service.createResponseHeader();
DeleteReferencesResponse response = new DeleteReferencesResponse(header, a(results, StatusCode.class), new DiagnosticInfo[0]);
service.setResponse(response);
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader in project milo by eclipse.
the class DefaultNodeManagementServiceSet method onAddReferences.
@Override
public void onAddReferences(ServiceRequest service) {
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
AddReferencesRequest request = (AddReferencesRequest) service.getRequest();
List<AddReferencesItem> referencesToAdd = l(request.getReferencesToAdd());
if (referencesToAdd.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (referencesToAdd.size() > server.getConfig().getLimits().getMaxNodesPerNodeManagement().longValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
AddReferencesContext context = new AddReferencesContext(server, session, new DiagnosticsContext<>());
server.getAddressSpaceManager().addReferences(context, referencesToAdd);
context.getFuture().thenAccept(results -> {
ResponseHeader header = service.createResponseHeader();
AddReferencesResponse response = new AddReferencesResponse(header, a(results, StatusCode.class), new DiagnosticInfo[0]);
service.setResponse(response);
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader 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);
});
}
Aggregations