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