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 org.opendaylight.controller.sal.binding.api.NotificationListener;
11 import org.opendaylight.yangtools.yang.binding.Notification;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
15 import com.google.common.base.Objects;
16 import com.google.common.base.Preconditions;
18 class NotifyTask implements Runnable {
19 private static final Logger LOG = LoggerFactory.getLogger(NotifyTask.class);
21 private final NotificationListener<?> listener;
22 private final Notification notification;
24 public NotifyTask(final NotificationListener<?> listener, final Notification notification) {
25 this.listener = Preconditions.checkNotNull(listener);
26 this.notification = Preconditions.checkNotNull(notification);
29 @SuppressWarnings("unchecked")
30 private <T extends Notification> NotificationListener<T> getListener() {
31 return (NotificationListener<T>)listener;
36 if (LOG.isDebugEnabled()) {
37 LOG.debug("Delivering notification {} to {}", notification, listener);
39 LOG.trace("Delivering notification {} to {}", notification.getClass().getName(), listener);
43 getListener().onNotification(notification);
44 } catch (final Exception e) {
45 LOG.error("Unhandled exception thrown by listener: {}", listener, e);
48 if (LOG.isDebugEnabled()) {
49 LOG.debug("Notification delivered {} to {}", notification, listener);
51 LOG.trace("Notification delivered {} to {}", notification.getClass().getName(), listener);
56 public int hashCode() {
59 result = prime * result + ((listener== null) ? 0 : listener.hashCode());
60 result = prime * result + ((notification== null) ? 0 : notification.hashCode());
65 public boolean equals(final Object obj) {
70 if (getClass() != obj.getClass())
72 NotifyTask other = (NotifyTask) obj;
73 if (listener == null) {
74 if (other.listener != null)
76 } else if (!listener.equals(other.listener))
78 if (notification == null) {
79 if (other.notification != null)
81 } else if (!notification.equals(other.notification))
87 public String toString() {
88 return Objects.toStringHelper(this)
89 .add("listener", listener)
90 .add("notification", notification.getClass())