a818c833e74809dc65931a1b8113a71483ad2739
[mdsal.git] / binding / mdsal-binding-api / src / main / java / org / opendaylight / mdsal / binding / api / ActionProviderService.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.annotations.Beta;
11 import com.google.common.collect.ImmutableSet;
12 import java.util.Set;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
15 import org.opendaylight.yangtools.concepts.ObjectRegistration;
16 import org.opendaylight.yangtools.yang.binding.Action;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19
20 /**
21  * Registration interface used by {@code action} implementations. Each action is defined in a YANG model,
22  * and implementations can be invoked  dynamically at runtime, via {@link ActionService}. Implementations registered
23  * with this interface may throw {@link IllegalArgumentException}s when they encounter inconsistent input data and
24  * {@link IllegalStateException} in they are unable to service the request.
25  *
26  * @author Robert Varga
27  */
28 @Beta
29 public interface ActionProviderService extends BindingService {
30     /**
31      * Register an implementation of an action, potentially constrained to a set of nodes.
32      *
33      * @param spec Action instance specification
34      * @param implementation Implementation of {@code actionInterface}
35      * @param datastore {@link LogicalDatastoreType} on which the implementation operates
36      * @param validNodes Set of nodes this implementation is constrained to, empty if this implementation can handle
37      *                   any target node.
38      * @return An {@link ObjectRegistration}
39      * @throws NullPointerException if any of the arguments is null
40      * @throws IllegalArgumentException if any of the {@code validNodes} does not match {@code datastore}
41      * @throws UnsupportedOperationException if this service cannot handle requested datastore
42      */
43     <P extends DataObject, A extends Action<? extends InstanceIdentifier<P>, ?, ?>, S extends A>
44         @NonNull ObjectRegistration<S> registerImplementation(@NonNull ActionSpec<A, P> spec, @NonNull S implementation,
45             @NonNull LogicalDatastoreType datastore, @NonNull Set<? extends InstanceIdentifier<P>> validNodes);
46
47     default <P extends DataObject, T extends Action<? extends InstanceIdentifier<P>, ?, ?>, S extends T>
48         @NonNull ObjectRegistration<S> registerImplementation(final @NonNull ActionSpec<T, P> spec,
49             final @NonNull S implementation, final @NonNull LogicalDatastoreType datastore) {
50         return registerImplementation(spec, implementation, datastore, ImmutableSet.of());
51     }
52
53     default <P extends DataObject, T extends Action<? extends InstanceIdentifier<P>, ?, ?>, S extends T>
54         @NonNull ObjectRegistration<S> registerImplementation(final @NonNull ActionSpec<T, P> spec,
55             final @NonNull S implementation) {
56         return registerImplementation(spec, implementation, LogicalDatastoreType.OPERATIONAL);
57     }
58 }