Search in sources :

Example 1 with ServerTypeNode

use of org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode in project FAAAST-Service by FraunhoferIOSB.

the class ExampleNamespace method startBogusEventNotifier.

private void startBogusEventNotifier() {
    // Set the EventNotifier bit on Server Node for Events.
    UaNode serverNode = getServer().getAddressSpaceManager().getManagedNode(Identifiers.Server).orElse(null);
    if (serverNode instanceof ServerTypeNode) {
        ((ServerTypeNode) serverNode).setEventNotifier(ubyte(1));
        // Post a bogus Event every couple seconds
        eventThread = new Thread(() -> {
            while (keepPostingEvents) {
                try {
                    BaseEventTypeNode eventNode = getServer().getEventFactory().createEvent(newNodeId(UUID.randomUUID()), Identifiers.BaseEventType);
                    eventNode.setBrowseName(new QualifiedName(1, "foo"));
                    eventNode.setDisplayName(LocalizedText.english("foo"));
                    eventNode.setEventId(ByteString.of(new byte[] { 0, 1, 2, 3 }));
                    eventNode.setEventType(Identifiers.BaseEventType);
                    eventNode.setSourceNode(serverNode.getNodeId());
                    eventNode.setSourceName(serverNode.getDisplayName().getText());
                    eventNode.setTime(DateTime.now());
                    eventNode.setReceiveTime(DateTime.NULL_VALUE);
                    eventNode.setMessage(LocalizedText.english("event message!"));
                    eventNode.setSeverity(ushort(2));
                    // noinspection UnstableApiUsage
                    getServer().getEventBus().post(eventNode);
                    eventNode.delete();
                } catch (Throwable e) {
                    logger.error("Error creating EventNode: {}", e.getMessage(), e);
                }
                try {
                    // noinspection BusyWait
                    Thread.sleep(2_000);
                } catch (InterruptedException ignored) {
                // ignored
                }
            }
        }, "bogus-event-poster");
        eventThread.start();
    }
}
Also used : BaseEventTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode) ServerTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode)

Example 2 with ServerTypeNode

use of org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode in project milo by eclipse.

the class TestNamespace method startBogusEventNotifier.

private void startBogusEventNotifier() {
    // Set the EventNotifier bit on Server Node for Events.
    UaNode serverNode = getServer().getAddressSpaceManager().getManagedNode(Identifiers.Server).orElse(null);
    if (serverNode instanceof ServerTypeNode) {
        ((ServerTypeNode) serverNode).setEventNotifier(ubyte(1));
        // Post a bogus Event every couple seconds
        eventThread = new Thread(() -> {
            try {
                Thread.sleep(2_000);
            } catch (InterruptedException ignored) {
            // ignored
            }
            while (keepPostingEvents) {
                try {
                    BaseEventTypeNode eventNode = getServer().getEventFactory().createEvent(newNodeId(UUID.randomUUID()), Identifiers.BaseEventType);
                    eventNode.setBrowseName(new QualifiedName(1, "foo"));
                    eventNode.setDisplayName(LocalizedText.english("foo"));
                    eventNode.setEventId(ByteString.of(new byte[] { 0, 1, 2, 3 }));
                    eventNode.setEventType(Identifiers.BaseEventType);
                    eventNode.setSourceNode(serverNode.getNodeId());
                    eventNode.setSourceName(serverNode.getDisplayName().getText());
                    eventNode.setTime(DateTime.now());
                    eventNode.setReceiveTime(DateTime.NULL_VALUE);
                    eventNode.setMessage(LocalizedText.english("event message!"));
                    eventNode.setSeverity(ushort(2));
                    // noinspection UnstableApiUsage
                    getServer().getEventBus().post(eventNode);
                    eventNode.delete();
                } catch (Throwable e) {
                    logger.error("Error creating EventNode: {}", e.getMessage(), e);
                }
                try {
                    // noinspection BusyWait
                    Thread.sleep(2_000);
                } catch (InterruptedException ignored) {
                // ignored
                }
            }
        }, "bogus-event-poster");
        eventThread.start();
    }
}
Also used : BaseEventTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode) ServerTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode)

Example 3 with ServerTypeNode

use of org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode in project milo by eclipse.

the class NodeFactoryTest method testInstanceListener.

