Reduce ObjectRegistration use
[mdsal.git] / binding / mdsal-binding-api / src / main / java / org / opendaylight / mdsal / binding / api / ActionService.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.binding.api;
9
10 import com.google.common.collect.ImmutableSet;
11 import java.util.Set;
12 import org.eclipse.jdt.annotation.NonNullByDefault;
13 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
14 import org.opendaylight.yangtools.yang.binding.Action;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.opendaylight.yangtools.yang.binding.RpcInput;
18
19 /**
20  * Provides access to registered {@code action} implementations. Each action is defined in a YANG model,
21  * and implementations are added dynamically at runtime, via {@link ActionProviderService}.
22  */
23 @NonNullByDefault
24 public interface ActionService extends BindingService {
25     /**
26      * Returns an implementation of a requested {@link Action}. Returned instance is not an actual implementation
27      * of the Action service interface, but a proxy implementation of the interface that forwards to an actual
28      * implementation, if any.
29      *
30      * <p>
31      * The following describes the behavior of the proxy when invoking
32      * {@link Action#invoke(InstanceIdentifier, RpcInput)}:
33      * <ul>
34      * <li>If an actual implementation is registered with the MD-SAL, all invocations are forwarded to the registered
35      * implementation.</li>
36      * <li>If no actual implementation is registered, all invocations will fail by throwing
37      * {@link IllegalStateException}.</li>
38      * <li>Prior to invoking the actual implementation, the method arguments are are validated. If any are invalid,
39      * an {@link IllegalArgumentException} is thrown.
40      * </ul>
41      *
42      * <p>
43      * The returned proxy is automatically updated with the most recent registered implementation, hence there is no
44      * guarantee that multiple consecutive invocations will be handled by the same implementation.
45      *
46      * @param spec Action instance specification
47      * @param validNodes Set of nodes this service will be constrained to, empty if no constraints are known
48      * @return A proxy implementation of the generated interface
49      * @throws NullPointerException if {@code actionInterface} is null
50      * @throws IllegalArgumentException when {@code actionInterface} does not conform to the Binding Specification
51      */
52     <P extends DataObject, A extends Action<? extends InstanceIdentifier<P>, ?, ?>> A getActionHandle(
53         ActionSpec<A, P> spec, Set<DataTreeIdentifier<P>> validNodes);
54
55     default <P extends DataObject, A extends Action<? extends InstanceIdentifier<P>, ?, ?>> A getActionHandle(
56             final ActionSpec<A, P> spec) {
57         return getActionHandle(spec, ImmutableSet.of());
58     }
59
60     default <P extends DataObject, A extends Action<? extends InstanceIdentifier<P>, ?, ?>> A getActionHandle(
61             final ActionSpec<A, P> spec, final LogicalDatastoreType dataStore, final InstanceIdentifier<P> path) {
62         return getActionHandle(spec, ImmutableSet.of(DataTreeIdentifier.of(dataStore, path)));
63     }
64
65     default <P extends DataObject, A extends Action<? extends InstanceIdentifier<P>, ?, ?>> A getActionHandle(
66             final ActionSpec<A, P> spec, final InstanceIdentifier<P> path) {
67         return getActionHandle(spec, LogicalDatastoreType.OPERATIONAL, path);
68     }
69
70     default <P extends DataObject, A extends Action<? extends InstanceIdentifier<P>, ?, ?>> A getActionHandle(
71             final ActionSpec<A, P> spec, @SuppressWarnings("unchecked") final DataTreeIdentifier<P>... nodes) {
72         return getActionHandle(spec, ImmutableSet.copyOf(nodes));
73     }
74 }