use of org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode in project milo by eclipse.
the class UaDataTypeNode method readIsAbstract.
/**
* Read the IsAbstract attribute for this Node from the server and update the local
* attribute if the operation succeeds.
*
* @return the {@link Boolean} read from the server.
* @throws UaException if a service- or operation-level error occurs.s
*/
public Boolean readIsAbstract() throws UaException {
DataValue value = readAttribute(AttributeId.IsAbstract);
StatusCode statusCode = value.getStatusCode();
if (statusCode != null && statusCode.isBad()) {
throw new UaException(statusCode, "read IsAbstract failed");
} else {
Boolean isAbstract = (Boolean) value.getValue().getValue();
setIsAbstract(isAbstract);
return isAbstract;
}
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode in project milo by eclipse.
the class UaMethodNode method writeUserExecutable.
/**
* Write a new UserExecutable attribute for this Node to the server and update the local
* attribute if the operation succeeds.
*
* @param userExecutable the {@link Boolean} to write to the server.
* @throws UaException if a service- or operation-level error occurs.
*/
public void writeUserExecutable(Boolean userExecutable) throws UaException {
DataValue value = DataValue.valueOnly(new Variant(userExecutable));
StatusCode statusCode = writeAttribute(AttributeId.UserExecutable, value);
if (statusCode != null && statusCode.isBad()) {
throw new UaException(statusCode, "write UserExecutable failed");
} else {
setUserExecutable(userExecutable);
}
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode in project milo by eclipse.
the class SubscriptionManager method publish.
public void publish(ServiceRequest service) {
PublishRequest request = (PublishRequest) service.getRequest();
SubscriptionAcknowledgement[] acknowledgements = request.getSubscriptionAcknowledgements();
if (acknowledgements != null) {
StatusCode[] results = new StatusCode[acknowledgements.length];
for (int i = 0; i < acknowledgements.length; i++) {
SubscriptionAcknowledgement acknowledgement = acknowledgements[i];
UInteger sequenceNumber = acknowledgement.getSequenceNumber();
UInteger subscriptionId = acknowledgement.getSubscriptionId();
Subscription subscription = subscriptions.get(subscriptionId);
if (subscription == null) {
logger.debug("Can't acknowledge sequenceNumber={} on subscriptionId={}; id not valid for this session", sequenceNumber, subscriptionId);
results[i] = new StatusCode(StatusCodes.Bad_SubscriptionIdInvalid);
} else {
logger.debug("Acknowledging sequenceNumber={} on subscriptionId={}", sequenceNumber, subscriptionId);
results[i] = subscription.acknowledge(sequenceNumber);
}
}
service.attr(KEY_ACK_RESULTS).set(results);
}
if (!transferred.isEmpty()) {
Subscription subscription = transferred.remove(0);
subscription.returnStatusChangeNotification(service, new StatusCode(StatusCodes.Good_SubscriptionTransferred));
return;
}
if (subscriptions.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NoSubscription);
return;
}
publishQueue.addRequest(service);
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode in project milo by eclipse.
the class DefaultSubscriptionServiceSet method onTransferSubscriptions.
@Override
public void onTransferSubscriptions(ServiceRequest service) throws UaException {
TransferSubscriptionsRequest request = (TransferSubscriptionsRequest) service.getRequest();
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
List<UInteger> subscriptionIds = l(request.getSubscriptionIds());
if (subscriptionIds.isEmpty()) {
throw new UaException(StatusCodes.Bad_NothingToDo);
}
List<TransferResult> results = Lists.newArrayList();
for (UInteger subscriptionId : subscriptionIds) {
Subscription subscription = server.getSubscriptions().get(subscriptionId);
if (subscription == null) {
results.add(new TransferResult(new StatusCode(StatusCodes.Bad_SubscriptionIdInvalid), new UInteger[0]));
} else {
Session otherSession = subscription.getSession();
if (!sessionsHaveSameUser(session, otherSession)) {
results.add(new TransferResult(new StatusCode(StatusCodes.Bad_UserAccessDenied), new UInteger[0]));
} else {
UInteger[] availableSequenceNumbers;
synchronized (subscription) {
otherSession.getSubscriptionManager().sendStatusChangeNotification(subscription, new StatusCode(StatusCodes.Good_SubscriptionTransferred));
otherSession.getSubscriptionManager().removeSubscription(subscriptionId);
subscription.setSubscriptionManager(session.getSubscriptionManager());
subscriptionManager.addSubscription(subscription);
subscription.getMonitoredItems().values().forEach(item -> item.setSession(session));
availableSequenceNumbers = subscription.getAvailableSequenceNumbers();
if (request.getSendInitialValues()) {
subscription.getMonitoredItems().values().stream().filter(item -> item instanceof MonitoredDataItem).map(item -> (MonitoredDataItem) item).forEach(MonitoredDataItem::maybeSendLastValue);
}
}
subscription.getSubscriptionDiagnostics().getTransferRequestCount().increment();
ApplicationDescription toClient = session.getClientDescription();
ApplicationDescription fromClient = otherSession.getClientDescription();
if (Objects.equals(toClient, fromClient)) {
subscription.getSubscriptionDiagnostics().getTransferredToSameClientCount().increment();
} else {
subscription.getSubscriptionDiagnostics().getTransferredToAltClientCount().increment();
}
results.add(new TransferResult(StatusCode.GOOD, availableSequenceNumbers));
}
}
}
TransferSubscriptionsResponse response = new TransferSubscriptionsResponse(service.createResponseHeader(), a(results, TransferResult.class), new DiagnosticInfo[0]);
service.setResponse(response);
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode 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);
});
}
Aggregations