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.md.sal.binding.compat;
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.yangtools.yang.binding.Notification;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 class NotifyTask implements Runnable {
17 private static final Logger LOG = LoggerFactory.getLogger(NotifyTask.class);
19 private final NotificationListenerRegistration<?> registration;
20 private final Notification notification;
22 public NotifyTask(final NotificationListenerRegistration<?> registration, final Notification notification) {
23 this.registration = Preconditions.checkNotNull(registration);
24 this.notification = Preconditions.checkNotNull(notification);
27 @SuppressWarnings("unchecked")
28 private <T extends Notification> NotificationListenerRegistration<T> getRegistration() {
29 return (NotificationListenerRegistration<T>)registration;
34 if (LOG.isDebugEnabled()) {
35 LOG.debug("Delivering notification {} to {}", notification, registration.getInstance());
37 LOG.trace("Delivering notification {} to {}", notification.getClass().getName(), registration.getInstance());
41 getRegistration().notify(notification);
42 } catch (final Exception e) {
43 LOG.error("Unhandled exception thrown by listener: {}", registration.getInstance(), e);
46 if (LOG.isDebugEnabled()) {
47 LOG.debug("Notification delivered {} to {}", notification, registration.getInstance());
49 LOG.trace("Notification delivered {} to {}", notification.getClass().getName(), registration.getInstance());
54 public int hashCode() {
57 result = prime * result + ((registration== null) ? 0 : registration.hashCode());
58 result = prime * result + ((notification== null) ? 0 : notification.hashCode());
63 public boolean equals(final Object obj) {
70 if (getClass() != obj.getClass()) {
73 final NotifyTask other = (NotifyTask) obj;
74 if (registration == null) {
75 if (other.registration != null) {
78 } else if (!registration.equals(other.registration)) {
81 if (notification == null) {
82 if (other.notification != null) {
85 } else if (!notification.equals(other.notification)) {
92 public String toString() {
93 return MoreObjects.toStringHelper(this)
94 .add("listener", registration)
95 .add("notification", notification.getClass())