Port WriteTransaction constants from controller
[mdsal.git] / binding / mdsal-binding-api / src / main / java / org / opendaylight / mdsal / binding / api / DataTreeProducer.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.binding.api;
9
10 import java.util.Collection;
11 import javax.annotation.Nonnull;
12
13 /**
14  * A data producer context. It allows transactions to be submitted to the subtrees specified at
15  * instantiation time. At any given time there may be a single transaction open. It needs to be
16  * either submitted or cancelled before another one can be open. Once a transaction is submitted, it
17  * will proceed to be committed asynchronously.
18  *
19  *<p>
20  * Each instance has an upper bound on the number of transactions which can be in-flight, once that
21  * capacity is exceeded, an attempt to create a new transaction will block until some transactions
22  * complete.
23  *
24  *<p>
25  * Each {@link DataTreeProducer} can be in two logical states, bound and unbound, which define the
26  * lifecycle rules for when is it legal to create and submit transactions in relationship with
27  * {@link DataTreeListener} callbacks.
28  *
29  *<p>
30  * When a producer is first created, it is unbound. In this state the producer can be accessed by
31  * any application thread to allocate or submit transactions, as long as the 'single open
32  * transaction' rule is maintained. The producer and any transaction object MUST NOT be accessed,
33  * directly or indirectly, from a {@link DataTreeListener} callback.
34  *
35  * <p>
36  * When a producer is referenced in a call to
37  * {@link DataTreeService#registerListener(DataTreeListener, java.util.Collection, boolean, java.util.Collection)}
38  * , an attempt will be made to bind the producer to the specified {@link DataTreeListener}. Such an
39  * attempt will fail the producer is already bound, or it has an open transaction. Once bound, the
40  * producer can only be accessed from within the {@link DataTreeListener} callback on that
41  * particular instance. Any transaction which is not submitted by the time the callback returns will
42  * be implicitly cancelled. A producer becomes unbound when the listener it is bound to becomes
43  * unregistered.
44  *
45  */
46 public interface DataTreeProducer extends DataTreeProducerFactory, AutoCloseable {
47     /**
48      * Allocate a new open transaction on this producer. Any and all transactions previously
49      * allocated must have been either submitted or cancelled by the time this method is invoked.
50      *
51      * @param isolated Indicates whether this transaction should be a barrier. A barrier transaction
52      *        is processed separately from any preceding transactions. Non-barrier transactions may
53      *        be merged and processed in a batch, such that any observers see the modifications
54      *        contained in them as if the modifications were made in a single transaction.
55      * @return A new {@link CursorAwareWriteTransaction}
56      * @throws IllegalStateException if a previous transaction was not closed.
57      * @throws IllegalThreadStateException if the calling thread context does not match the
58      *         lifecycle rules enforced by the producer state (e.g. bound or unbound). This
59      *         exception is thrown on a best effort basis and programs should not rely on it for
60      *         correct operation.
61      */
62     @Nonnull
63     CursorAwareWriteTransaction createTransaction(boolean isolated);
64
65     /**
66      * {@inheritDoc}.
67      *
68      *<p>
69      * When invoked on a {@link DataTreeProducer}, this method has additional restrictions. There
70      * may not be an open transaction from this producer. The method needs to be invoked in
71      * appropriate context, e.g. bound or unbound.
72      *
73      *<p>
74      * Specified subtrees must be accessible by this producer. Accessible means they are a subset of
75      * the subtrees specified when the producer is instantiated. The set is further reduced as child
76      * producers are instantiated -- if you create a producer for /a and then a child for /a/b, /a/b
77      * is not accessible from the first producer.
78      *
79      *<p>
80      * Once this method returns successfully, this (parent) producer loses the ability to access the
81      * specified paths until the resulting (child) producer is shut down.
82      *
83      * @throws IllegalStateException if there is an open transaction
84      * @throws IllegalArgumentException if subtrees contains a subtree which is not accessible by
85      *         this producer
86      * @throws IllegalThreadStateException if the calling thread context does not match the
87      *         lifecycle rules enforced by the producer state (e.g. bound or unbound). This
88      *         exception is thrown on a best effort basis and programs should not rely on it for
89      *         correct operation.
90      */
91     @Override
92     @Nonnull
93     DataTreeProducer createProducer(@Nonnull Collection<DataTreeIdentifier<?>> subtrees);
94
95     /**
96      * {@inheritDoc}.
97      *
98      * @throws DataTreeProducerBusyException when there is an open transaction.
99      */
100     @Override
101     void close() throws DataTreeProducerException;
102 }