Deprecate all MD-SAL APIs
[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 com.google.common.base.Preconditions;
11 import org.opendaylight.controller.sal.binding.api.NotificationListener;
12 import org.opendaylight.yangtools.yang.binding.Notification;
13
14 /**
15  * An aggregated listener registration. This is a result of registering an invoker which can handle multiple
16  * interfaces at the same time. In order to support correct delivery, we need to maintain per-type registrations
17  * which get squashed if a notification which implements multiple interfaces is encountered.
18  *
19  * <p>
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 @Deprecated
27 abstract class AggregatedNotificationListenerRegistration<N extends Notification, A>
28         extends AbstractNotificationListenerRegistration<N> {
29     private final A aggregator;
30
31     protected AggregatedNotificationListenerRegistration(final Class<? extends Notification> type,
32             final NotificationListener<N> listener, final A aggregator) {
33         super(type, listener);
34         this.aggregator = Preconditions.checkNotNull(aggregator);
35     }
36
37     protected A getAggregator() {
38         return aggregator;
39     }
40
41     @Override
42     public int hashCode() {
43         return aggregator.hashCode();
44     }
45
46     @Override
47     public boolean equals(final Object obj) {
48         if (this == obj) {
49             return true;
50         }
51         if (obj == null) {
52             return false;
53         }
54         if (!this.getClass().equals(obj.getClass())) {
55             return false;
56         }
57
58         return aggregator.equals(((AggregatedNotificationListenerRegistration<?, ?>)obj).aggregator);
59     }
60 }