Search in sources :

Example 1 with WriteResponse

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);
    });
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) WriteRequest(org.eclipse.milo.opcua.stack.core.types.structured.WriteRequest) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) WriteResponse(org.eclipse.milo.opcua.stack.core.types.structured.WriteResponse) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) WriteContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.WriteContext) WriteValue(org.eclipse.milo.opcua.stack.core.types.structured.WriteValue) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) Session(org.eclipse.milo.opcua.sdk.server.Session)

Example 2 with WriteResponse

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]);
}
Also used : WriteValue(org.eclipse.milo.opcua.stack.core.types.structured.WriteValue) WriteResponse(org.eclipse.milo.opcua.stack.core.types.structured.WriteResponse)

Aggregations

WriteResponse (org.eclipse.milo.opcua.stack.core.types.structured.WriteResponse)2 WriteValue (org.eclipse.milo.opcua.stack.core.types.structured.WriteValue)2 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 WriteContext (org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.WriteContext)1 DiagnosticInfo (org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo)1 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)1 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)1 WriteRequest (org.eclipse.milo.opcua.stack.core.types.structured.WriteRequest)1