Bug 2933: Make DataTreeModification and Listeners type-safe
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / md / sal / binding / api / DataTreeChangeService.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.controller.md.sal.binding.api;
9
10 import javax.annotation.Nonnull;
11 import org.opendaylight.yangtools.concepts.ListenerRegistration;
12 import org.opendaylight.yangtools.yang.binding.DataObject;
13
14 /**
15  * A {@link DOMService} which allows users to register for changes to a
16  * subtree.
17  */
18 public interface DataTreeChangeService extends BindingService {
19     /**
20      * Registers a {@link DataTreeChangeListener} to receive
21      * notifications when data changes under a given path in the conceptual data
22      * tree.
23      * <p>
24      * You are able to register for notifications  for any node or subtree
25      * which can be represented using {@link DataTreeIdentifier}.
26      * <p>
27      *
28      * You are able to register for data change notifications for a subtree or leaf
29      * even if it does not exist. You will receive notification once that node is
30      * created.
31      * <p>
32      * If there is any pre-existing data in the data tree for the path for which you are
33      * registering, you will receive an initial data change event, which will
34      * contain all pre-existing data, marked as created.
35      *
36      * <p>
37      * This method returns a {@link ListenerRegistration} object. To
38      * "unregister" your listener for changes call the {@link ListenerRegistration#close()}
39      * method on the returned object.
40      * <p>
41      * You MUST explicitly unregister your listener when you no longer want to receive
42      * notifications. This is especially true in OSGi environments, where failure to
43      * do so during bundle shutdown can lead to stale listeners being still registered.
44      *
45      * @param treeId
46      *            Data tree identifier of the subtree which should be watched for
47      *            changes.
48      * @param listener
49      *            Listener instance which is being registered
50      * @return Listener registration object, which may be used to unregister
51      *         your listener using {@link ListenerRegistration#close()} to stop
52      *         delivery of change events.
53      */
54     @Nonnull <T extends DataObject,L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener(@Nonnull DataTreeIdentifier<T> treeId, @Nonnull L listener);
55 }