Search in sources :

Example 1 with SubscriptionListener

use of org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscriptionManager.SubscriptionListener in project milo by eclipse.

the class SubscriptionWatchdogTimerTest method testSubscriptionWatchdogTimer.

@Disabled("run this test manually")
@Test
public void testSubscriptionWatchdogTimer() throws UaException, InterruptedException {
    ManagedDataItem dataItem = subscription.createDataItem(Identifiers.Server_ServerStatus_State);
    assertTrue(dataItem.getStatusCode().isGood());
    CountDownLatch latch = new CountDownLatch(2);
    subscription.addStatusListener(new ManagedSubscription.StatusListener() {

        @Override
        public void onSubscriptionWatchdogTimerElapsed(ManagedSubscription subscription) {
            System.out.println("onWatchdogTimerElapsed() id=" + subscription.getSubscription().getSubscriptionId());
            latch.countDown();
        }
    });
    client.getSubscriptionManager().addSubscriptionListener(new SubscriptionListener() {

        @Override
        public void onSubscriptionWatchdogTimerElapsed(UaSubscription subscription) {
            System.out.println("onWatchdogTimerElapsed() id=" + subscription.getSubscriptionId());
            latch.countDown();
        }
    });
    UInteger subscriptionId = subscription.getSubscription().getSubscriptionId();
    server.getSubscriptions().get(subscriptionId).deleteSubscription();
    System.out.printf("deleted subscription id=%s on server...%n", subscriptionId);
    System.out.println("waiting for watchdog timer to elapse...");
    assertTrue(latch.await(15, TimeUnit.SECONDS));
}
Also used : UaSubscription(org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) SubscriptionListener(org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscriptionManager.SubscriptionListener) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 UaSubscription (org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription)1 SubscriptionListener (org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscriptionManager.SubscriptionListener)1 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)1 Disabled (org.junit.jupiter.api.Disabled)1 Test (org.junit.jupiter.api.Test)1