Search in sources :

Example 1 with ManagedEventItem

use of org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedEventItem in project milo by eclipse.

the class ManagedSubscriptionEventExample method run.

@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
    client.connect().get();
    final CountDownLatch eventLatch = new CountDownLatch(3);
    ManagedSubscription subscription = ManagedSubscription.create(client);
    subscription.addEventChangeListener((eventItems, variants) -> {
        for (int i = 0; i < eventItems.size(); i++) {
            ManagedEventItem eventItem = eventItems.get(i);
            Variant[] eventFieldValues = variants.get(i);
            logger.info("Event Received from {}", eventItem.getNodeId());
            for (int j = 0; j < eventFieldValues.length; j++) {
                logger.info("\tvariant[{}]: {}", j, eventFieldValues[j].getValue());
            }
        }
        eventLatch.countDown();
    });
    EventFilter eventFilter = new EventFilterBuilder().select(Identifiers.BaseEventType, new QualifiedName(0, "EventId")).select(Identifiers.BaseEventType, new QualifiedName(0, "EventType")).select(Identifiers.BaseEventType, new QualifiedName(0, "Severity")).select(Identifiers.BaseEventType, new QualifiedName(0, "Time")).select(Identifiers.BaseEventType, new QualifiedName(0, "Message")).build();
    ManagedEventItem eventItem = subscription.createEventItem(Identifiers.Server, eventFilter);
    // wait for some events to arrive before completing
    eventLatch.await();
    eventItem.delete();
    future.complete(client);
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) ManagedEventItem(org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedEventItem) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedSubscription(org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedSubscription) EventFilter(org.eclipse.milo.opcua.stack.core.types.structured.EventFilter) EventFilterBuilder(org.eclipse.milo.opcua.sdk.client.subscriptions.EventFilterBuilder)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 EventFilterBuilder (org.eclipse.milo.opcua.sdk.client.subscriptions.EventFilterBuilder)1 ManagedEventItem (org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedEventItem)1 ManagedSubscription (org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedSubscription)1 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)1 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)1 EventFilter (org.eclipse.milo.opcua.stack.core.types.structured.EventFilter)1