/* * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.sal.binding.impl; import org.opendaylight.controller.sal.binding.api.NotificationListener; import org.opendaylight.yangtools.yang.binding.Notification; import com.google.common.base.Preconditions; /** * An aggregated listener registration. This is a result of registering an invoker which can handle multiple * interfaces at the same time. In order to support correct delivery, we need to maintain per-type registrations * which get squashed if a notification which implements multiple interfaces is encountered. * * We take care of that by implementing alternate {@link #hashCode()}/{@link #equals(Object)}, which resolve * to the backing aggregator. * * @param Notification type * @param Aggregator type */ abstract class AggregatedNotificationListenerRegistration extends AbstractNotificationListenerRegistration { private final A aggregator; protected AggregatedNotificationListenerRegistration(final Class type, final NotificationListener listener, final A aggregator) { super(type, listener); this.aggregator = Preconditions.checkNotNull(aggregator); } protected A getAggregator() { return aggregator; } @Override public int hashCode() { return aggregator.hashCode(); } @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!this.getClass().equals(obj.getClass())) { return false; } return aggregator.equals(((AggregatedNotificationListenerRegistration)obj).aggregator); } }