Bug 1435: Fixed incorrect links in javadoc.
[mdsal.git] / dom / mdsal-dom-api / src / main / java / org / opendaylight / mdsal / dom / api / DOMDataTreeCommitCohort.java
1 /*
2  * Copyright (c) 2015 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.dom.api;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.util.concurrent.CheckedFuture;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.mdsal.common.api.DataValidationFailedException;
14 import org.opendaylight.mdsal.common.api.PostCanCommitStep;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
16
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 DOMDataTreeCommitCohort}s are hooked up into commit of data tree changes and MAY
26  * negatively affect performance of data broker / store.
27  *
28  * Implementations of this interface are discouraged, unless you really need ability to veto data
29  * tree changes, or to provide external state change in sync with visibility of commited data.
30  *
31  *
32  * <h2>Implementation requirements</h2>
33  *
34  * <h3>Correctness assumptions</h3> Implementation SHOULD use only {@link DOMDataTreeCandidate} and
35  * provided {@link SchemaContext} for validation purposes.
36  *
37  * Use of any other external mutable state is discouraged, implementation MUST NOT use any
38  * transaction related APIs on same data broker / data store instance during invocation of
39  * callbacks, except ones provided as argument. Note that this MAY BE enforced by some
40  * implementations of {@link DOMDataBroker} or DOMDataCommitCoordinator
41  *
42  * Note that this may be enforced by some implementations of {@link DOMDataTreeCommitCohortRegistry}
43  * and such calls may fail.
44  *
45  * <h3>Correct model usage</h3> If implementation is performing YANG-model driven validation
46  * implementation SHOULD use provided schema context.
47  *
48  * Any other instance of {@link SchemaContext} obtained by other means, may not be valid for
49  * associated DOMDataTreeCandidate and it may lead to incorrect validation or processing of provided
50  * data.
51  *
52  * <h3>DataTreeCandidate assumptions</h3> Implementation SHOULD NOT make any assumptions on
53  * {@link DOMDataTreeCandidate} being successfully committed until associated
54  * {@link PostCanCommitStep#preCommit()} and
55  * {@link org.opendaylight.mdsal.common.api.PostPreCommitStep#commit()} callback was invoked.
56  *
57  *
58  * <h2>Usage patterns</h2>
59  *
60  * <h3>Data Tree Validator</h3>
61  *
62  * Validator is implementation, which only validates {@link DOMDataTreeCandidate} and does not
63  * retain any state derived from edited data - does not care if {@link DOMDataTreeCandidate} was
64  * rejected afterwards or transaction was cancelled.
65  *
66  * Implementation may opt-out from receiving {@code preCommit()}, {@code commit()}, {@code abort()}
67  * callbacks by returning {@link PostCanCommitStep#NOOP}.
68  *
69  * TODO: Provide example and describe more usage patterns
70  *
71  * @author Tony Tkacik &lt;ttkacik@cisco.com&gt;
72  *
73  */
74 @Beta
75 public interface DOMDataTreeCommitCohort {
76
77     /**
78      * Validates supplied data tree candidate and associates cohort-specific steps with data broker
79      * transaction.
80      *
81      * If {@link DataValidationFailedException} is thrown by implementation, commit of supplied data
82      * will be prevented, with the DataBroker transaction providing the thrown exception as the
83      * cause of failure.
84      *
85      * Note the implementations are expected to do validation and processing asynchronous.
86      *
87      * Implementations SHOULD do processing fast, and are discouraged SHOULD NOT block on any
88      * external resources.
89      *
90      * Implementation MUST NOT access any data transaction related APIs during invocation of
91      * callback. Note that this may be enforced by some implementations of
92      * {@link DOMDataTreeCommitCohortRegistry} and such calls may fail.
93      *
94      * Implementation MAY opt-out from implementing other steps by returning
95      * {@link PostCanCommitStep#NOOP}. Otherwise implementation MUST return instance of
96      * {@link PostCanCommitStep}, which will be used to invoke
97      * {@link org.opendaylight.mdsal.common.api.PostPreCommitStep#commit()} or
98      * {@link PostCanCommitStep#abort()} based on accepting data by data broker and or other commit
99      * cohorts.
100      *
101      * @param txId Transaction identifier. SHOULD be used only for reporting and correlation.
102      *        Implementation MUST NOT use {@code txId} for validation.
103      * @param candidate Data Tree candidate to be validated and committed.
104      * @param ctx Schema Context to which Data Tree candidate should conform.
105      * @return Checked future which will successfully complete with user-supplied implementation of
106      *         {@link PostCanCommitStep} if data are valid, or failed check future with
107      *         {@link DataValidationFailedException} if and only if provided
108      *         {@link DOMDataTreeCandidate} did not pass validation. Users are encouraged to use
109      *         more specific subclasses of this exception to provide additional information about
110      *         validation failure reason.
111      */
112     @Nonnull
113     CheckedFuture<PostCanCommitStep, DataValidationFailedException> canCommit(@Nonnull Object txId,
114             @Nonnull DOMDataTreeCandidate candidate, @Nonnull SchemaContext ctx);
115 }