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%2FNotifyTask.java;h=5f0de6bc16c8a18ba1fc925b3a84693c85d06536;hp=9471616f01123604757e5ae32916cf8408fca994;hb=2685d08af5ff639854358e3e5aea393460a6a615;hpb=357ebddddbb29d3ed35685516dc184e0603e2def diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotifyTask.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotifyTask.java index 9471616f01..5f0de6bc16 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotifyTask.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotifyTask.java @@ -7,92 +7,57 @@ */ package org.opendaylight.controller.sal.binding.impl; -import java.util.concurrent.Callable; - -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.Functions.Function0; -import org.eclipse.xtext.xbase.lib.util.ToStringHelper; import org.opendaylight.controller.sal.binding.api.NotificationListener; import org.opendaylight.yangtools.yang.binding.Notification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class NotifyTask implements Callable { - private static Logger log = new Function0() { - @Override - public Logger apply() { - Logger _logger = LoggerFactory.getLogger(NotifyTask.class); - return _logger; - } - }.apply(); +import com.google.common.base.Objects; +import com.google.common.base.Preconditions; - @SuppressWarnings("rawtypes") - private final NotificationListener _listener; +class NotifyTask implements Runnable { + private static final Logger LOG = LoggerFactory.getLogger(NotifyTask.class); - public NotificationListener getListener() { - return this._listener; - } + private final NotificationListener listener; + private final Notification notification; - private final Notification _notification; + public NotifyTask(final NotificationListener listener, final Notification notification) { + this.listener = Preconditions.checkNotNull(listener); + this.notification = Preconditions.checkNotNull(notification); + } - public Notification getNotification() { - return this._notification; + @SuppressWarnings("unchecked") + private NotificationListener getListener() { + return (NotificationListener)listener; } @Override - public Object call() { + public void run() { + if (LOG.isDebugEnabled()) { + LOG.debug("Delivering notification {} to {}", notification, listener); + } else { + LOG.trace("Delivering notification {} to {}", notification.getClass().getName(), listener); + } + try { - boolean _isDebugEnabled = NotifyTask.log.isDebugEnabled(); - if (_isDebugEnabled) { - Notification _notification = this.getNotification(); - NotificationListener _listener = this.getListener(); - NotifyTask.log.debug("Delivering notification {} to {}", _notification, _listener); - } else { - Notification _notification_1 = this.getNotification(); - Class _class = _notification_1.getClass(); - String _name = _class.getName(); - NotificationListener _listener_1 = this.getListener(); - NotifyTask.log.trace("Delivering notification {} to {}", _name, _listener_1); - } - NotificationListener _listener_2 = this.getListener(); - Notification _notification_2 = this.getNotification(); - _listener_2.onNotification(_notification_2); - boolean _isDebugEnabled_1 = NotifyTask.log.isDebugEnabled(); - if (_isDebugEnabled_1) { - Notification _notification_3 = this.getNotification(); - NotificationListener _listener_3 = this.getListener(); - NotifyTask.log.debug("Notification delivered {} to {}", _notification_3, _listener_3); - } else { - Notification _notification_4 = this.getNotification(); - Class _class_1 = _notification_4.getClass(); - String _name_1 = _class_1.getName(); - NotificationListener _listener_4 = this.getListener(); - NotifyTask.log.trace("Notification delivered {} to {}", _name_1, _listener_4); - } - } catch (final Throwable _t) { - if (_t instanceof Exception) { - final Exception e = (Exception)_t; - NotificationListener _listener_5 = this.getListener(); - NotifyTask.log.error("Unhandled exception thrown by listener: {}", _listener_5, e); - } else { - throw Exceptions.sneakyThrow(_t); - } + getListener().onNotification(notification); + } catch (final Exception e) { + LOG.error("Unhandled exception thrown by listener: {}", listener, e); } - return null; - } - public NotifyTask(final NotificationListener listener, final Notification notification) { - super(); - this._listener = listener; - this._notification = notification; + if (LOG.isDebugEnabled()) { + LOG.debug("Notification delivered {} to {}", notification, listener); + } else { + LOG.trace("Notification delivered {} to {}", notification.getClass().getName(), listener); + } } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((_listener== null) ? 0 : _listener.hashCode()); - result = prime * result + ((_notification== null) ? 0 : _notification.hashCode()); + result = prime * result + ((listener== null) ? 0 : listener.hashCode()); + result = prime * result + ((notification== null) ? 0 : notification.hashCode()); return result; } @@ -105,22 +70,24 @@ public class NotifyTask implements Callable { if (getClass() != obj.getClass()) return false; NotifyTask other = (NotifyTask) obj; - if (_listener == null) { - if (other._listener != null) + if (listener == null) { + if (other.listener != null) return false; - } else if (!_listener.equals(other._listener)) + } else if (!listener.equals(other.listener)) return false; - if (_notification == null) { - if (other._notification != null) + if (notification == null) { + if (other.notification != null) return false; - } else if (!_notification.equals(other._notification)) + } else if (!notification.equals(other.notification)) return false; return true; } @Override public String toString() { - String result = new ToStringHelper().toString(this); - return result; + return Objects.toStringHelper(this) + .add("listener", listener) + .add("notification", notification.getClass()) + .toString(); } }