X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Fimpl%2FNotificationBrokerImpl.xtend;h=6d675b4b5eb5f546b1a7fd7743d301fb62a56f0b;hp=b4fd6b67712d6054b2f74737d89f3ea091aa9345;hb=82eb3f94c133e091ca5dd2f26450da9f121c12ca;hpb=edb3b76df1fa27594d5f9ee368d737576b0b38f8 diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend index b4fd6b6771..6d675b4b5e 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend @@ -8,80 +8,51 @@ package org.opendaylight.controller.sal.binding.impl import com.google.common.collect.HashMultimap +import com.google.common.collect.ImmutableSet import com.google.common.collect.Multimap -import java.util.Collection +import com.google.common.collect.Multimaps import java.util.Collections import java.util.concurrent.Callable import java.util.concurrent.ExecutorService +import java.util.concurrent.Future +import java.util.Set import org.opendaylight.controller.sal.binding.api.NotificationListener import org.opendaylight.controller.sal.binding.api.NotificationProviderService +import org.opendaylight.controller.sal.binding.api.NotificationProviderService.NotificationInterestListener +import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory.NotificationInvoker import org.opendaylight.yangtools.concepts.AbstractObjectRegistration import org.opendaylight.yangtools.concepts.ListenerRegistration import org.opendaylight.yangtools.concepts.Registration +import org.opendaylight.yangtools.concepts.util.ListenerRegistry import org.opendaylight.yangtools.yang.binding.Notification import org.slf4j.LoggerFactory -import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder class NotificationBrokerImpl implements NotificationProviderService, AutoCloseable { - + + val ListenerRegistry interestListeners = ListenerRegistry.create; + val Multimap, NotificationListener> listeners; @Property var ExecutorService executor; + + val logger = LoggerFactory.getLogger(NotificationBrokerImpl) new() { - listeners = HashMultimap.create() + listeners = Multimaps.synchronizedSetMultimap(HashMultimap.create()) } @Deprecated new(ExecutorService executor) { - listeners = HashMultimap.create() + listeners = Multimaps.synchronizedSetMultimap(HashMultimap.create()) this.executor = executor; } - @Deprecated - override addNotificationListener(Class notificationType, - NotificationListener listener) { - listeners.put(notificationType, listener) - } - - @Deprecated - override removeNotificationListener(Class notificationType, - NotificationListener listener) { - listeners.remove(notificationType, listener) - } - - override notify(Notification notification) { - publish(notification) - } - def getNotificationTypes(Notification notification) { notification.class.interfaces.filter[it != Notification && Notification.isAssignableFrom(it)] } - @SuppressWarnings("unchecked") - private def notifyAll(Collection> listeners, Notification notification) { - listeners.forEach[(it as NotificationListener).onNotification(notification)] - } - - @Deprecated - override addNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) { - throw new UnsupportedOperationException("Deprecated method. Use registerNotificationListener instead."); - - } - - @Deprecated - override removeNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) { - throw new UnsupportedOperationException( - "Deprecated method. Use RegisterNotificationListener returned value to close registration.") - } - - @Deprecated - override notify(Notification notification, ExecutorService service) { - publish(notification, service) - } - override publish(Notification notification) { publish(notification, executor) } @@ -89,26 +60,46 @@ class NotificationBrokerImpl implements NotificationProviderService, AutoCloseab override publish(Notification notification, ExecutorService service) { val allTypes = notification.notificationTypes - var Iterable> listenerToNotify = Collections.emptySet(); + var Iterable> listenerToNotify = Collections.emptySet(); for (type : allTypes) { listenerToNotify = listenerToNotify + listeners.get(type as Class) } val tasks = listenerToNotify.map[new NotifyTask(it, notification)].toSet; - executor.invokeAll(tasks); + submitAll(executor,tasks); } - + + def submitAll(ExecutorService service, Set tasks) { + val ret = ImmutableSet.>builder(); + for(task : tasks) { + ret.add(service.submit(task)); + } + return ret.build(); + } + override registerNotificationListener(Class notificationType, NotificationListener listener) { val reg = new GenericNotificationRegistration(notificationType, listener, this); listeners.put(notificationType, listener); + announceNotificationSubscription(notificationType); return reg; } + + def announceNotificationSubscription(Class notification) { + for (listener : interestListeners) { + try { + listener.instance.onNotificationSubscribtion(notification); + } catch (Exception e) { + logger.error("", e.message) + } + } + } override registerNotificationListener( org.opendaylight.yangtools.yang.binding.NotificationListener listener) { val invoker = SingletonHolder.INVOKER_FACTORY.invokerFor(listener); for (notifyType : invoker.supportedNotifications) { listeners.put(notifyType, invoker.invocationProxy) + announceNotificationSubscription(notifyType) } val registration = new GeneratedListenerRegistration(listener, invoker,this); return registration as Registration; @@ -128,6 +119,14 @@ class NotificationBrokerImpl implements NotificationProviderService, AutoCloseab //FIXME: implement properly. } + override registerInterestListener(NotificationInterestListener interestListener) { + val registration = interestListeners.register(interestListener); + + for(notification : listeners.keySet) { + interestListener.onNotificationSubscribtion(notification); + } + return registration + } } class GenericNotificationRegistration extends AbstractObjectRegistration> implements ListenerRegistration> { @@ -185,13 +184,13 @@ class NotifyTask implements Callable { if(log.isDebugEnabled){ log.debug("Delivering notification {} to {}",notification,listener); } else { - log.info("Delivering notification {} to {}",notification.class.name,listener); + log.trace("Delivering notification {} to {}",notification.class.name,listener); } listener.onNotification(notification); if(log.isDebugEnabled){ log.debug("Notification delivered {} to {}",notification,listener); } else { - log.info("Notification delivered {} to {}",notification.class.name,listener); + log.trace("Notification delivered {} to {}",notification.class.name,listener); } } catch (Exception e) { log.error("Unhandled exception thrown by listener: {}", listener, e);