Add reverse() method in Edge and Path classes
[controller.git] / opendaylight / md-sal / sal-common-api / src / main / java / org / opendaylight / controller / md / sal / common / api / data / DataCommitHandler.java
1 /*
2  * Copyright (c) 2013 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.controller.md.sal.common.api.data;
9
10 import org.opendaylight.controller.sal.common.DataStoreIdentifier;
11 import org.opendaylight.yangtools.concepts.Path;
12 import org.opendaylight.yangtools.yang.common.RpcResult;
13 /**
14  * Two phase commit handler (cohort) of the two-phase commit protocol of data.
15  *
16  * <p>
17  * The provider should expose the implementation of DataCommitHandler if it's
18  * functionality depends on any subset of data stored in data repositories, in
19  * order to participate in {@link DataBrokerService#commit(DataStoreIdentifier)
20  * operation.
21  *
22  * <p>
23  * Operations of two-phase commit handlers should not change data in data store,
24  * this is responsibility of the coordinator (broker or some component of the
25  * broker).
26  *
27  * The commit handlers are responsible for changing the internal state of the
28  * provider to reflect the commited changes in data.
29  *
30  * <h3>Two-phase commit</h3>
31  *
32  * <h4>Commit Request Phase</h4>
33  *
34  * <ol>
35  * <li> <code>Consumer</code> edits data by invocation of
36  * <code>DataBrokerService.editCandidateData(DataStoreIdentifier, DataRoot)</code>
37  * <li> <code>Consumer</code> starts a commit by invoking
38  * <code>DataBrokerService.commit(DataStoreIdentifier)</code>
39  * <li> <code>Broker</code> retrieves a list of all registered
40  * <code>DataCommitHandlers</code>
41  * <li>For each <code>DataCommitHandler</code>
42  * <ol>
43  * <li><code>Broker</code> invokes a
44  * <code>DataCommitHandler.requestCommit(DataStoreIdentifier)</code> operation.
45  * <li><code>DataCommitHandler</code> returns a <code>RpcResult</code> with
46  * <code>CommitTransaction</code>
47  * <li>If the result was successful, broker adds <code>CommitTransaction</code>
48  * to the list of opened transactions. If not, brokers stops a commit request
49  * phase and starts a rollback phase.
50  * </ol>
51  * <li><code>Broker</code> starts a commit finish phase
52  * </ol>
53  *
54  * <h4>Commit Finish Phase</h4>
55  *
56  * <ol>
57  * <li>For each <code>CommitTransaction</code> from Commit Request phase
58  * <ol>
59  * <li><code>Broker</code> broker invokes a
60  * <code>CommitTransaction.finish()</code>
61  * <li>The provider finishes a commit (applies the change) and returns an
62  * <code>RpcResult</code>.
63  * </ol>
64  * <li>
65  * <ul>
66  * <li>If all returned results means successful, the brokers end two-phase
67  * commit by returning a success commit result to the Consumer.
68  * <li>If error occured, the broker starts a commit rollback phase.
69  * </ul>
70  * </ol>
71  *
72  * <h4>Commit Rollback Phase</h4>
73  * <li>For each <code>DataCommitTransaction</code> from Commit Request phase
74  * <ol>
75  * <li><code>Broker</code>
76  * broker invokes a {@link DataCommitTransaction#finish()}
77  * <li>The provider rollbacks a commit and returns an {@link RpcResult} of
78  * rollback. </ol>
79  * <li>Broker returns a error result to the consumer.
80  *
81  * @param <P> Class representing a path
82  * @param <D> Superclass from which all data objects are derived from.
83  */
84 public interface DataCommitHandler<P extends Path<P>, D> {
85
86
87     DataCommitTransaction<P, D> requestCommit(DataModification<P,D> modification);
88
89     public interface DataCommitTransaction<P extends Path<P>, D> {
90
91         DataModification<P,D> getModification();
92
93         /**
94          *
95          * Finishes a commit.
96          *
97          * This callback is invoked by commit coordinator to finish commit action.
98          *
99          * The implementation is required to finish transaction or return unsuccessful
100          * rpc result if something went wrong.
101          *
102          * The provider (commit handler) should apply all changes to its state
103          * which are a result of data change-
104          *
105          * @return
106          */
107         RpcResult<Void> finish() throws IllegalStateException;
108
109         /**
110          * Rollbacks a commit.
111          *
112          * This callback is invoked by commit coordinator to finish commit action.
113          *
114          * The provider (commit handler) should rollback all changes to its state
115          * which were a result of previous request commit.
116          *
117          * @return
118          * @throws IllegalStateException
119          *             If the method is invoked after {@link #finish()}
120          */
121         RpcResult<Void> rollback() throws IllegalStateException;
122     }
123
124 }