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