+++ /dev/null
-/**
- * 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() {
- }
-
-}
+++ /dev/null
-/**
- * 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();
- }
-}
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
@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,