use of org.eclipse.milo.opcua.sdk.client.subscriptions.EventFilterBuilder 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);
}
Aggregations