BUG-614: convert NotificationBrokerImpl
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / impl / NotifyTask.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.binding.impl;
9
10 import java.util.concurrent.Callable;
11
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;
19
20 public class NotifyTask implements Callable<Object> {
21     private static Logger log = new Function0<Logger>() {
22         @Override
23         public Logger apply() {
24             Logger _logger = LoggerFactory.getLogger(NotifyTask.class);
25             return _logger;
26         }
27     }.apply();
28
29     @SuppressWarnings("rawtypes")
30     private final NotificationListener _listener;
31
32     public NotificationListener getListener() {
33         return this._listener;
34     }
35
36     private final Notification _notification;
37
38     public Notification getNotification() {
39         return this._notification;
40     }
41
42     @Override
43     public Object call() {
44         try {
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);
50             } else {
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);
56             }
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);
65             } else {
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);
71             }
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);
77             } else {
78                 throw Exceptions.sneakyThrow(_t);
79             }
80         }
81         return null;
82     }
83
84     public NotifyTask(final NotificationListener listener, final Notification notification) {
85         super();
86         this._listener = listener;
87         this._notification = notification;
88     }
89
90     @Override
91     public int hashCode() {
92         final int prime = 31;
93         int result = 1;
94         result = prime * result + ((_listener== null) ? 0 : _listener.hashCode());
95         result = prime * result + ((_notification== null) ? 0 : _notification.hashCode());
96         return result;
97     }
98
99     @Override
100     public boolean equals(final Object obj) {
101         if (this == obj)
102             return true;
103         if (obj == null)
104             return false;
105         if (getClass() != obj.getClass())
106             return false;
107         NotifyTask other = (NotifyTask) obj;
108         if (_listener == null) {
109             if (other._listener != null)
110                 return false;
111         } else if (!_listener.equals(other._listener))
112             return false;
113         if (_notification == null) {
114             if (other._notification != null)
115                 return false;
116         } else if (!_notification.equals(other._notification))
117             return false;
118         return true;
119     }
120
121     @Override
122     public String toString() {
123         String result = new ToStringHelper().toString(this);
124         return result;
125     }
126 }