Search in sources :

Example 1 with AttributeObserver

use of org.eclipse.milo.opcua.sdk.server.nodes.AttributeObserver in project milo by eclipse.

the class SessionDiagnosticsVariable 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());
    attributeObserver = (node, attributeId, value) -> {
        if (attributeId == AttributeId.Value) {
            DataValue dataValue = (DataValue) value;
            Object o = dataValue.getValue().getValue();
            if (o instanceof Boolean) {
                diagnosticsEnabled.set((Boolean) o);
            }
        }
    };
    diagnosticsNode.getEnabledFlagNode().addAttributeObserver(attributeObserver);
    node.getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject xo = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getSessionDiagnosticsDataType());
        return new DataValue(new Variant(xo));
    }));
    node.getSessionIdNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        NodeId value = session.getSessionDiagnostics().getSessionId();
        return new DataValue(new Variant(value));
    }));
    node.getSessionNameNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        String value = session.getSessionDiagnostics().getSessionName();
        return new DataValue(new Variant(value));
    }));
    node.getClientDescriptionNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getClientDescription());
        return new DataValue(new Variant(value));
    }));
    node.getServerUriNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        String value = session.getSessionDiagnostics().getServerUri();
        return new DataValue(new Variant(value));
    }));
    node.getEndpointUrlNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        String value = session.getSessionDiagnostics().getEndpointUrl();
        return new DataValue(new Variant(value));
    }));
    node.getLocaleIdsNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        String[] value = session.getSessionDiagnostics().getLocaleIds();
        return new DataValue(new Variant(value));
    }));
    node.getActualSessionTimeoutNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        Double value = session.getSessionDiagnostics().getActualSessionTimeout();
        return new DataValue(new Variant(value));
    }));
    node.getMaxResponseMessageSizeNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = session.getSessionDiagnostics().getMaxResponseMessageSize();
        return new DataValue(new Variant(value));
    }));
    node.getClientConnectionTimeNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        DateTime value = session.getSessionDiagnostics().getClientConnectionTime();
        return new DataValue(new Variant(value));
    }));
    node.getClientLastContactTimeNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        DateTime value = session.getSessionDiagnostics().getClientLastContactTime();
        return new DataValue(new Variant(value));
    }));
    node.getCurrentSubscriptionsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = session.getSessionDiagnostics().getCurrentSubscriptionsCount();
        return new DataValue(new Variant(value));
    }));
    node.getCurrentMonitoredItemsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = session.getSessionDiagnostics().getCurrentMonitoredItemsCount();
        return new DataValue(new Variant(value));
    }));
    node.getCurrentPublishRequestsInQueueNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = session.getSessionDiagnostics().getCurrentPublishRequestsInQueue();
        return new DataValue(new Variant(value));
    }));
    node.getTotalRequestCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getTotalRequestCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getUnauthorizedRequestCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = uint(session.getSessionDiagnostics().getUnauthorizedRequestCount().longValue());
        return new DataValue(new Variant(value));
    }));
    node.getReadCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getReadCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getHistoryReadCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getHistoryReadCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getWriteCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getWriteCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getHistoryUpdateCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getHistoryUpdateCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getCallCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getCallCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getCreateMonitoredItemsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getCreateMonitoredItemsCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getModifyMonitoredItemsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getModifyMonitoredItemsCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getSetMonitoringModeCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getSetMonitoringModeCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getSetTriggeringCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getSetTriggeringCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getDeleteMonitoredItemsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getDeleteMonitoredItemsCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getCreateSubscriptionCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getCreateSubscriptionCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getModifySubscriptionCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getModifySubscriptionCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getSetPublishingModeCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getSetPublishingModeCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getPublishCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getPublishCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getRepublishCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getRepublishCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getTransferSubscriptionsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getTransferSubscriptionsCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getDeleteSubscriptionsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getDeleteSubscriptionsCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getAddNodesCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getAddNodesCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getAddReferencesCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getAddReferencesCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getDeleteNodesCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getDeleteNodesCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getDeleteReferencesCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getDeleteReferencesCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getBrowseCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getBrowseCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getBrowseNextCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getBrowseNextCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getTranslateBrowsePathsToNodeIdsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getTranslateBrowsePathsToNodeIdsCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getQueryFirstCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getQueryFirstCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getQueryNextCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getQueryNextCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getRegisterNodesCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getRegisterNodesCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
    node.getUnregisterNodesCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject value = ExtensionObject.encode(server.getSerializationContext(), session.getSessionDiagnostics().getUnregisterNodesCount().getServiceCounter());
        return new DataValue(new Variant(value));
    }));
}
Also used : NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SessionDiagnosticsVariableTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.SessionDiagnosticsVariableTypeNode) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) Util.diagnosticValueFilter(org.eclipse.milo.opcua.sdk.server.diagnostics.variables.Util.diagnosticValueFilter) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime) AbstractLifecycle(org.eclipse.milo.opcua.sdk.server.AbstractLifecycle) Session(org.eclipse.milo.opcua.sdk.server.Session) AttributeObserver(org.eclipse.milo.opcua.sdk.server.nodes.AttributeObserver) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) ServerDiagnosticsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerDiagnosticsTypeNode) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) NoSuchElementException(java.util.NoSuchElementException) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ServerDiagnosticsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerDiagnosticsTypeNode) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with AttributeObserver

