Remove common.api.TransactionChain
[mdsal.git] / common / mdsal-common-api / src / main / java / org / opendaylight / mdsal / common / api / AsyncReadWriteTransaction.java
1 /*
2  * Copyright (c) 2017 Brocade Communications 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.common.api;
9
10 import org.opendaylight.yangtools.concepts.Path;
11
12 /**
13  * Transaction enabling a client to have combined read/write capabilities.
14  *
15  * <p>
16  * The initial state of the write transaction is stable snapshot of current data tree
17  * state captured when transaction was created and it's state and underlying
18  * data tree are not affected by other concurrently running transactions.
19  *
20  * <p>
21  * Write transactions are isolated from other concurrent write transactions. All
22  * writes are local to the transaction and represents only a proposal of state
23  * change for data tree and it is not visible to any other concurrently running
24  * transactions.
25  *
26  * <p>
27  * Applications publish the changes proposed in the transaction by calling {@link #commit}
28  * on the transaction. This seals the transaction
29  * (preventing any further writes using this transaction) and commits it to be
30  * processed and applied to global conceptual data tree.
31  *
32  * <p>
33  * The transaction commit may fail due to a concurrent transaction modifying and committing data in
34  * an incompatible way. See {@link #commit()} for more concrete commit failure examples.
35  *
36  * <b>Implementation Note:</b> This interface is not intended to be implemented
37  * by users of MD-SAL, but only to be consumed by them.
38  *
39  * <h2>Examples</h2>
40  *
41  * <h3>Transaction local state</h3>
42  *
43  * <p>
44  * Let's assume initial state of data tree for <code>PATH</code> is <code>A</code>
45  * .
46  * <pre>
47  * txWrite = broker.newReadWriteTransaction(); // concurrent write transaction
48  *
49  * txWrite.read(OPERATIONAL,PATH).get()        // will return Optional containing A
50  * txWrite.put(OPERATIONAL,PATH,B);            // writes B to PATH
51  * txWrite.read(OPERATIONAL,PATH).get()        // will return Optional Containing B
52  *
53  * txWrite.commit().get();                     // data tree is updated, PATH contains B
54  *
55  * tx1afterCommit = broker.newReadOnlyTransaction(); // read Transaction is snapshot of new state
56  * tx1afterCommit.read(OPERATIONAL,PATH).get(); // returns Optional containing B
57  * </pre>
58  *
59  * <p>
60  * As you could see read-write transaction provides capabilities as
61  * {@link AsyncWriteTransaction} but also allows for reading proposed changes as
62  * if they already happened.
63  *
64  * <h3>Transaction isolation (read transaction, read-write transaction)</h3> Let
65  * assume initial state of data tree for <code>PATH</code> is <code>A</code>.
66  *
67  * <pre>
68  * txRead = broker.newReadOnlyTransaction();   // read Transaction is snapshot of data
69  * txWrite = broker.newReadWriteTransaction(); // concurrent write transaction
70  *
71  * txRead.read(OPERATIONAL,PATH).get();        // will return Optional containing A
72  * txWrite.read(OPERATIONAL,PATH).get()        // will return Optional containing A
73  *
74  * txWrite.put(OPERATIONAL,PATH,B);            // writes B to PATH
75  * txWrite.read(OPERATIONAL,PATH).get()        // will return Optional Containing B
76  *
77  * txRead.read(OPERATIONAL,PATH).get();        // concurrent read transaction still returns
78  *                                             // Optional containing A
79  *
80  * txWrite.commit().get();                     // data tree is updated, PATH contains B
81  * txRead.read(OPERATIONAL,PATH).get();        // still returns Optional containing A
82  *
83  * tx1afterCommit = broker.newReadOnlyTransaction(); // read Transaction is snapshot of new state
84  * tx1afterCommit.read(OPERATIONAL,PATH).get(); // returns Optional containing B
85  * </pre>
86  *
87  * <h3>Transaction isolation (2 concurrent read-write transactions)</h3> Let
88  * assume initial state of data tree for <code>PATH</code> is <code>A</code>.
89  *
90  * <pre>
91  * tx1 = broker.newReadWriteTransaction(); // read Transaction is snapshot of data
92  * tx2 = broker.newReadWriteTransaction(); // concurrent write transaction
93  *
94  * tx1.read(OPERATIONAL,PATH).get();       // will return Optional containing A
95  * tx2.read(OPERATIONAL,PATH).get()        // will return Optional containing A
96  *
97  * tx2.put(OPERATIONAL,PATH,B);            // writes B to PATH
98  * tx2.read(OPERATIONAL,PATH).get()        // will return Optional Containing B
99  *
100  * tx1.read(OPERATIONAL,PATH).get();       // tx1 read-write transaction still sees Optional
101  *                                         // containing A since is isolated from tx2
102  * tx1.put(OPERATIONAL,PATH,C);            // writes C to PATH
103  * tx1.read(OPERATIONAL,PATH).get()        // will return Optional Containing C
104  *
105  * tx2.read(OPERATIONAL,PATH).get()        // tx2 read-write transaction still sees Optional
106  *                                         // containing B since is isolated from tx1
107  *
108  * tx2.commit().get();                     // data tree is updated, PATH contains B
109  * tx1.read(OPERATIONAL,PATH).get();       // still returns Optional containing C since is isolated from tx2
110  *
111  * tx1afterCommit = broker.newReadOnlyTransaction(); // read Transaction is snapshot of new state
112  * tx1afterCommit.read(OPERATIONAL,PATH).get(); // returns Optional containing B
113  *
114  * tx1.commit()                            // Will fail with OptimisticLockFailedException
115  *                                         // which means concurrent transaction changed the same PATH
116  *
117  * </pre>
118  *
119  * <p>
120  * <b>Note:</b> examples contains blocking calls on future only to illustrate
121  * that action happened after other asynchronous action. Use of blocking call
122  * {@link com.google.common.util.concurrent.ListenableFuture#get()} is discouraged for most uses and you should
123  * use
124  * {@link com.google.common.util.concurrent.Futures#addCallback(com.google.common.util.concurrent.ListenableFuture,
125  * com.google.common.util.concurrent.FutureCallback)}
126  * or other functions from {@link com.google.common.util.concurrent.Futures} to
127  * register more specific listeners.
128  *
129  * @see AsyncReadTransaction
130  * @see AsyncWriteTransaction
131  *
132  * @param <P> Type of path (subtree identifier), which represents location in tree
133  * @param <D> Type of data (payload), which represents data payload
134  * @deprecated This interface is being removed. Use either
135  *             {@code org.opendaylight.mdsal.binding.api.ReadWriteTransaction}
136  *             or {@code org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction} instead.
137  */
138 @Deprecated
139 public interface AsyncReadWriteTransaction<P extends Path<P>, D> extends AsyncReadTransaction<P, D>,
140         AsyncWriteTransaction<P, D> {
141
142 }