f0db891f140be765580ac9eedb3c07e8c84f0d4d
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / impl / AggregatedNotificationListenerRegistration.java
1 /*
2  * Copyright (c) 2014 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 org.opendaylight.controller.sal.binding.api.NotificationListener;
11 import org.opendaylight.yangtools.yang.binding.Notification;
12
13 import com.google.common.base.Preconditions;
14
15 /**
16  * An aggregated listener registration. This is a result of registering an invoker which can handle multiple
17  * interfaces at the same time. In order to support correct delivery, we need to maintain per-type registrations
18  * which get squashed if a notification which implements multiple interfaces is encountered.
19  *
20  * We take care of that by implementing alternate {@link #hashCode()}/{@link #equals(Object)}, which resolve
21  * to the backing aggregator.
22  *
23  * @param <N> Notification type
24  * @param <A> Aggregator type
25  */
26 abstract class AggregatedNotificationListenerRegistration<N extends Notification, A> extends AbstractNotificationListenerRegistration<N> {
27     private final A aggregator;
28
29     protected AggregatedNotificationListenerRegistration(final Class<? extends Notification> type, final NotificationListener<N> listener, final A aggregator) {
30         super(type, listener);
31         this.aggregator = Preconditions.checkNotNull(aggregator);
32     }
33
34     protected A getAggregator() {
35         return aggregator;
36     }
37
38     @Override
39     public int hashCode() {
40         return aggregator.hashCode();
41     }
42
43     @Override
44     public boolean equals(final Object obj) {
45         if (this == obj) {
46             return true;
47         }
48         if (obj == null) {
49             return false;
50         }
51         if (!this.getClass().equals(obj.getClass())) {
52             return false;
53         }
54
55         return aggregator.equals(((AggregatedNotificationListenerRegistration<?, ?>)obj).aggregator);
56     }
57 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.