Fix action invocation and registration
[mdsal.git] / binding / mdsal-binding-api / src / main / java / org / opendaylight / mdsal / binding / api / DataTreeCommitCohort.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.util.concurrent.FluentFuture;
12 import edu.umd.cs.findbugs.annotations.CheckReturnValue;
13 import java.util.Collection;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.mdsal.common.api.DataValidationFailedException;
16 import org.opendaylight.mdsal.common.api.PostCanCommitStep;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18
19 /**
20  * Commit cohort participating in commit of data modification, which can validate data tree
21  * modifications, with option to reject supplied modification, and with callbacks describing state
22  * of commit.
23  *
24  * <h2>Performance implications</h2>
25  *
26  * {@link DataTreeCommitCohort}s are hooked up into commit of data tree changes and MAY
27  * negatively affect performance of data broker / store.
28  *
29  * <p>
30  * Implementations of this interface are discouraged, unless you really need ability to veto data
31  * tree changes, or to provide external state change in sync with visibility of commited data.
32  *
33  * <h2>Implementation requirements</h2>
34  *
35  * <h3>Correctness assumptions</h3> Implementation SHOULD use only provided
36  * {@link DataTreeModification} for validation purposes.
37  *
38  * <p>
39  * Use of any other external mutable state is discouraged, implementation MUST NOT use any
40  * transaction related APIs on same data broker / data store instance during invocation of
41  * callbacks, except ones provided as argument. Note that this MAY BE enforced by some
42  * implementations of {@link DataBroker} or Commit coordinator
43  *
44  * <p>
45  * Note that this may be enforced by some implementations of {@link DataTreeCommitCohortRegistry}
46  * and such calls may fail.
47  *
48  * <h3>DataTreeCandidate assumptions</h3> Implementation SHOULD NOT make any assumptions on
49  * {@link DataTreeModification} being successfully committed until associated
50  * {@link PostCanCommitStep#preCommit()} and
51  * {@link org.opendaylight.mdsal.common.api.PostPreCommitStep#commit()} callback was invoked.
52  *
53  * <h2>Usage patterns</h2>
54  *
55  * <h3>Data Tree Validator</h3>
56  *
57  * <p>
58  * Validator is implementation, which only validates {@link DataTreeModification} and does not
59  * retain any state derived from edited data - does not care if {@link DataTreeModification} was
60  * rejected afterwards or transaction was cancelled.
61  *
62  * <p>
63  * Implementation may opt-out from receiving {@code preCommit()}, {@code commit()}, {@code abort()}
64  * callbacks by returning {@link PostCanCommitStep#NOOP}.
65  *
66  * <p>
67  * TODO: Provide example and describe more usage patterns
68  *
69  * @author Tony Tkacik &lt;ttkacik@cisco.com&gt;
70  */
71 @Beta
72 public interface DataTreeCommitCohort<T extends DataObject> {
73     /**
74      * Validates the supplied data tree modifications and associates the cohort-specific steps with data broker
75      * transaction.
76      *
77      * <p>
78      * If {@link DataValidationFailedException} is thrown by implementation, the commit of the supplied data
79      * will be prevented, with the DataBroker transaction providing the thrown exception as the cause of failure.
80      *
81      * <p>
82      * Note the implementations are expected to do validation and processing asynchronous. Implementations SHOULD do
83      * processing fast, and are discouraged from blocking on any external resources. Implementation MUST NOT access
84      * any data transaction related APIs during invocation of the callback. Note that this may be enforced by some
85      * implementations of {@link DataTreeCommitCohortRegistry} and such calls may fail.
86      *
87      * <p>
88      * Implementation MAY opt-out from implementing other steps by returning
89      * {@link PostCanCommitStep#NOOP}. Otherwise implementation MUST return instance of
90      * {@link PostCanCommitStep}, which will be used to invoke
91      * {@link org.opendaylight.mdsal.common.api.PostPreCommitStep#commit()} or
92      * {@link PostCanCommitStep#abort()} based on accepting data by data broker and or other commit cohorts.
93      *
94      * @param txId Transaction identifier. SHOULD be used only for reporting and correlation.
95      *        Implementation MUST NOT use {@code txId} for validation.
96      * @param modifications the {@link DataTreeModification}s to be validated and committed.
97      * @return a FluentFuture which will successfully complete with the user-supplied implementation of
98      *         {@link PostCanCommitStep} if all candidates are valid, or a failed future with a
99      *         {@link DataValidationFailedException} if and only if a provided
100      *         {@link DataTreeModification} instance did not pass validation. Users are encouraged to use
101      *         more specific subclasses of this exception to provide additional information about
102      *         validation failure reason.
103      */
104     @CheckReturnValue
105     @NonNull FluentFuture<PostCanCommitStep> canCommit(@NonNull Object txId,
106             @NonNull Collection<DataTreeModification<T>> modifications);
107 }