Merge "BUG-1200 changed help for agentpath && added comment describing functions.sh"
[controller.git] / opendaylight / md-sal / sal-common-api / src / main / java / org / opendaylight / controller / md / sal / common / api / data / AsyncDataTransactionFactory.java
1 /*
2  * Copyright (c) 2014 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.yangtools.concepts.Path;
11
12 /**
13  * A factory which allocates new transactions to operate on the data
14  * tree.
15  *
16  * <p>
17  * <b>Note:</b> This interface is not intended to be used directly, but rather
18  * via subinterfaces which introduces additional semantics to allocated
19  * transactions.
20  * <ul>
21  * <li> {@link AsyncDataBroker}
22  * <li> {@link TransactionChain}
23  * </ul>
24  *
25  * <p>
26  * All operations on the data tree are performed via one of the transactions:
27  * <ul>
28  * <li>Read-Only - allocated using {@link #newReadOnlyTransaction()}
29  * <li>Write-Only - allocated using {@link #newWriteOnlyTransaction()}
30  * <li>Read-Write - allocated using {@link #newReadWriteTransaction()}
31  * </ul>
32  *
33  * <p>
34  * These transactions provides a stable isolated view of the data tree, which is
35  * guaranteed to be not affected by other concurrent transactions, until
36  * transaction is committed.
37  *
38  * <p>
39  * For a detailed explanation of how transaction are isolated and how transaction-local
40  * changes are committed to global data tree, see
41  * {@link AsyncReadTransaction}, {@link AsyncWriteTransaction},
42  * {@link AsyncReadWriteTransaction} and {@link AsyncWriteTransaction#commit()}.
43  *
44  * <p>
45  * It is strongly recommended to use the type of transaction, which
46  * provides only the minimal capabilities you need. This allows for
47  * optimizations at the data broker / data store level. For example,
48  * implementations may optimize the transaction for reading if they know ahead
49  * of time that you only need to read data - such as not keeping additional meta-data,
50  * which may be required for write transactions.
51  *<p>
52  * <b>Implementation Note:</b> This interface is not intended to be implemented
53  * by users of MD-SAL, but only to be consumed by them.
54  *
55  * @see AsyncDataBroker
56  * @see TransactionChain
57  *
58  * @param <P>
59  *            Type of path (subtree identifier), which represents location in
60  *            tree
61  * @param <D>
62  *            Type of data (payload), which represents data payload
63  */
64 public interface AsyncDataTransactionFactory<P extends Path<P>, D> {
65
66     /**
67      * Allocates a new read-only transaction which provides an immutable snapshot of
68      * the data tree.
69      *<p>
70      * The view of data tree is an immutable snapshot of current data tree state when
71      * transaction was allocated.
72      *
73      * @return new read-only transaction
74      */
75     AsyncReadOnlyTransaction<P, D> newReadOnlyTransaction();
76
77     /**
78      * Allocates new read-write transaction which provides a mutable view of the data
79      * tree.
80      *
81      * <p>
82      * Preconditions for mutation of data tree are captured from the snapshot of
83      * data tree state, when the transaction is allocated. If data was
84      * changed during transaction in an incompatible way then the commit of this transaction
85      * will fail. See {@link AsyncWriteTransaction#commit()} for more
86      * details about conflicting and not-conflicting changes and
87      * failure scenarios.
88      *
89      * @return new read-write transaction
90      */
91     AsyncReadWriteTransaction<P, D> newReadWriteTransaction();
92
93     /**
94      * Allocates new write-only transaction based on latest state of data
95      * tree.
96      *
97      * <p>
98      * Preconditions for mutation of data tree are captured from the snapshot of
99      * data tree state, when the transaction is allocated. If data was
100      * changed during transaction in an incompatible way then the commit of this transaction
101      * will fail. See {@link AsyncWriteTransaction#commit()} for more
102      * details about conflicting and not-conflicting changes and
103      * failure scenarios.
104      *
105      * <p>
106      * Since this transaction does not provide a view of the data it SHOULD BE
107      * used only by callers which are exclusive writers (exporters of data)
108      * to the subtree they modify. This prevents optimistic
109      * lock failures as described in {@link AsyncWriteTransaction#commit()}.
110      * <p>
111      * Exclusivity of writers to particular subtree SHOULD BE enforced by
112      * external locking mechanism.
113      *
114      * @return new write-only transaction
115      */
116     AsyncWriteTransaction<P, D> newWriteOnlyTransaction();
117
118 }