use of org.eclipse.milo.opcua.stack.core.types.structured.SessionSecurityDiagnosticsDataType in project milo by eclipse.
the class SessionSecurityDiagnosticsVariableArray 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::createSessionSecurityDiagnosticsVariable);
if (sessionListener == null) {
addSessionListener();
}
} else if (previous && !current) {
if (sessionListener != null) {
server.getSessionManager().removeSessionListener(sessionListener);
sessionListener = null;
}
sessionSecurityDiagnosticsVariables.forEach(Lifecycle::shutdown);
sessionSecurityDiagnosticsVariables.clear();
}
}
}
};
diagnosticsNode.getEnabledFlagNode().addAttributeObserver(attributeObserver);
node.getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
ExtensionObject[] xos = ExtensionObject.encodeArray(server.getSerializationContext(), server.getSessionManager().getAllSessions().stream().map(s -> s.getSessionSecurityDiagnostics().getSessionSecurityDiagnosticsDataType()).toArray(SessionSecurityDiagnosticsDataType[]::new));
return new DataValue(new Variant(xos));
}));
}
Aggregations