From: Tom Pantelis Date: Wed, 31 May 2017 18:47:23 +0000 (-0400) Subject: Bug 8568: Removed deprecated HydrogenNotificationBrokerImpl X-Git-Tag: release/nitrogen~162 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=972be549f4dcae32ce8df9c734d1e3e539514e84 Bug 8568: Removed deprecated HydrogenNotificationBrokerImpl Change-Id: I707a787b3e705fb9959056e50f06b2207933bcd3 Signed-off-by: Tom Pantelis --- 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 index 90e9484f05..0000000000 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/HydrogenNotificationBrokerImpl.java +++ /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 interestListeners = - ListenerRegistry.create(); - private final AtomicReference 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, NotificationListenerRegistration> mutableListeners() { - return HashMultimap.create(listeners.get().getListeners()); - } - - private void addRegistrations(final NotificationListenerRegistration... registrations) { - synchronized (this) { - final Multimap, 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, NotificationListenerRegistration> newListeners = - mutableListeners(); - - for (final NotificationListenerRegistration reg : registrations) { - newListeners.remove(reg.getType(), reg); - } - - listeners.set(new ListenerMapGeneration(newListeners)); - } - - private void announceNotificationSubscription(final Class notification) { - for (final ListenerRegistration 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 registerInterestListener(final NotificationInterestListener interestListener) { - final ListenerRegistration registration = this.interestListeners.register(interestListener); - - for (final Class notification : listeners.get().getKnownTypes()) { - interestListener.onNotificationSubscribtion(notification); - } - return registration; - } - - @Override - public NotificationListenerRegistration registerNotificationListener(final Class notificationType, final NotificationListener listener) { - final NotificationListenerRegistration reg = new AbstractNotificationListenerRegistration(notificationType, listener) { - @Override - protected void removeRegistration() { - removeRegistrations(this); - } - }; - - addRegistrations(reg); - return reg; - } - - @Override - public ListenerRegistration registerNotificationListener(final org.opendaylight.yangtools.yang.binding.NotificationListener listener) { - final NotificationInvoker invoker = NotificationInvoker.invokerFor(listener); - final Set> types = invoker.getSupportedNotifications(); - final NotificationListenerRegistration[] regs = new NotificationListenerRegistration[types.size()]; - - // Populate the registrations... - int i = 0; - for (final Class type : types) { - regs[i] = new AggregatedNotificationListenerRegistration(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(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 index 8bb27f9c8d..0000000000 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/NotifyTask.java +++ /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 NotificationListenerRegistration getRegistration() { - return (NotificationListenerRegistration)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(); - } -} diff --git a/opendaylight/md-sal/sal-binding-config/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/NotificationBrokerImplModule.java b/opendaylight/md-sal/sal-binding-config/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/NotificationBrokerImplModule.java index 46cb7ceee0..1416cda5d8 100644 --- a/opendaylight/md-sal/sal-binding-config/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/NotificationBrokerImplModule.java +++ b/opendaylight/md-sal/sal-binding-config/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/NotificationBrokerImplModule.java @@ -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, diff --git a/opendaylight/md-sal/sal-binding-config/src/main/yang/opendaylight-binding-broker-impl.yang b/opendaylight/md-sal/sal-binding-config/src/main/yang/opendaylight-binding-broker-impl.yang index ad6ae4c2d3..a40acc87a0 100644 --- a/opendaylight/md-sal/sal-binding-config/src/main/yang/opendaylight-binding-broker-impl.yang +++ b/opendaylight/md-sal/sal-binding-config/src/main/yang/opendaylight-binding-broker-impl.yang @@ -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; } }