2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.binding.impl;
10 import java.util.concurrent.Callable;
12 import org.eclipse.xtext.xbase.lib.Exceptions;
13 import org.eclipse.xtext.xbase.lib.Functions.Function0;
14 import org.eclipse.xtext.xbase.lib.util.ToStringHelper;
15 import org.opendaylight.controller.sal.binding.api.NotificationListener;
16 import org.opendaylight.yangtools.yang.binding.Notification;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public class NotifyTask implements Callable<Object> {
21 private static Logger log = new Function0<Logger>() {
23 public Logger apply() {
24 Logger _logger = LoggerFactory.getLogger(NotifyTask.class);
29 @SuppressWarnings("rawtypes")
30 private final NotificationListener _listener;
32 public NotificationListener getListener() {
33 return this._listener;
36 private final Notification _notification;
38 public Notification getNotification() {
39 return this._notification;
43 public Object call() {
45 boolean _isDebugEnabled = NotifyTask.log.isDebugEnabled();
46 if (_isDebugEnabled) {
47 Notification _notification = this.getNotification();
48 NotificationListener _listener = this.getListener();
49 NotifyTask.log.debug("Delivering notification {} to {}", _notification, _listener);
51 Notification _notification_1 = this.getNotification();
52 Class<? extends Notification> _class = _notification_1.getClass();
53 String _name = _class.getName();
54 NotificationListener _listener_1 = this.getListener();
55 NotifyTask.log.trace("Delivering notification {} to {}", _name, _listener_1);
57 NotificationListener _listener_2 = this.getListener();
58 Notification _notification_2 = this.getNotification();
59 _listener_2.onNotification(_notification_2);
60 boolean _isDebugEnabled_1 = NotifyTask.log.isDebugEnabled();
61 if (_isDebugEnabled_1) {
62 Notification _notification_3 = this.getNotification();
63 NotificationListener _listener_3 = this.getListener();
64 NotifyTask.log.debug("Notification delivered {} to {}", _notification_3, _listener_3);
66 Notification _notification_4 = this.getNotification();
67 Class<? extends Notification> _class_1 = _notification_4.getClass();
68 String _name_1 = _class_1.getName();
69 NotificationListener _listener_4 = this.getListener();
70 NotifyTask.log.trace("Notification delivered {} to {}", _name_1, _listener_4);
72 } catch (final Throwable _t) {
73 if (_t instanceof Exception) {
74 final Exception e = (Exception)_t;
75 NotificationListener _listener_5 = this.getListener();
76 NotifyTask.log.error("Unhandled exception thrown by listener: {}", _listener_5, e);
78 throw Exceptions.sneakyThrow(_t);
84 public NotifyTask(final NotificationListener listener, final Notification notification) {
86 this._listener = listener;
87 this._notification = notification;
91 public int hashCode() {
94 result = prime * result + ((_listener== null) ? 0 : _listener.hashCode());
95 result = prime * result + ((_notification== null) ? 0 : _notification.hashCode());
100 public boolean equals(final Object obj) {
105 if (getClass() != obj.getClass())
107 NotifyTask other = (NotifyTask) obj;
108 if (_listener == null) {
109 if (other._listener != null)
111 } else if (!_listener.equals(other._listener))
113 if (_notification == null) {
114 if (other._notification != null)
116 } else if (!_notification.equals(other._notification))
122 public String toString() {
123 String result = new ToStringHelper().toString(this);