2 * Copyright (c) 2016 Red Hat, 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.genius.datastoreutils;
10 import java.util.Collection;
11 import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
12 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
13 import org.opendaylight.mdsal.binding.api.DataTreeModification;
14 import org.opendaylight.serviceutils.tools.listener.ChainableDataTreeChangeListener;
15 import org.opendaylight.serviceutils.tools.listener.ChainableDataTreeChangeListenerImpl;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
19 * {@link ClusteredDataTreeChangeListener} which is chain-able ({@link ChainableDataTreeChangeListener}).
21 * <p>Do *NOT* use this just in order to be able to wait for change event processing of listeners extending this
22 * in tests with the AsyncEventsWaiter. That is not necessary - because this listener is not asynchronous.
23 * This is just intended to be used for any other cases where you would like a CDTL to be chainable, not
24 * for tests and the AsyncEventsWaiter.
26 * @author Michael Vorburger
28 public abstract class ChainableClusteredDataTreeChangeListenerBase<T extends DataObject>
29 implements ClusteredDataTreeChangeListener<T>, ChainableDataTreeChangeListener<T> {
31 private final ChainableDataTreeChangeListenerImpl<T> chainingDelegate = new ChainableDataTreeChangeListenerImpl<>();
34 public void addBeforeListener(DataTreeChangeListener<T> listener) {
35 chainingDelegate.addBeforeListener(listener);
39 public void addAfterListener(DataTreeChangeListener<T> listener) {
40 chainingDelegate.addAfterListener(listener);
44 public final void onDataTreeChanged(Collection<DataTreeModification<T>> changes) {
45 chainingDelegate.notifyBeforeOnDataTreeChanged(changes);
46 onDataTreeChanged2(changes);
47 chainingDelegate.notifyAfterOnDataTreeChanged(changes);
50 protected abstract void onDataTreeChanged2(Collection<DataTreeModification<T>> changes);