From 77d1dee3dfeb8725d5e738ed3f997a84b1051db2 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Tue, 7 Apr 2015 13:41:29 +0200 Subject: [PATCH] Extracted NotificationInvokerImpl to separate class. Change-Id: Ie7494e872200581ce6cf5dcae2088ab2afda3671 Signed-off-by: Tony Tkacik --- ...BindingDOMNotificationListenerAdapter.java | 33 ++++++++++++++++ .../BindingDOMNotificationServiceAdapter.java | 38 +++++-------------- 2 files changed, 43 insertions(+), 28 deletions(-) create mode 100644 opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java new file mode 100644 index 0000000000..03da29642c --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java @@ -0,0 +1,33 @@ +/* + * 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.impl; + +import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.dom.api.DOMNotification; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener; +import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory; +import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer; +import org.opendaylight.yangtools.yang.binding.Notification; + +class BindingDOMNotificationListenerAdapter implements DOMNotificationListener { + + private final NotificationInvokerFactory.NotificationInvoker invoker; + private final BindingNormalizedNodeSerializer codec; + + public BindingDOMNotificationListenerAdapter(final BindingNormalizedNodeSerializer codec, final NotificationInvokerFactory.NotificationInvoker invoker) { + this.codec = codec; + this.invoker = invoker; + } + + @Override + public void onNotification(@Nonnull final DOMNotification notification) { + final Notification baNotification = + codec.fromNormalizedNodeNotification(notification.getType(), notification.getBody()); + invoker.getInvocationProxy().onNotification(baNotification); + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationServiceAdapter.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationServiceAdapter.java index 50a0a2815f..6006266cc2 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationServiceAdapter.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationServiceAdapter.java @@ -13,10 +13,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; -import javax.annotation.Nonnull; import org.opendaylight.controller.md.sal.binding.api.NotificationService; import org.opendaylight.controller.md.sal.binding.impl.BindingDOMAdapterBuilder.Factory; -import org.opendaylight.controller.md.sal.dom.api.DOMNotification; import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener; import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService; import org.opendaylight.controller.md.sal.dom.api.DOMService; @@ -44,16 +42,16 @@ public class BindingDOMNotificationServiceAdapter implements NotificationService private final DOMNotificationService domNotifService; private final NotificationInvokerFactory notificationInvokerFactory; - public BindingDOMNotificationServiceAdapter(BindingNormalizedNodeSerializer codec, DOMNotificationService domNotifService, NotificationInvokerFactory notificationInvokerFactory) { + public BindingDOMNotificationServiceAdapter(final BindingNormalizedNodeSerializer codec, final DOMNotificationService domNotifService, final NotificationInvokerFactory notificationInvokerFactory) { this.codec = codec; this.domNotifService = domNotifService; this.notificationInvokerFactory = notificationInvokerFactory; } @Override - public ListenerRegistration registerNotificationListener(T listener) { + public ListenerRegistration registerNotificationListener(final T listener) { final NotificationInvokerFactory.NotificationInvoker invoker = notificationInvokerFactory.invokerFor(listener); - final DOMNotificationListener domListener = new NotificationInvokerImpl(invoker); + final DOMNotificationListener domListener = new BindingDOMNotificationListenerAdapter(codec, invoker); final Collection schemaPaths = convertNotifTypesToSchemaPath(invoker.getSupportedNotifications()); final ListenerRegistration domRegistration = domNotifService.registerNotificationListener(domListener, schemaPaths); @@ -62,9 +60,9 @@ public class BindingDOMNotificationServiceAdapter implements NotificationService - private Collection convertNotifTypesToSchemaPath(Set> notificationTypes) { + private Collection convertNotifTypesToSchemaPath(final Set> notificationTypes) { final List schemaPaths = new ArrayList<>(); - for (Class notificationType : notificationTypes) { + for (final Class notificationType : notificationTypes) { schemaPaths.add(SchemaPath.create(true, BindingReflections.findQName(notificationType))); } return schemaPaths; @@ -78,7 +76,7 @@ public class BindingDOMNotificationServiceAdapter implements NotificationService private static class ListenerRegistrationImpl extends AbstractListenerRegistration { private final ListenerRegistration listenerRegistration; - public ListenerRegistrationImpl(T listener, ListenerRegistration listenerRegistration) { + public ListenerRegistrationImpl(final T listener, final ListenerRegistration listenerRegistration) { super(listener); this.listenerRegistration = listenerRegistration; } @@ -89,30 +87,14 @@ public class BindingDOMNotificationServiceAdapter implements NotificationService } } - private class NotificationInvokerImpl implements DOMNotificationListener { - private final NotificationInvokerFactory.NotificationInvoker invoker; - - public NotificationInvokerImpl(NotificationInvokerFactory.NotificationInvoker invoker) { - this.invoker = invoker; - } - - @Override - public void onNotification(@Nonnull DOMNotification notification) { - final Notification baNotification = - codec.fromNormalizedNodeNotification(notification.getType(), notification.getBody()); - invoker.getInvocationProxy().onNotification(baNotification); - - } - } - private static class Builder extends BindingDOMAdapterBuilder { @Override - protected NotificationService createInstance(BindingToNormalizedNodeCodec codec, - ClassToInstanceMap delegates) { - DOMNotificationService domNotification = delegates.getInstance(DOMNotificationService.class); - NotificationInvokerFactory invokerFactory = SingletonHolder.INVOKER_FACTORY; + protected NotificationService createInstance(final BindingToNormalizedNodeCodec codec, + final ClassToInstanceMap delegates) { + final DOMNotificationService domNotification = delegates.getInstance(DOMNotificationService.class); + final NotificationInvokerFactory invokerFactory = SingletonHolder.INVOKER_FACTORY; return new BindingDOMNotificationServiceAdapter(codec.getCodecRegistry(), domNotification, invokerFactory); } -- 2.36.6