import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceWithInterestListeners;
import org.opendaylight.controller.md.sal.binding.compat.HydrogenNotificationBrokerImpl;
import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationPublishServiceAdapter;
+import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationServiceAdapter;
import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
private static AutoCloseable createHeliumAdapter(final NotificationPublishService publishService,
final NotificationService listenService) {
- if(publishService instanceof BindingDOMNotificationPublishServiceAdapter) {
- final BindingDOMNotificationPublishServiceAdapter casted = (BindingDOMNotificationPublishServiceAdapter) publishService;
- final DOMNotificationPublishService domService = casted.getDomPublishService();
- if(domService instanceof DOMNotificationSubscriptionListenerRegistry) {
- final DOMNotificationSubscriptionListenerRegistry subsRegistry = (DOMNotificationSubscriptionListenerRegistry) domService;
- return new HeliumNotificationProviderServiceWithInterestListeners(publishService, listenService, casted.getCodecRegistry(), subsRegistry);
+ if (listenService instanceof BindingDOMNotificationServiceAdapter
+ && publishService instanceof BindingDOMNotificationPublishServiceAdapter) {
+ final BindingDOMNotificationPublishServiceAdapter castedPublish =
+ (BindingDOMNotificationPublishServiceAdapter) publishService;
+ final BindingDOMNotificationServiceAdapter castedListen =
+ (BindingDOMNotificationServiceAdapter) listenService;
+ final DOMNotificationPublishService domPublishService = castedPublish.getDomPublishService();
+ if (domPublishService instanceof DOMNotificationSubscriptionListenerRegistry) {
+ final DOMNotificationSubscriptionListenerRegistry subsRegistry =
+ (DOMNotificationSubscriptionListenerRegistry) domPublishService;
+ return new HeliumNotificationProviderServiceWithInterestListeners(castedPublish, castedListen,
+ subsRegistry);
}
}
return new HeliumNotificationProviderServiceAdapter(publishService, listenService);
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.binding.compat;
+
+import javax.annotation.Nonnull;
+import org.opendaylight.controller.md.sal.binding.impl.LazySerializedDOMNotification;
+import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
+import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener;
+import org.opendaylight.controller.sal.binding.api.NotificationListener;
+import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer;
+import org.opendaylight.yangtools.yang.binding.Notification;
+
+final class FunctionalNotificationListenerAdapter<N extends Notification> implements DOMNotificationListener {
+
+ private final BindingNormalizedNodeSerializer codec;
+ private final NotificationListener<N> delegate;
+ private final Class<N> type;
+
+ public FunctionalNotificationListenerAdapter(final BindingNormalizedNodeSerializer codec, final Class<N> type, final NotificationListener<N> delegate) {
+ this.codec = codec;
+ this.type = type;
+ this.delegate = delegate;
+ }
+
+ @Override
+ public void onNotification(@Nonnull final DOMNotification notification) {
+ delegate.onNotification( type.cast(deserialize(notification)));
+ }
+
+ private Notification deserialize(final DOMNotification notification) {
+ if(notification instanceof LazySerializedDOMNotification) {
+ return ((LazySerializedDOMNotification) notification).getBindingData();
+ }
+ return codec.fromNormalizedNodeNotification(notification.getType(), notification.getBody());
+ }
+}
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.controller.md.sal.binding.api.NotificationService;
+import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationPublishServiceAdapter;
+import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationServiceAdapter;
import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec;
+import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListener;
import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
+import org.opendaylight.controller.sal.binding.api.NotificationListener;
+import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.util.ListenerRegistry;
import org.opendaylight.yangtools.yang.binding.Notification;
+import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final ListenerRegistry<NotificationInterestListener> interestListeners = ListenerRegistry.create();
private final ListenerRegistration<Listener> domListener;
+ private final DOMNotificationService domService;
private final BindingToNormalizedNodeCodec codec;
public HeliumNotificationProviderServiceWithInterestListeners(
- final NotificationPublishService publishService, final NotificationService listenService, final BindingToNormalizedNodeCodec codec, final DOMNotificationSubscriptionListenerRegistry registry) {
+ final BindingDOMNotificationPublishServiceAdapter publishService, final BindingDOMNotificationServiceAdapter listenService, final DOMNotificationSubscriptionListenerRegistry registry) {
super(publishService, listenService);
- this.codec = codec;
+ this.codec = publishService.getCodecRegistry();
this.domListener = registry.registerSubscriptionListener(new Listener());
+ this.domService = listenService.getDomService();
}
@Override
}
}
+ @Override
+ public <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(
+ final Class<T> type, final NotificationListener<T> listener) {
+
+ final FunctionalNotificationListenerAdapter<T> adapter = new FunctionalNotificationListenerAdapter<>(codec, type, listener);
+ final SchemaPath domType = SchemaPath.create(true, BindingReflections.findQName(type));
+ final ListenerRegistration<?> domReg = domService.registerNotificationListener(adapter, domType);
+ return new AbstractListenerRegistration<NotificationListener<T>>(listener) {
+ @Override
+ protected void removeRegistration() {
+ domReg.close();
+ }
+
+ };
+ }
+
private void notifyListener(final NotificationInterestListener listener, final Set<Class<? extends Notification>> baEvent) {
for(final Class<? extends Notification> event: baEvent) {
listener.onNotificationSubscribtion(event);
return ImmutableSet.of(DOMNotificationService.class);
}
}
+
+ public DOMNotificationService getDomService() {
+ return domNotifService;
+ }
}
* of notification actually accessed data from notification.
*
*/
-class LazySerializedDOMNotification implements DOMNotification {
+public final class LazySerializedDOMNotification implements DOMNotification {
private final BindingNormalizedNodeSerializer codec;
private final Notification data;
return domBody;
}
- protected Notification getBindingData() {
+ public Notification getBindingData() {
return data;
}
}