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