Search in sources :

Example 1 with BaseEventTypeNode

use of org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode 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 BaseEventTypeNode

use of org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode 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 BaseEventTypeNode

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

the class EqualsTest method testScalar.

@Test
public void testScalar() throws Exception {
    OperatorContext context = mock(OperatorContext.class);
    BaseEventTypeNode eventNode = mock(BaseEventTypeNode.class);
    FilterOperand op0 = new LiteralOperand(new Variant(42));
    FilterOperand op1 = new LiteralOperand(new Variant(42));
    when(context.resolve(op0, eventNode)).thenReturn(42);
    when(context.resolve(op1, eventNode)).thenReturn(42);
    Boolean result = Operators.EQUALS.apply(context, eventNode, new FilterOperand[] { op0, op1 });
    assertNotNull(result);
    assertTrue(result);
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) BaseEventTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode) LiteralOperand(org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand) OperatorContext(org.eclipse.milo.opcua.sdk.server.events.OperatorContext) FilterOperand(org.eclipse.milo.opcua.stack.core.types.structured.FilterOperand) Test(org.testng.annotations.Test)

Example 4 with BaseEventTypeNode

use of org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode 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 BaseEventTypeNode

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

the class GenerateEventMethod method invoke.

@Override
protected Variant[] invoke(InvocationContext invocationContext, Variant[] inputValues) throws UaException {
    NodeId eventTypeId = (NodeId) inputValues[0].getValue();
    BaseEventTypeNode eventNode = server.getEventFactory().createEvent(new NodeId(1, UUID.randomUUID()), eventTypeId);
    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(getNode().getNodeId());
    eventNode.setSourceName(getNode().getDisplayName().getText());
    eventNode.setTime(DateTime.now());
    eventNode.setReceiveTime(DateTime.NULL_VALUE);
    eventNode.setMessage(LocalizedText.english("event message!"));
    eventNode.setSeverity(ushort(2));
    server.getEventBus().post(eventNode);
    eventNode.delete();
    return new Variant[0];
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) BaseEventTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)

Aggregations

BaseEventTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode)16 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)11 FilterOperand (org.eclipse.milo.opcua.stack.core.types.structured.FilterOperand)9 LiteralOperand (org.eclipse.milo.opcua.stack.core.types.structured.LiteralOperand)9 OperatorContext (org.eclipse.milo.opcua.sdk.server.events.OperatorContext)8 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)8 Test (org.testng.annotations.Test)8 UaNode (org.eclipse.milo.opcua.sdk.server.nodes.UaNode)5 ServerTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode)4 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)4 UaException (org.eclipse.milo.opcua.stack.core.UaException)2 NotNull (org.jetbrains.annotations.NotNull)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1