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.yangtools.yang.binding.Notification;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
14 import com.google.common.base.Objects;
15 import com.google.common.base.Preconditions;
17 class NotifyTask implements Runnable {
18 private static final Logger LOG = LoggerFactory.getLogger(NotifyTask.class);
20 private final NotificationListenerRegistration<?> registration;
21 private final Notification notification;
23 public NotifyTask(final NotificationListenerRegistration<?> registration, final Notification notification) {
24 this.registration = Preconditions.checkNotNull(registration);
25 this.notification = Preconditions.checkNotNull(notification);
28 @SuppressWarnings("unchecked")
29 private <T extends Notification> NotificationListenerRegistration<T> getRegistration() {
30 return (NotificationListenerRegistration<T>)registration;
35 if (LOG.isDebugEnabled()) {
36 LOG.debug("Delivering notification {} to {}", notification, registration.getInstance());
38 LOG.trace("Delivering notification {} to {}", notification.getClass().getName(), registration.getInstance());
42 getRegistration().notify(notification);
43 } catch (final Exception e) {
44 LOG.error("Unhandled exception thrown by listener: {}", registration.getInstance(), e);
47 if (LOG.isDebugEnabled()) {
48 LOG.debug("Notification delivered {} to {}", notification, registration.getInstance());
50 LOG.trace("Notification delivered {} to {}", notification.getClass().getName(), registration.getInstance());
55 public int hashCode() {
58 result = prime * result + ((registration== null) ? 0 : registration.hashCode());
59 result = prime * result + ((notification== null) ? 0 : notification.hashCode());
64 public boolean equals(final Object obj) {
69 if (getClass() != obj.getClass())
71 NotifyTask other = (NotifyTask) obj;
72 if (registration == null) {
73 if (other.registration != null)
75 } else if (!registration.equals(other.registration))
77 if (notification == null) {
78 if (other.notification != null)
80 } else if (!notification.equals(other.notification))
86 public String toString() {
87 return Objects.toStringHelper(this)
88 .add("listener", registration)
89 .add("notification", notification.getClass())