use of org.eclipse.milo.opcua.sdk.server.DiagnosticsContext 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);
});
}
use of org.eclipse.milo.opcua.sdk.server.DiagnosticsContext 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.sdk.server.DiagnosticsContext in project milo by eclipse.
the class DefaultAttributeHistoryServiceSet method onHistoryUpdate.
@Override
public void onHistoryUpdate(ServiceRequest service) {
historyUpdateMetric.record(service);
HistoryUpdateRequest request = (HistoryUpdateRequest) service.getRequest();
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
List<HistoryUpdateDetails> historyUpdateDetailsList = l(request.getHistoryUpdateDetails()).stream().map(e -> (HistoryUpdateDetails) e.decode(server.getSerializationContext())).collect(Collectors.toList());
if (historyUpdateDetailsList.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (historyUpdateDetailsList.size() > server.getConfig().getLimits().getMaxNodesPerWrite().intValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
DiagnosticsContext<HistoryUpdateDetails> diagnosticsContext = new DiagnosticsContext<>();
HistoryUpdateContext context = new HistoryUpdateContext(server, session, diagnosticsContext);
server.getAddressSpaceManager().historyUpdate(context, historyUpdateDetailsList);
context.getFuture().thenAccept(values -> {
ResponseHeader header = service.createResponseHeader();
DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(historyUpdateDetailsList);
HistoryUpdateResponse response = new HistoryUpdateResponse(header, a(values, HistoryUpdateResult.class), diagnosticInfos);
service.setResponse(response);
});
}
use of org.eclipse.milo.opcua.sdk.server.DiagnosticsContext in project milo by eclipse.
the class DefaultAttributeHistoryServiceSet method onHistoryRead.
@Override
public void onHistoryRead(ServiceRequest service) {
historyReadMetric.record(service);
HistoryReadRequest request = (HistoryReadRequest) service.getRequest();
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
List<HistoryReadValueId> 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.getTimestampsToReturn() == null) {
service.setServiceFault(StatusCodes.Bad_TimestampsToReturnInvalid);
return;
}
DiagnosticsContext<HistoryReadValueId> diagnosticsContext = new DiagnosticsContext<>();
HistoryReadContext context = new HistoryReadContext(server, session, diagnosticsContext);
HistoryReadDetails details = (HistoryReadDetails) request.getHistoryReadDetails().decode(server.getSerializationContext());
server.getAddressSpaceManager().historyRead(context, details, request.getTimestampsToReturn(), nodesToRead);
context.getFuture().thenAccept(values -> {
ResponseHeader header = service.createResponseHeader();
DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(nodesToRead);
HistoryReadResponse response = new HistoryReadResponse(header, a(values, HistoryReadResult.class), diagnosticInfos);
service.setResponse(response);
});
}
use of org.eclipse.milo.opcua.sdk.server.DiagnosticsContext in project milo by eclipse.
the class DefaultMethodServiceSet method onCall.
@Override
public void onCall(ServiceRequest service) {
callCounter.record(service);
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
CallRequest request = (CallRequest) service.getRequest();
List<CallMethodRequest> methodsToCall = l(request.getMethodsToCall());
if (methodsToCall.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (methodsToCall.size() > server.getConfig().getLimits().getMaxNodesPerMethodCall().longValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
DiagnosticsContext<CallMethodRequest> diagnosticsContext = new DiagnosticsContext<>();
CallContext context = new CallContext(server, session, diagnosticsContext);
server.getAddressSpaceManager().call(context, methodsToCall);
context.getFuture().thenAccept(values -> {
ResponseHeader header = service.createResponseHeader();
CallResponse response = new CallResponse(header, a(values, CallMethodResult.class), new DiagnosticInfo[0]);
service.setResponse(response);
});
}
Aggregations