use of org.eclipse.milo.opcua.stack.core.types.structured.WriteResponse in project milo by eclipse.
the class DefaultAttributeServiceSet method onWrite.
@Override
public void onWrite(ServiceRequest service) {
WriteRequest request = (WriteRequest) service.getRequest();
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
List<WriteValue> nodesToWrite = l(request.getNodesToWrite());
if (nodesToWrite.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (nodesToWrite.size() > server.getConfig().getLimits().getMaxNodesPerWrite().intValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
DiagnosticsContext<WriteValue> diagnosticsContext = new DiagnosticsContext<>();
WriteContext context = new WriteContext(server, session, new DiagnosticsContext<>());
server.getAddressSpaceManager().write(context, nodesToWrite);
context.getFuture().thenAccept(values -> {
ResponseHeader header = service.createResponseHeader();
DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(nodesToWrite);
WriteResponse response = new WriteResponse(header, values.toArray(new StatusCode[0]), diagnosticInfos);
service.setResponse(response);
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.WriteResponse in project milo by eclipse.
the class UaNode method writeAttributeAsync.
/**
* An asynchronous implementation of {@link #writeAttribute(AttributeId, DataValue)}.
*
* @return a CompletableFuture that completes successfully with the operation result or
* completes exceptionally if a service-level error occurs.
*/
public CompletableFuture<StatusCode> writeAttributeAsync(AttributeId attributeId, DataValue value) {
WriteValue writeValue = new WriteValue(getNodeId(), attributeId.uid(), null, value);
CompletableFuture<WriteResponse> future = client.write(newArrayList(writeValue));
return future.thenApply(response -> response.getResults()[0]);
}
Aggregations