use of org.eclipse.milo.opcua.sdk.server.nodes.AttributeObserver in project milo by eclipse.

the class ServerDiagnosticsSummaryVariable 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());
    attributeObserver = (node, attributeId, value) -> {
        if (attributeId == AttributeId.Value) {
            DataValue dataValue = (DataValue) value;
            Object o = dataValue.getValue().getValue();
            if (o instanceof Boolean) {
                diagnosticsEnabled.set((Boolean) o);
            }
        }
    };
    diagnosticsNode.getEnabledFlagNode().addAttributeObserver(attributeObserver);
    node.getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        ExtensionObject xo = ExtensionObject.encode(server.getSerializationContext(), server.getDiagnosticsSummary().getServerDiagnosticsSummaryDataType());
        return new DataValue(new Variant(xo));
    }));
    node.getServerViewCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = uint(server.getDiagnosticsSummary().getCurrentViewCount().longValue());
        return new DataValue(new Variant(value));
    }));
    node.getCurrentSessionCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = uint(server.getDiagnosticsSummary().getCurrentSessionCount().longValue());
        return new DataValue(new Variant(value));
    }));
    node.getCumulatedSessionCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = uint(server.getDiagnosticsSummary().getCumulatedSessionCount().longValue());
        return new DataValue(new Variant(value));
    }));
    node.getSecurityRejectedSessionCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = uint(server.getDiagnosticsSummary().getSecurityRejectedSessionCount().longValue());
        return new DataValue(new Variant(value));
    }));
    node.getRejectedSessionCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = uint(server.getDiagnosticsSummary().getRejectedSessionCount().longValue());
        return new DataValue(new Variant(value));
    }));
    node.getSessionTimeoutCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = uint(server.getDiagnosticsSummary().getSessionTimeoutCount().longValue());
        return new DataValue(new Variant(value));
    }));
    node.getSessionAbortCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = uint(server.getDiagnosticsSummary().getSessionAbortCount().longValue());
        return new DataValue(new Variant(value));
    }));
    node.getPublishingIntervalCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = uint(server.getDiagnosticsSummary().getPublishingIntervalCount().longValue());
        return new DataValue(new Variant(value));
    }));
    node.getCurrentSubscriptionCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = uint(server.getDiagnosticsSummary().getCurrentSubscriptionCount().longValue());
        return new DataValue(new Variant(value));
    }));
    node.getCumulatedSubscriptionCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = uint(server.getDiagnosticsSummary().getCumulatedSubscriptionCount().longValue());
        return new DataValue(new Variant(value));
    }));
    node.getSecurityRejectedRequestsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = server.getDiagnosticsSummary().getSecurityRejectedRequestCount();
        return new DataValue(new Variant(value));
    }));
    node.getRejectedRequestsCountNode().getFilterChain().addLast(diagnosticValueFilter(diagnosticsEnabled, ctx -> {
        UInteger value = server.getDiagnosticsSummary().getRejectedRequestCount();
        return new DataValue(new Variant(value));
    }));
}
Also used : ServerDiagnosticsSummaryTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.ServerDiagnosticsSummaryTypeNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) Util.diagnosticValueFilter(org.eclipse.milo.opcua.sdk.server.diagnostics.variables.Util.diagnosticValueFilter) AbstractLifecycle(org.eclipse.milo.opcua.sdk.server.AbstractLifecycle) AttributeObserver(org.eclipse.milo.opcua.sdk.server.nodes.AttributeObserver) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) ServerDiagnosticsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerDiagnosticsTypeNode) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) NoSuchElementException(java.util.NoSuchElementException) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ServerDiagnosticsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerDiagnosticsTypeNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with AttributeObserver

use of org.eclipse.milo.opcua.sdk.server.nodes.AttributeObserver in project milo by eclipse.

the class SessionDiagnosticsVariableArray method onShutdown.

@Override
protected void onShutdown() {
    AttributeObserver observer = attributeObserver;
    if (observer != null) {
        ServerDiagnosticsTypeNode diagnosticsNode = (ServerDiagnosticsTypeNode) server.getAddressSpaceManager().getManagedNode(Identifiers.Server_ServerDiagnostics).orElseThrow(() -> new NoSuchElementException("NodeId: " + Identifiers.Server_ServerDiagnostics));
        diagnosticsNode.getEnabledFlagNode().removeAttributeObserver(observer);
        attributeObserver = null;
    }
    if (sessionListener != null) {
        server.getSessionManager().removeSessionListener(sessionListener);
        sessionListener = null;
    }
    sessionDiagnosticsVariables.forEach(Lifecycle::shutdown);
    sessionDiagnosticsVariables.clear();
    node.delete();
}
Also used : ServerDiagnosticsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerDiagnosticsTypeNode) AttributeObserver(org.eclipse.milo.opcua.sdk.server.nodes.AttributeObserver) AbstractLifecycle(org.eclipse.milo.opcua.sdk.server.AbstractLifecycle) Lifecycle(org.eclipse.milo.opcua.sdk.server.Lifecycle) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with AttributeObserver

