From: Robert Varga Date: Sun, 1 Jun 2014 06:01:21 +0000 (+0200) Subject: BUG-614: Hide the executor and improve logging X-Git-Tag: release/helium~733 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=c59d59a9ef1fc10e09a85044bb1bd208ff3219f2 BUG-614: Hide the executor and improve logging As part of the xtend->Java rewrite, we get rid of unnecessary getExecutor() and improve logging a bit. Change-Id: I9c7052472289f701a289f4ba76312fb28af18a3f Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.java index 6de878f851..9efd48eabd 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.java @@ -14,8 +14,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import org.eclipse.xtext.xbase.lib.Conversions; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.Functions.Function0; import org.eclipse.xtext.xbase.lib.Functions.Function1; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.opendaylight.controller.sal.binding.api.NotificationListener; @@ -30,6 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.base.Objects; +import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; @@ -39,33 +38,13 @@ import com.google.common.collect.Multimaps; import com.google.common.collect.SetMultimap; public class NotificationBrokerImpl implements NotificationProviderService, AutoCloseable { - private final ListenerRegistry interestListeners = new Function0>() { - @Override - public ListenerRegistry apply() { - ListenerRegistry _create = ListenerRegistry.create(); - return _create; - } - }.apply(); - - private final Multimap,NotificationListener> listeners; - - private ExecutorService _executor; + private static final Logger LOG = LoggerFactory.getLogger(NotificationBrokerImpl.class); - public ExecutorService getExecutor() { - return this._executor; - } - - public void setExecutor(final ExecutorService executor) { - this._executor = executor; - } + private final ListenerRegistry interestListeners = + ListenerRegistry.create(); - private final Logger logger = new Function0() { - @Override - public Logger apply() { - Logger _logger = LoggerFactory.getLogger(NotificationBrokerImpl.class); - return _logger; - } - }.apply(); + private final Multimap,NotificationListener> listeners; + private ExecutorService executor; public NotificationBrokerImpl() { HashMultimap,NotificationListener> _create = HashMultimap., NotificationListener>create(); @@ -81,6 +60,10 @@ public class NotificationBrokerImpl implements NotificationProviderService, Auto this.setExecutor(executor); } + public void setExecutor(final ExecutorService executor) { + this.executor = Preconditions.checkNotNull(executor); + } + public Iterable> getNotificationTypes(final Notification notification) { Class _class = notification.getClass(); Class[] _interfaces = _class.getInterfaces(); @@ -104,8 +87,7 @@ public class NotificationBrokerImpl implements NotificationProviderService, Auto @Override public void publish(final Notification notification) { - ExecutorService _executor = this.getExecutor(); - this.publish(notification, _executor); + this.publish(notification, executor); } @Override @@ -126,8 +108,7 @@ public class NotificationBrokerImpl implements NotificationProviderService, Auto }; Iterable _map = IterableExtensions., NotifyTask>map(listenerToNotify, _function); final Set tasks = IterableExtensions.toSet(_map); - ExecutorService _executor = this.getExecutor(); - this.submitAll(_executor, tasks); + this.submitAll(executor, tasks); } public ImmutableSet> submitAll(final ExecutorService service, final Set tasks) { @@ -148,19 +129,13 @@ public class NotificationBrokerImpl implements NotificationProviderService, Auto return reg; } - public void announceNotificationSubscription(final Class notification) { - for (final ListenerRegistration listener : this.interestListeners) { + private void announceNotificationSubscription(final Class notification) { + for (final ListenerRegistration listener : interestListeners) { try { - NotificationInterestListener _instance = listener.getInstance(); - _instance.onNotificationSubscribtion(notification); - } catch (final Throwable _t) { - if (_t instanceof Exception) { - final Exception e = (Exception)_t; - String _message = e.getMessage(); - this.logger.error("", _message); - } else { - throw Exceptions.sneakyThrow(_t); - } + listener.getInstance().onNotificationSubscribtion(notification); + } catch (Exception e) { + LOG.warn("Listener {} reported unexpected error on notification {}", + listener.getInstance(), notification, e); } } }