Search in sources :

Example 1 with NotificationListenerRegistration

use of org.opendaylight.netconf.notifications.NotificationListenerRegistration in project netconf by opendaylight.

the class CreateSubscription method handleWithNoSubsequentOperations.

@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException {
    operationElement.checkName(CREATE_SUBSCRIPTION);
    operationElement.checkNamespace(CreateSubscriptionInput.QNAME.getNamespace().toString());
    // FIXME reimplement using CODEC_REGISTRY and parse everything into generated class instance
    // Binding doesn't support anyxml nodes yet, so filter could not be retrieved
    // xml -> normalized node -> CreateSubscriptionInput conversion could be slower than current approach
    final Optional<XmlElement> filter = operationElement.getOnlyChildElementWithSameNamespaceOptionally("filter");
    // Replay not supported
    final Optional<XmlElement> startTime = operationElement.getOnlyChildElementWithSameNamespaceOptionally("startTime");
    checkArgument(startTime.isEmpty(), "StartTime element not yet supported");
    // Stop time not supported
    final Optional<XmlElement> stopTime = operationElement.getOnlyChildElementWithSameNamespaceOptionally("stopTime");
    checkArgument(stopTime.isEmpty(), "StopTime element not yet supported");
    final StreamNameType streamNameType = parseStreamIfPresent(operationElement);
    requireNonNull(netconfSession);
    // Premature streams are allowed (meaning listener can register even if no provider is available yet)
    if (!notifications.isStreamAvailable(streamNameType)) {
        LOG.warn("Registering premature stream {}. No publisher available yet for session {}", streamNameType, getNetconfSessionIdForReporting());
    }
    final NotificationListenerRegistration notificationListenerRegistration = notifications.registerNotificationListener(streamNameType, new NotificationSubscription(netconfSession, filter));
    subscriptions.add(notificationListenerRegistration);
    return document.createElement(XmlNetconfConstants.OK);
}
Also used : StreamNameType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) NotificationListenerRegistration(org.opendaylight.netconf.notifications.NotificationListenerRegistration)

Example 2 with NotificationListenerRegistration

use of org.opendaylight.netconf.notifications.NotificationListenerRegistration in project netconf by opendaylight.

the class NetconfNotificationManagerTest method testNotificationListeners.

@Test
public void testNotificationListeners() throws Exception {
    final NetconfNotificationManager netconfNotificationManager = createManager();
    final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration = netconfNotificationManager.registerBaseNotificationPublisher();
    final NetconfCapabilityChangeBuilder capabilityChangedBuilder = new NetconfCapabilityChangeBuilder();
    final NetconfNotificationListener listener = mock(NetconfNotificationListener.class);
    doNothing().when(listener).onNotification(any(StreamNameType.class), any(NetconfNotification.class));
    final NotificationListenerRegistration notificationListenerRegistration = netconfNotificationManager.registerNotificationListener(NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listener);
    final NetconfCapabilityChange notification = capabilityChangedBuilder.build();
    baseNotificationPublisherRegistration.onCapabilityChanged(notification);
    verify(listener).onNotification(any(StreamNameType.class), any(NetconfNotification.class));
    notificationListenerRegistration.close();
    baseNotificationPublisherRegistration.onCapabilityChanged(notification);
    verifyNoMoreInteractions(listener);
}
Also used : StreamNameType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType) BaseNotificationPublisherRegistration(org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration) NetconfCapabilityChangeBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder) NetconfNotificationListener(org.opendaylight.netconf.notifications.NetconfNotificationListener) NotificationListenerRegistration(org.opendaylight.netconf.notifications.NotificationListenerRegistration) NetconfCapabilityChange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange) NetconfNotification(org.opendaylight.netconf.notifications.NetconfNotification) Test(org.junit.Test)

Aggregations

NotificationListenerRegistration (org.opendaylight.netconf.notifications.NotificationListenerRegistration)2 StreamNameType (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType)2 Test (org.junit.Test)1 XmlElement (org.opendaylight.netconf.api.xml.XmlElement)1 BaseNotificationPublisherRegistration (org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration)1 NetconfNotification (org.opendaylight.netconf.notifications.NetconfNotification)1 NetconfNotificationListener (org.opendaylight.netconf.notifications.NetconfNotificationListener)1 NetconfCapabilityChange (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange)1 NetconfCapabilityChangeBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder)1