3fee8bf2b849371b5c79bfbbc575753516891d0e
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / compat / 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.md.sal.binding.compat;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.opendaylight.controller.sal.binding.api.NotificationListener;
13 import org.opendaylight.yangtools.yang.binding.Notification;
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  * <p>
21  * We take care of that by implementing alternate {@link #hashCode()}/{@link #equals(Object)}, which resolve
22  * to the backing aggregator.
23  *
24  * @param <N> Notification type
25  * @param <A> Aggregator type
26  */
27 @Deprecated
28 abstract class AggregatedNotificationListenerRegistration<N extends Notification, A>
29         extends AbstractNotificationListenerRegistration<N> {
30     private final A aggregator;
31
32     protected AggregatedNotificationListenerRegistration(final Class<? extends Notification> type,
33             final NotificationListener<N> listener, final A aggregator) {
34         super(type, listener);
35         this.aggregator = requireNonNull(aggregator);
36     }
37
38     protected A getAggregator() {
39         return aggregator;
40     }
41
42     @Override
43     public int hashCode() {
44         return aggregator.hashCode();
45     }
46
47     @Override
48     public boolean equals(final Object obj) {
49         if (this == obj) {
50             return true;
51         }
52         if (obj == null) {
53             return false;
54         }
55         if (!this.getClass().equals(obj.getClass())) {
56             return false;
57         }
58
59         return aggregator.equals(((AggregatedNotificationListenerRegistration<?, ?>)obj).aggregator);
60     }
61 }