use of org.eclipse.milo.opcua.stack.core.types.structured.SessionDiagnosticsDataType in project milo by eclipse.
the class SessionDiagnosticsVariableArray method onStartup.
@Override
protected void onStartup() {
ServerDiagnosticsTypeNode diagnosticsNode = (ServerDiagnosticsTypeNode) server.getAddressSpaceManager().getManagedNode(Identifiers.Server_ServerDiagnostics).orElseThrow(() -> new NoSuchElementException("NodeId: " + Identifiers.Server_ServerDiagnostics));
diagnosticsEnabled.set(diagnosticsNode.getEnabledFlag());
if (diagnosticsEnabled.get()) {
addSessionListener();
}
attributeObserver = (node, attributeId, value) -> {
if (attributeId == AttributeId.Value) {
DataValue dataValue = (DataValue) value;
Object o = dataValue.getValue().getValue();
if (o instanceof Boolean) {
boolean current = (boolean) o;
boolean previous = diagnosticsEnabled.getAndSet(current);
if (!previous && current) {
server.getSessionManager().getAllSessions().forEach(this::createSessionDiagnosticsVariable);
if (sessionListener == null) {
addSessionListener();
}
} else if (previous && !current) {
if (sessionListener != null) {
server.getSessionManager().removeSessionListener(sessionListener);
sessionListener = null;
}
sessionDiagnosticsVariables.forEach(Lifecycle::shutdown);
sessionDiagnosticsVariables.clear();
}
}
}
};
diagnosticsNode.getEnabledFlagNode().addAttributeObserver(attributeObserver);
node.getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
ExtensionObject[] xos = ExtensionObject.encodeArray(server.getSerializationContext(), server.getSessionManager().getAllSessions().stream().map(s -> s.getSessionDiagnostics().getSessionDiagnosticsDataType()).toArray(SessionDiagnosticsDataType[]::new));
return new DataValue(new Variant(xos));
}));
}
Aggregations