3c6c43c2946def05e89b98c4153d5423746daa1e
[mdsal.git] / binding / mdsal-binding-api / src / main / java / org / opendaylight / mdsal / binding / api / DataTreeChangeListener.java
1 /*
2  * Copyright (c) 2015 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.mdsal.binding.api;
9
10 import java.util.Collection;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.binding.DataObject;
13
14 /**
15  * Interface implemented by classes interested in receiving notifications about
16  * data tree changes. It provides a cursor-based view of the change, which has potentially
17  * lower overhead and allow more flexible consumption of change event.
18  */
19 public interface DataTreeChangeListener<T extends DataObject> {
20     /**
21      * Invoked when there was data change for the supplied path, which was used
22      * to register this listener.
23      *
24      * <p>
25      * This method may be also invoked during registration of the listener if
26      * there is any pre-existing data in the conceptual data tree for supplied
27      * path. This initial event will contain all pre-existing data as created.
28      *
29      * <p>
30      * Note: If there is no pre-existing data, the method {@link #onInitialData} will be invoked.
31      *
32      * <p>
33      * A data change event may be triggered spuriously, e.g. such that data before
34      * and after compare as equal. Implementations of this interface are expected
35      * to recover from such events. Event producers are expected to exert reasonable
36      * effort to suppress such events.
37      *
38      *<p>
39      * In other words, it is completely acceptable to observe
40      * a {@link DataObjectModification}, while the state observed before and
41      * after- data items compare as equal.
42      *
43      * @param changes Collection of change events, may not be null or empty.
44      */
45     void onDataTreeChanged(@NonNull Collection<DataTreeModification<T>> changes);
46
47     /**
48      * Invoked only once during registration of the listener if there was no data in the conceptual data tree
49      * for the supplied path, which was used to register this listener, and after this
50      * {@link #onDataTreeChanged(Collection)} would always be invoked for data changes.
51      *
52      * <p>
53      * Default implementation does nothing and is appropriate for users who do not care about ascertaining
54      * initial state.
55      */
56     // FIXME: 8.0.0: this method should be non-default
57     default void onInitialData() {
58         //no-op
59     }
60 }