use of org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedSubscription.ChangeListener in project milo by eclipse.
the class ManagedSubscriptionTest method eventChangeListener.
@Test
public void eventChangeListener() throws UaException, InterruptedException {
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
subscription.addChangeListener(new ChangeListener() {
@Override
public void onEventReceived(List<ManagedEventItem> eventItems, List<Variant[]> eventFields) {
if (eventItems.get(0).getNodeId().equals(Identifiers.Server)) {
latch1.countDown();
}
}
});
subscription.addEventChangeListener((eventItems, eventFields) -> {
if (eventItems.get(0).getNodeId().equals(Identifiers.Server)) {
latch2.countDown();
}
});
EventFilter eventFilter = new EventFilter(new SimpleAttributeOperand[] { new SimpleAttributeOperand(Identifiers.BaseEventType, new QualifiedName[] { new QualifiedName(0, "EventId") }, AttributeId.Value.uid(), null), new SimpleAttributeOperand(Identifiers.BaseEventType, new QualifiedName[] { new QualifiedName(0, "Time") }, AttributeId.Value.uid(), null), new SimpleAttributeOperand(Identifiers.BaseEventType, new QualifiedName[] { new QualifiedName(0, "Message") }, AttributeId.Value.uid(), null) }, new ContentFilter(null));
ManagedEventItem eventItem = subscription.createEventItem(Identifiers.Server, eventFilter);
assertTrue(eventItem.getStatusCode().isGood());
assertTrue(latch1.await(5, TimeUnit.SECONDS));
assertTrue(latch2.await(5, TimeUnit.SECONDS));
}
use of org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedSubscription.ChangeListener in project milo by eclipse.
the class ManagedSubscriptionTest method dataChangeListener.
@Test
public void dataChangeListener() throws UaException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(2);
subscription.addChangeListener(new ChangeListener() {
@Override
public void onDataReceived(List<ManagedDataItem> dataItems, List<DataValue> dataValues) {
if (dataItems.get(0).getNodeId().equals(Identifiers.Server_ServerStatus_State)) {
latch.countDown();
}
}
});
subscription.addDataChangeListener((dataItems, dataValues) -> {
if (dataItems.get(0).getNodeId().equals(Identifiers.Server_ServerStatus_State)) {
latch.countDown();
}
});
ManagedDataItem dataItem = subscription.createDataItem(Identifiers.Server_ServerStatus_State);
assertTrue(dataItem.getStatusCode().isGood());
assertTrue(latch.await(5, TimeUnit.SECONDS));
}
Aggregations