Search in sources :

Example 1 with ChangeListener

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));
}
Also used : SimpleAttributeOperand(org.eclipse.milo.opcua.stack.core.types.structured.SimpleAttributeOperand) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) ChangeListener(org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedSubscription.ChangeListener) CountDownLatch(java.util.concurrent.CountDownLatch) EventFilter(org.eclipse.milo.opcua.stack.core.types.structured.EventFilter) ContentFilter(org.eclipse.milo.opcua.stack.core.types.structured.ContentFilter) Test(org.junit.jupiter.api.Test)

Example 2 with ChangeListener

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));
}
Also used : DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) ChangeListener(org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedSubscription.ChangeListener) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)2 ChangeListener (org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedSubscription.ChangeListener)2 Test (org.junit.jupiter.api.Test)2 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)1 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)1 ContentFilter (org.eclipse.milo.opcua.stack.core.types.structured.ContentFilter)1 EventFilter (org.eclipse.milo.opcua.stack.core.types.structured.EventFilter)1 SimpleAttributeOperand (org.eclipse.milo.opcua.stack.core.types.structured.SimpleAttributeOperand)1