@Test
public void testInstanceListener() throws Exception {
    final AtomicBoolean methodAdded = new AtomicBoolean(false);
    final AtomicBoolean objectAdded = new AtomicBoolean(false);
    final AtomicBoolean variableAdded = new AtomicBoolean(false);
    ServerTypeNode serverNode = (ServerTypeNode) nodeFactory.createNode(new NodeId(0, "Server"), Identifiers.ServerType, new NodeFactory.InstantiationCallback() {

        @Override
        public boolean includeOptionalNode(NodeId typeDefinitionId, QualifiedName browseName) {
            return true;
        }

        @Override
        public void onMethodAdded(@Nullable UaObjectNode parent, UaMethodNode instance) {
            String pbn = parent != null ? parent.getBrowseName().getName() : null;
            System.out.println("onMethodAdded parent=" + pbn + " instance=" + instance.getBrowseName().getName());
            methodAdded.set(true);
        }

        @Override
        public void onObjectAdded(@Nullable UaNode parent, UaObjectNode instance, NodeId typeDefinitionId) {
            String pbn = parent != null ? parent.getBrowseName().getName() : null;
            System.out.println("onObjectAdded parent=" + pbn + " instance=" + instance.getBrowseName().getName());
            objectAdded.set(true);
        }

        @Override
        public void onVariableAdded(@Nullable UaNode parent, UaVariableNode instance, NodeId typeDefinitionId) {
            String pbn = parent != null ? parent.getBrowseName().getName() : null;
            System.out.println("onVariableAdded parent=" + pbn + " instance=" + instance.getBrowseName().getName());
            variableAdded.set(true);
        }
    });
    assertTrue(methodAdded.get());
    assertTrue(objectAdded.get());
    assertTrue(variableAdded.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UaObjectNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode) UaMethodNode(org.eclipse.milo.opcua.sdk.server.nodes.UaMethodNode) ServerTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) Nullable(org.jetbrains.annotations.Nullable) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 4 with ServerTypeNode

use of org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode in project tech-pdai-spring-demos by realpdai.

the class ExampleNamespace method startBogusEventNotifier.

private void startBogusEventNotifier() {
    // Set the EventNotifier bit on Server Node for Events.
    UaNode serverNode = getServer().getAddressSpaceManager().getManagedNode(Identifiers.Server).orElse(null);
    if (serverNode instanceof ServerTypeNode) {
        ((ServerTypeNode) serverNode).setEventNotifier(ubyte(1));
        // Post a bogus Event every couple seconds
        eventThread = new Thread(() -> {
            while (keepPostingEvents) {
                try {
                    BaseEventTypeNode eventNode = getServer().getEventFactory().createEvent(newNodeId(UUID.randomUUID()), Identifiers.BaseEventType);
                    eventNode.setBrowseName(new QualifiedName(1, "foo"));
                    eventNode.setDisplayName(LocalizedText.english("foo"));
                    eventNode.setEventId(ByteString.of(new byte[] { 0, 1, 2, 3 }));
                    eventNode.setEventType(Identifiers.BaseEventType);
                    eventNode.setSourceNode(serverNode.getNodeId());
                    eventNode.setSourceName(serverNode.getDisplayName().getText());
                    eventNode.setTime(DateTime.now());
                    eventNode.setReceiveTime(DateTime.NULL_VALUE);
                    eventNode.setMessage(LocalizedText.english("event message!"));
                    eventNode.setSeverity(ushort(2));
                    // noinspection UnstableApiUsage
                    getServer().getEventBus().post(eventNode);
                    eventNode.delete();
                } catch (Throwable e) {
                    logger.error("Error creating EventNode: {}", e.getMessage(), e);
                }
                try {
                    // noinspection BusyWait
                    Thread.sleep(2_000);
                } catch (InterruptedException ignored) {
                // ignored
                }
            }
        }, "bogus-event-poster");
        eventThread.start();
    }
}
Also used : BaseEventTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode) ServerTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode)

Example 5 with ServerTypeNode

use of org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode in project milo by eclipse.

the class OpcUaNamespace method configureServerObject.

