Bug 8568: Removed deprecated HydrogenNotificationBrokerImpl 80/58180/1
authorTom Pantelis <tompantelis@gmail.com>
Wed, 31 May 2017 18:47:23 +0000 (14:47 -0400)
committerTom Pantelis <tompantelis@gmail.com>
Fri, 2 Jun 2017 15:12:58 +0000 (11:12 -0400)
Change-Id: I707a787b3e705fb9959056e50f06b2207933bcd3
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/HydrogenNotificationBrokerImpl.java [deleted file]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/NotifyTask.java [deleted file]
opendaylight/md-sal/sal-binding-config/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/NotificationBrokerImplModule.java
opendaylight/md-sal/sal-binding-config/src/main/yang/opendaylight-binding-broker-impl.yang

diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/HydrogenNotificationBrokerImpl.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/HydrogenNotificationBrokerImpl.java
deleted file mode 100644 (file)
index 90e9484..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-/**
- * Copyright (c) 2013 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 com.google.common.base.Preconditions;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimap;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicReference;
-import javax.annotation.concurrent.GuardedBy;
-import org.opendaylight.controller.sal.binding.api.NotificationListener;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
-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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Deprecated
-public class HydrogenNotificationBrokerImpl implements NotificationProviderService, AutoCloseable {
-    private static final Logger LOG = LoggerFactory.getLogger(HydrogenNotificationBrokerImpl.class);
-
-    private final ListenerRegistry<NotificationInterestListener> interestListeners =
-            ListenerRegistry.create();
-    private final AtomicReference<ListenerMapGeneration> listeners = new AtomicReference<>(new ListenerMapGeneration());
-    private final ExecutorService executor;
-
-    public HydrogenNotificationBrokerImpl(final ExecutorService executor) {
-        this.executor = Preconditions.checkNotNull(executor);
-    }
-
-    @Override
-    public void publish(final Notification notification) {
-        publish(notification, executor);
-    }
-
-    @Override
-    public void publish(final Notification notification, final ExecutorService service) {
-        for (final NotificationListenerRegistration<?> r : listeners.get().listenersFor(notification)) {
-            service.submit(new NotifyTask(r, notification));
-        }
-    }
-
-    @GuardedBy("this")
-    private Multimap<Class<? extends Notification>, NotificationListenerRegistration<?>> mutableListeners() {
-        return HashMultimap.create(listeners.get().getListeners());
-    }
-
-    private void addRegistrations(final NotificationListenerRegistration<?>... registrations) {
-        synchronized (this) {
-            final Multimap<Class<? extends Notification>, NotificationListenerRegistration<?>> newListeners =
-                    mutableListeners();
-            for (final NotificationListenerRegistration<?> reg : registrations) {
-                newListeners.put(reg.getType(), reg);
-            }
-
-            listeners.set(new ListenerMapGeneration(newListeners));
-        }
-
-        // Notifications are dispatched out of lock...
-        for (final NotificationListenerRegistration<?> reg : registrations) {
-            announceNotificationSubscription(reg.getType());
-        }
-    }
-
-    private synchronized void removeRegistrations(final NotificationListenerRegistration<?>... registrations) {
-        final Multimap<Class<? extends Notification>, NotificationListenerRegistration<?>> newListeners =
-                mutableListeners();
-
-        for (final NotificationListenerRegistration<?> reg : registrations) {
-            newListeners.remove(reg.getType(), reg);
-        }
-
-        listeners.set(new ListenerMapGeneration(newListeners));
-    }
-
-    private void announceNotificationSubscription(final Class<? extends Notification> notification) {
-        for (final ListenerRegistration<NotificationInterestListener> listener : interestListeners) {
-            try {
-                listener.getInstance().onNotificationSubscribtion(notification);
-            } catch (final Exception e) {
-                LOG.warn("Listener {} reported unexpected error on notification {}",
-                        listener.getInstance(), notification, e);
-            }
-        }
-    }
-
-    @Override
-    public ListenerRegistration<NotificationInterestListener> registerInterestListener(final NotificationInterestListener interestListener) {
-        final ListenerRegistration<NotificationInterestListener> registration = this.interestListeners.register(interestListener);
-
-        for (final Class<? extends Notification> notification : listeners.get().getKnownTypes()) {
-            interestListener.onNotificationSubscribtion(notification);
-        }
-        return registration;
-    }
-
-    @Override
-    public <T extends Notification> NotificationListenerRegistration<T> registerNotificationListener(final Class<T> notificationType, final NotificationListener<T> listener) {
-        final NotificationListenerRegistration<T> reg = new AbstractNotificationListenerRegistration<T>(notificationType, listener) {
-            @Override
-            protected void removeRegistration() {
-                removeRegistrations(this);
-            }
-        };
-
-        addRegistrations(reg);
-        return reg;
-    }
-
-    @Override
-    public ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(final org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
-        final NotificationInvoker invoker = NotificationInvoker.invokerFor(listener);
-        final Set<Class<? extends Notification>> types = invoker.getSupportedNotifications();
-        final NotificationListenerRegistration<?>[] regs = new NotificationListenerRegistration<?>[types.size()];
-
-        // Populate the registrations...
-        int i = 0;
-        for (final Class<? extends Notification> type : types) {
-            regs[i] = new AggregatedNotificationListenerRegistration<Notification, Object>(type, invoker, regs) {
-                @Override
-                protected void removeRegistration() {
-                    // Nothing to do, will be cleaned up by parent (below)
-                }
-            };
-            ++i;
-        }
-
-        // ... now put them to use ...
-        addRegistrations(regs);
-
-        // ... finally return the parent registration
-        return new AbstractListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener>(listener) {
-            @Override
-            protected void removeRegistration() {
-                removeRegistrations(regs);
-                for (final ListenerRegistration<?> reg : regs) {
-                    reg.close();
-                }
-            }
-        };
-    }
-
-    @Override
-    public void close() {
-    }
-
-}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/NotifyTask.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/NotifyTask.java
deleted file mode 100644 (file)
index 8bb27f9..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * Copyright (c) 2013 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 com.google.common.base.MoreObjects;
-import com.google.common.base.Preconditions;
-import org.opendaylight.yangtools.yang.binding.Notification;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-class NotifyTask implements Runnable {
-    private static final Logger LOG = LoggerFactory.getLogger(NotifyTask.class);
-
-    private final NotificationListenerRegistration<?> registration;
-    private final Notification notification;
-
-    public NotifyTask(final NotificationListenerRegistration<?> registration, final Notification notification) {
-        this.registration = Preconditions.checkNotNull(registration);
-        this.notification = Preconditions.checkNotNull(notification);
-    }
-
-    @SuppressWarnings("unchecked")
-    private <T extends Notification> NotificationListenerRegistration<T> getRegistration() {
-        return (NotificationListenerRegistration<T>)registration;
-    }
-
-    @Override
-    public void run() {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Delivering notification {} to {}", notification, registration.getInstance());
-        } else {
-            LOG.trace("Delivering notification {} to {}", notification.getClass().getName(), registration.getInstance());
-        }
-
-        try {
-            getRegistration().notify(notification);
-        } catch (final Exception e) {
-            LOG.error("Unhandled exception thrown by listener: {}", registration.getInstance(), e);
-        }
-
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Notification delivered {} to {}", notification, registration.getInstance());
-        } else {
-            LOG.trace("Notification delivered {} to {}", notification.getClass().getName(), registration.getInstance());
-        }
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((registration== null) ? 0 : registration.hashCode());
-        result = prime * result + ((notification== null) ? 0 : notification.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(final Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        final NotifyTask other = (NotifyTask) obj;
-        if (registration == null) {
-            if (other.registration != null) {
-                return false;
-            }
-        } else if (!registration.equals(other.registration)) {
-            return false;
-        }
-        if (notification == null) {
-            if (other.notification != null) {
-                return false;
-            }
-        } else if (!notification.equals(other.notification)) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    public String toString() {
-        return MoreObjects.toStringHelper(this)
-                .add("listener", registration)
-                .add("notification", notification.getClass())
-                .toString();
-    }
-}
index 46cb7ce..1416cda 100644 (file)
@@ -11,12 +11,10 @@ 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.compat.HeliumNotificationProviderServiceAdapter;
 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;
 
 /**
  * @deprecated Replaced by blueprint wiring
@@ -44,21 +42,7 @@ public final class NotificationBrokerImplModule extends
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-
-        final NotificationPublishService notificationPublishService = getNotificationPublishAdapterDependency();
-        final NotificationService notificationService = getNotificationAdapterDependency();
-
-        if(notificationPublishService != null & notificationService != null) {
-            return createHeliumAdapter(notificationPublishService,notificationService);
-        }
-
-        /*
-         *  FIXME: Switch to new broker (which has different threading model)
-         *  once this change is communicated with downstream users or
-         *  we will have adapter implementation which will honor Helium
-         *  threading model for notifications.
-         */
-        return new HydrogenNotificationBrokerImpl(SingletonHolder.getDefaultNotificationExecutor());
+        return createHeliumAdapter(getNotificationPublishAdapterDependency(), getNotificationAdapterDependency());
     }
 
     private static AutoCloseable createHeliumAdapter(final NotificationPublishService publishService,
index ad6ae4c..a40acc8 100644 (file)
@@ -216,7 +216,7 @@ module opendaylight-sal-binding-broker-impl {
                 status deprecated;
                 uses config:service-ref {
                     refine type {
-                        mandatory false;
+                        mandatory true;
                         config:required-identity binding-new-notification-service;
                     }
                 }
@@ -226,7 +226,7 @@ module opendaylight-sal-binding-broker-impl {
                 status deprecated;
                 uses config:service-ref {
                     refine type {
-                        mandatory false;
+                        mandatory true;
                         config:required-identity binding-new-notification-publish-service;
                     }
                 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.