use of org.eclipse.milo.opcua.sdk.server.nodes.AttributeObserver 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));
    }));
}
Also used : NodeManager(org.eclipse.milo.opcua.sdk.server.api.NodeManager) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SessionDiagnosticsVariableTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.SessionDiagnosticsVariableTypeNode) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) Util.diagnosticValueFilter(org.eclipse.milo.opcua.sdk.server.diagnostics.variables.Util.diagnosticValueFilter) Session(org.eclipse.milo.opcua.sdk.server.Session) SessionListener(org.eclipse.milo.opcua.sdk.server.SessionListener) ArrayList(java.util.ArrayList) ValueRank(org.eclipse.milo.opcua.sdk.core.ValueRank) AccessLevel(org.eclipse.milo.opcua.sdk.core.AccessLevel) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) NoSuchElementException(java.util.NoSuchElementException) Reference(org.eclipse.milo.opcua.sdk.core.Reference) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) Logger(org.slf4j.Logger) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) AbstractLifecycle(org.eclipse.milo.opcua.sdk.server.AbstractLifecycle) AttributeObserver(org.eclipse.milo.opcua.sdk.server.nodes.AttributeObserver) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) List(java.util.List) Lifecycle(org.eclipse.milo.opcua.sdk.server.Lifecycle) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ServerDiagnosticsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerDiagnosticsTypeNode) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) UaException(org.eclipse.milo.opcua.stack.core.UaException) SessionDiagnosticsDataType(org.eclipse.milo.opcua.stack.core.types.structured.SessionDiagnosticsDataType) NodeFactory(org.eclipse.milo.opcua.sdk.server.nodes.factories.NodeFactory) SessionDiagnosticsArrayTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.SessionDiagnosticsArrayTypeNode) Collections(java.util.Collections) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ServerDiagnosticsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerDiagnosticsTypeNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NoSuchElementException(java.util.NoSuchElementException)

Example 5 with AttributeObserver

use of org.eclipse.milo.opcua.sdk.server.nodes.AttributeObserver 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));
    }));
}
Also used : NodeManager(org.eclipse.milo.opcua.sdk.server.api.NodeManager) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) SessionSecurityDiagnosticsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.SessionSecurityDiagnosticsTypeNode) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) Util.diagnosticValueFilter(org.eclipse.milo.opcua.sdk.server.diagnostics.variables.Util.diagnosticValueFilter) Session(org.eclipse.milo.opcua.sdk.server.Session) SessionListener(org.eclipse.milo.opcua.sdk.server.SessionListener) ArrayList(java.util.ArrayList) ValueRank(org.eclipse.milo.opcua.sdk.core.ValueRank) AccessLevel(org.eclipse.milo.opcua.sdk.core.AccessLevel) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) SessionSecurityDiagnosticsArrayTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.SessionSecurityDiagnosticsArrayTypeNode) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) NoSuchElementException(java.util.NoSuchElementException) Reference(org.eclipse.milo.opcua.sdk.core.Reference) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) Logger(org.slf4j.Logger) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) AbstractLifecycle(org.eclipse.milo.opcua.sdk.server.AbstractLifecycle) AttributeObserver(org.eclipse.milo.opcua.sdk.server.nodes.AttributeObserver) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) List(java.util.List) Lifecycle(org.eclipse.milo.opcua.sdk.server.Lifecycle) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ServerDiagnosticsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerDiagnosticsTypeNode) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) UaException(org.eclipse.milo.opcua.stack.core.UaException) SessionSecurityDiagnosticsDataType(org.eclipse.milo.opcua.stack.core.types.structured.SessionSecurityDiagnosticsDataType) NodeFactory(org.eclipse.milo.opcua.sdk.server.nodes.factories.NodeFactory) Collections(java.util.Collections) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ServerDiagnosticsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerDiagnosticsTypeNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

NoSuchElementException (java.util.NoSuchElementException)14 ServerDiagnosticsTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerDiagnosticsTypeNode)14 AttributeObserver (org.eclipse.milo.opcua.sdk.server.nodes.AttributeObserver)14 AbstractLifecycle (org.eclipse.milo.opcua.sdk.server.AbstractLifecycle)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)7 Util.diagnosticValueFilter (org.eclipse.milo.opcua.sdk.server.diagnostics.variables.Util.diagnosticValueFilter)7 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)7 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)7 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)7 ExtensionObject (org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)7 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)7 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)6 Lifecycle (org.eclipse.milo.opcua.sdk.server.Lifecycle)4 Session (org.eclipse.milo.opcua.sdk.server.Session)4 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 List (java.util.List)3 AccessLevel (org.eclipse.milo.opcua.sdk.core.AccessLevel)3 Reference (org.eclipse.milo.opcua.sdk.core.Reference)3