private void configureServerObject() {
    ServerTypeNode serverTypeNode = (ServerTypeNode) getNodeManager().get(Identifiers.Server);
    assert serverTypeNode != null;
    // This Node is optional and we don't support it, so delete it entirely.
    serverTypeNode.getNamespacesNode().delete();
    serverTypeNode.getNamespaceArrayNode().getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(server.getNamespaceTable().toArray()))));
    serverTypeNode.getServerArrayNode().getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(server.getServerTable().toArray()))));
    serverTypeNode.setAuditing(false);
    serverTypeNode.getServerDiagnosticsNode().setEnabledFlag(false);
    serverTypeNode.setServiceLevel(ubyte(255));
    ServerStatusTypeNode serverStatus = serverTypeNode.getServerStatusNode();
    BuildInfo buildInfo = server.getConfig().getBuildInfo();
    serverStatus.setBuildInfo(buildInfo);
    serverStatus.getBuildInfoNode().setBuildDate(buildInfo.getBuildDate());
    serverStatus.getBuildInfoNode().setBuildNumber(buildInfo.getBuildNumber());
    serverStatus.getBuildInfoNode().setManufacturerName(buildInfo.getManufacturerName());
    serverStatus.getBuildInfoNode().setProductName(buildInfo.getProductName());
    serverStatus.getBuildInfoNode().setProductUri(buildInfo.getProductUri());
    serverStatus.getBuildInfoNode().setSoftwareVersion(buildInfo.getSoftwareVersion());
    serverStatus.setCurrentTime(DateTime.now());
    serverStatus.setSecondsTillShutdown(uint(0));
    serverStatus.setShutdownReason(LocalizedText.NULL_VALUE);
    serverStatus.setState(ServerState.Running);
    serverStatus.setStartTime(DateTime.now());
    serverStatus.getCurrentTimeNode().getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(DateTime.now()))));
    serverStatus.getFilterChain().addLast(AttributeFilters.getValue(ctx -> {
        ServerStatusTypeNode serverStatusNode = (ServerStatusTypeNode) ctx.getNode();
        ExtensionObject xo = ExtensionObject.encode(server.getSerializationContext(), new ServerStatusDataType(serverStatusNode.getStartTime(), DateTime.now(), serverStatusNode.getState(), serverStatusNode.getBuildInfo(), serverStatusNode.getSecondsTillShutdown(), serverStatusNode.getShutdownReason()));
        return new DataValue(new Variant(xo));
    }));
    final OpcUaServerConfigLimits limits = server.getConfig().getLimits();
    ServerCapabilitiesTypeNode serverCapabilities = serverTypeNode.getServerCapabilitiesNode();
    serverCapabilities.setServerProfileArray(new String[] { "http://opcfoundation.org/UA-Profile/Server/StandardUA" });
    serverCapabilities.setLocaleIdArray(new String[] { Locale.ENGLISH.getLanguage() });
    serverCapabilities.setMaxArrayLength(limits.getMaxArrayLength());
    serverCapabilities.setMaxStringLength(limits.getMaxStringLength());
    serverCapabilities.setMaxByteStringLength(limits.getMaxByteStringLength());
    serverCapabilities.setMaxBrowseContinuationPoints(limits.getMaxBrowseContinuationPoints());
    serverCapabilities.setMaxHistoryContinuationPoints(limits.getMaxHistoryContinuationPoints());
    serverCapabilities.setMaxQueryContinuationPoints(limits.getMaxQueryContinuationPoints());
    serverCapabilities.setMinSupportedSampleRate(limits.getMinSupportedSampleRate());
    OperationLimitsTypeNode limitsNode = serverCapabilities.getOperationLimitsNode();
    limitsNode.setMaxMonitoredItemsPerCall(limits.getMaxMonitoredItemsPerCall());
    limitsNode.setMaxNodesPerBrowse(limits.getMaxNodesPerBrowse());
    limitsNode.setMaxNodesPerHistoryReadData(limits.getMaxNodesPerHistoryReadData());
    limitsNode.setMaxNodesPerHistoryReadEvents(limits.getMaxNodesPerHistoryReadEvents());
    limitsNode.setMaxNodesPerHistoryUpdateData(limits.getMaxNodesPerHistoryUpdateData());
    limitsNode.setMaxNodesPerHistoryUpdateEvents(limits.getMaxNodesPerHistoryUpdateEvents());
    limitsNode.setMaxNodesPerMethodCall(limits.getMaxNodesPerMethodCall());
    limitsNode.setMaxNodesPerNodeManagement(limits.getMaxNodesPerNodeManagement());
    limitsNode.setMaxNodesPerRead(limits.getMaxNodesPerRead());
    limitsNode.setMaxNodesPerRegisterNodes(limits.getMaxNodesPerRegisterNodes());
    limitsNode.setMaxNodesPerTranslateBrowsePathsToNodeIds(limits.getMaxNodesPerTranslateBrowsePathsToNodeIds());
    limitsNode.setMaxNodesPerWrite(limits.getMaxNodesPerWrite());
    serverTypeNode.getServerRedundancyNode().setRedundancySupport(RedundancySupport.None);
    configureGetMonitoredItems();
    configureResendData();
}
Also used : OperationLimitsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.OperationLimitsTypeNode) DataItem(org.eclipse.milo.opcua.sdk.server.api.DataItem) LoggerFactory(org.slf4j.LoggerFactory) ServerState(org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime) GetMonitoredItemsMethod(org.eclipse.milo.opcua.sdk.server.model.methods.GetMonitoredItemsMethod) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) Locale(java.util.Locale) AbstractMethodInvocationHandler(org.eclipse.milo.opcua.sdk.server.api.methods.AbstractMethodInvocationHandler) BaseEventTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode) Out(org.eclipse.milo.opcua.sdk.server.api.methods.Out) EventItem(org.eclipse.milo.opcua.sdk.server.api.EventItem) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UUID(java.util.UUID) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) SubscriptionModel(org.eclipse.milo.opcua.sdk.server.util.SubscriptionModel) RedundancySupport(org.eclipse.milo.opcua.stack.core.types.enumerated.RedundancySupport) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) List(java.util.List) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ResendDataMethod(org.eclipse.milo.opcua.sdk.server.model.methods.ResendDataMethod) ServerTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) ServerCapabilitiesTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerCapabilitiesTypeNode) ManagedNamespaceWithLifecycle(org.eclipse.milo.opcua.sdk.server.api.ManagedNamespaceWithLifecycle) Function(java.util.function.Function) Session(org.eclipse.milo.opcua.sdk.server.Session) Lists(com.google.common.collect.Lists) ServerStatusDataType(org.eclipse.milo.opcua.stack.core.types.structured.ServerStatusDataType) AttributeFilters(org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilters) UaMethodNode(org.eclipse.milo.opcua.sdk.server.nodes.UaMethodNode) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) Logger(org.slf4j.Logger) OpcUaServerConfigLimits(org.eclipse.milo.opcua.sdk.server.api.config.OpcUaServerConfigLimits) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) Unsigned.ushort(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ushort) MonitoredDataItem(org.eclipse.milo.opcua.sdk.server.items.MonitoredDataItem) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) Subscription(org.eclipse.milo.opcua.sdk.server.subscriptions.Subscription) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) ConditionRefreshMethod(org.eclipse.milo.opcua.sdk.server.model.methods.ConditionRefreshMethod) BuildInfo(org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo) Unsigned.ubyte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ubyte) ServerStatusTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.ServerStatusTypeNode) TimeUnit(java.util.concurrent.TimeUnit) MonitoredItem(org.eclipse.milo.opcua.sdk.server.api.MonitoredItem) NonceUtil(org.eclipse.milo.opcua.stack.core.util.NonceUtil) BaseMonitoredItem(org.eclipse.milo.opcua.sdk.server.items.BaseMonitoredItem) UaException(org.eclipse.milo.opcua.stack.core.UaException) Namespaces(org.eclipse.milo.opcua.stack.core.util.Namespaces) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ServerStatusDataType(org.eclipse.milo.opcua.stack.core.types.structured.ServerStatusDataType) OperationLimitsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.OperationLimitsTypeNode) ServerTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) ServerStatusTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.ServerStatusTypeNode) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) BuildInfo(org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo) ServerCapabilitiesTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerCapabilitiesTypeNode) OpcUaServerConfigLimits(org.eclipse.milo.opcua.sdk.server.api.config.OpcUaServerConfigLimits)

Aggregations

ServerTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode)7 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)7 UaNode (org.eclipse.milo.opcua.sdk.server.nodes.UaNode)6 BaseEventTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode)5 UaMethodNode (org.eclipse.milo.opcua.sdk.server.nodes.UaMethodNode)2 UaVariableNode (org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode)2 LocalizedText (org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText)2 Lists (com.google.common.collect.Lists)1 List (java.util.List)1 Locale (java.util.Locale)1 UUID (java.util.UUID)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Function (java.util.function.Function)1 Reference (org.eclipse.milo.opcua.sdk.core.Reference)1 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)1 Session (org.eclipse.milo.opcua.sdk.server.Session)1 DataItem (org.eclipse.milo.opcua.sdk.server.api.DataItem)1 EventItem (org.eclipse.milo.opcua.sdk.server.api.EventItem)1 ManagedNamespaceWithLifecycle (org.eclipse.milo.opcua.sdk.server.api.ManagedNamespaceWithLifecycle)1