Skip to content

Commit

Permalink
Add new callback methods to UaSubscription.NotificationListener
Browse files Browse the repository at this point in the history
Add `onNotificationDataLost` and `onSubscriptionTransferFailed` callbacks to
UaSubscription.NotificationListener. This allows registering a listener at the
subscription level for callbacks that previously required registration with
OpcUaSubscriptionManager and would be invoked for all subscriptions.
  • Loading branch information
kevinherron committed Jun 22, 2021
1 parent b2c089e commit 12abe41
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 the Eclipse Milo Authors
* Copyright (c) 2021 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,6 +15,7 @@
import java.util.stream.Collectors;

import com.google.common.collect.ImmutableList;
import org.eclipse.milo.opcua.sdk.client.api.UaSession;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
import org.eclipse.milo.opcua.stack.core.types.builtin.DateTime;
import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;
Expand Down Expand Up @@ -297,6 +298,27 @@ default void onKeepAliveNotification(UaSubscription subscription, DateTime publi
*/
default void onStatusChangedNotification(UaSubscription subscription, StatusCode status) {}

/**
* Attempts to recover missed notification data have failed.
* <p>
* When a notification is missed a series of Republish requests are initiated to recover the missing data. If
* republishing fails, or any of the notifications are no longer available, this callback will be invoked.
*
* @param subscription the subscription that missed notification data.
*/
default void onNotificationDataLost(UaSubscription subscription) {}

/**
* A new {@link UaSession} was established, and upon attempting to transfer an existing subscription to this
* new session, a failure occurred.
* <p>
* This subscription will be removed from {@link UaSubscriptionManager}'s bookkeeping. It must be re-created.
*
* @param subscription the {@link UaSubscription} that could not be transferred.
* @param statusCode the {@link StatusCode} for the transfer failure.
*/
default void onSubscriptionTransferFailed(UaSubscription subscription, StatusCode statusCode) {}

}

}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 the Eclipse Milo Authors
* Copyright (c) 2021 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -363,6 +363,11 @@ public void transferFailed(UInteger subscriptionId, StatusCode statusCode) {

if (subscription != null) {
subscriptionListeners.forEach(l -> l.onSubscriptionTransferFailed(subscription, statusCode));

subscription.getNotificationListeners().forEach(
l ->
l.onSubscriptionTransferFailed(subscription, statusCode)
);
}
}

Expand Down Expand Up @@ -528,10 +533,12 @@ private void onPublishComplete(PublishResponse response, AtomicLong pendingCount
logger.debug("Republish failed: {}", ex.getMessage(), ex);

subscriptionListeners.forEach(l -> l.onNotificationDataLost(subscription));
subscription.getNotificationListeners().forEach(l -> l.onNotificationDataLost(subscription));
} else {
// Republish succeeded, possibly with some data loss, resume processing.
if (dataLost) {
subscriptionListeners.forEach(l -> l.onNotificationDataLost(subscription));
subscription.getNotificationListeners().forEach(l -> l.onNotificationDataLost(subscription));
}
}

Expand Down

0 comments on commit 12abe41

Please sign in to comment.