Refactor DOM{Action,Rpc}Implementation
[mdsal.git] / dom / mdsal-dom-api / src / main / java / org / opendaylight / mdsal / dom / api / DOMActionAvailabilityExtension.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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.dom.api;
9
10 import com.google.common.annotations.Beta;
11 import java.util.Set;
12 import org.eclipse.jdt.annotation.NonNullByDefault;
13 import org.opendaylight.yangtools.concepts.Registration;
14 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
15 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
16
17 /**
18  * A {@link DOMActionService.Extension} exposed by {@link DOMActionService}s which allow their users to listen
19  * for actions are becoming available.
20  */
21 @Beta
22 @NonNullByDefault
23 public interface DOMActionAvailabilityExtension extends DOMActionService.Extension {
24     /**
25      * Register a {@link AvailabilityListener} with this service to receive notifications about operation
26      * implementations becoming (un)available. The listener will be invoked with the current implementations reported
27      * and will be kept uptodate as implementations come and go.
28      *
29      * <p>
30      * Users should note that using a listener does not necessarily mean that
31      * {@link DOMActionService#invokeAction(Absolute, DOMDataTreeIdentifier, ContainerNode)} will not report
32      * a failure due to {@link DOMActionNotAvailableException} and need to be ready to handle it.
33      *
34      * <p>
35      * Implementations are encouraged to take reasonable precautions to prevent this scenario from occurring.
36      *
37      * @param listener {@link AvailabilityListener} instance to register
38      * @return A {@link Registration} representing this registration. Performing a {@link Registration#close()} will
39      *         cancel it.
40      * @throws NullPointerException if {@code listener} is null
41      */
42     Registration registerAvailabilityListener(AvailabilityListener listener);
43
44     /**
45      * A listener used to track Operation implementations becoming (un)available to a {@link DOMActionService}.
46      */
47     interface AvailabilityListener {
48         /**
49          * Method invoked whenever an action type becomes available or unavailable. There are two sets reported,
50          * removed and added. To reconstruct the state, first apply removed and then added operations, like this:
51          *
52          * <code>
53          *     Set&lt;DOMActionInstancelt;?&gt;&gt; operations;
54          *     operations.removeAll(removed);
55          *     operations.addAll(added);
56          * </code>
57          *
58          * @param removed operations which disappeared
59          * @param added operations which became available
60          */
61         void onActionsChanged(Set<DOMActionInstance> removed, Set<DOMActionInstance> added);
62
63         /**
64          * Implementation filtering method. This method is useful for forwarding operation implementations,
65          * which need to ensure they do not re-announce their own implementations. Without this method
66          * a forwarder which registers an implementation would be notified of its own implementation,
67          * potentially re-exporting it as local -- hence creating a forwarding loop.
68          *
69          * @param impl Operation implementation being registered
70          * @return False if the implementation should not be reported, defaults to true.
71          */
72         default boolean acceptsImplementation(final DOMActionImplementation impl) {
73             return true;
74         }
75     }
76 }