2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.api;
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableSet;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
15 import org.opendaylight.yangtools.yang.binding.Action;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.opendaylight.yangtools.yang.binding.RpcInput;
21 * Provides access to registered {@code action} implementations. Each action is defined in a YANG model,
22 * and implementations are added dynamically at runtime, via {@link ActionProviderService}.
24 * @author Robert Varga
28 public interface ActionService extends BindingService {
30 * Returns an implementation of a requested {@link Action}. Returned instance is not an actual implementation
31 * of the Action service interface, but a proxy implementation of the interface that forwards to an actual
32 * implementation, if any.
35 * The following describes the behavior of the proxy when invoking
36 * {@link Action#invoke(InstanceIdentifier, RpcInput)}:
38 * <li>If an actual implementation is registered with the MD-SAL, all invocations are forwarded to the registered
39 * implementation.</li>
40 * <li>If no actual implementation is registered, all invocations will fail by throwing
41 * {@link IllegalStateException}.</li>
42 * <li>Prior to invoking the actual implementation, the method arguments are are validated. If any are invalid,
43 * an {@link IllegalArgumentException} is thrown.
47 * The returned proxy is automatically updated with the most recent registered implementation, hence there is no
48 * guarantee that multiple consecutive invocations will be handled by the same implementation.
50 * @param actionInterface Generated Action interface
51 * @param validNodes Set of nodes this service will be constrained to, empty if no constraints are known
52 * @return A proxy implementation of the generated interface
53 * @throws NullPointerException if {@code actionInterface} is null
54 * @throws IllegalArgumentException when {@code actionInterface} does not conform to the Binding Specification
56 <O extends DataObject, T extends Action<?, ?, ?>> T getActionHandle(Class<T> actionInterface,
57 Set<DataTreeIdentifier<O>> validNodes);
59 default <O extends DataObject, T extends Action<O, ?, ?>> T getActionHandle(final Class<T> actionInterface) {
60 return getActionHandle(actionInterface, ImmutableSet.of());
63 default <O extends DataObject, T extends Action<O, ?, ?>> T getActionHandle(final Class<T> actionInterface,
64 final LogicalDatastoreType dataStore, final InstanceIdentifier<O> path) {
65 return getActionHandle(actionInterface, ImmutableSet.of(DataTreeIdentifier.create(dataStore, path)));
68 default <O extends DataObject, T extends Action<O, ?, ?>> T getActionHandle(final Class<T> actionInterface,
69 final InstanceIdentifier<O> path) {
70 return getActionHandle(actionInterface, LogicalDatastoreType.OPERATIONAL, path);
73 default <O extends DataObject, T extends Action<O, ?, ?>> T getActionHandle(final Class<T> actionInterface,
74 @SuppressWarnings("unchecked") final DataTreeIdentifier<O>... nodes) {
75 return getActionHandle(actionInterface, ImmutableSet.copyOf(nodes));