Migrate mdsal-dom-api to JDT annotations
[mdsal.git] / dom / mdsal-dom-api / src / main / java / org / opendaylight / mdsal / dom / api / DOMDataTreeProducer.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 java.util.Collection;
11 import org.eclipse.jdt.annotation.NonNull;
12
13 /**
14  * A data producer context. It allows transactions to be submitted to the subtrees
15  * specified at instantiation time. At any given time there may be a single transaction
16  * open. It needs to be either submitted or cancelled before another one can be open.
17  * Once a transaction is submitted, it 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,
21  * once that capacity is exceeded, an attempt to create a new transaction will block
22  * until some transactions complete.
23  *
24  * <p>
25  * Each {@link DOMDataTreeProducer} can be in two logical states, bound and unbound,
26  * which define the lifecycle rules for when is it legal to create and submit transactions
27  * in relationship with {@link DOMDataTreeListener} callbacks.
28  *
29  * <p>
30  * When a producer is first created, it is unbound. In this state the producer can be
31  * accessed by any application thread to allocate or submit transactions, as long as
32  * the 'single open transaction' rule is maintained. The producer and any transaction
33  * object MUST NOT be accessed, directly or indirectly, from a {@link DOMDataTreeListener}
34  * callback.
35  *
36  * <p>
37  * When a producer is referenced in a call to {@link DOMDataTreeService#registerListener(DOMDataTreeListener,
38  * Collection, boolean, Collection)},
39  * an attempt will be made to bind the producer to the specified {@link DOMDataTreeListener}.
40  * Such an attempt will fail the producer is already bound, or it has an open transaction.
41  * Once bound, the producer can only be accessed from within the {@link DOMDataTreeListener}
42  * callback on that particular instance. Any transaction which is not submitted by the
43  * time the callback returns will be implicitly cancelled. A producer becomes unbound
44  * when the listener it is bound to becomes unregistered.
45  */
46 public interface DOMDataTreeProducer extends DOMDataTreeProducerFactory, 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 DOMDataTreeCursorAwareTransaction}
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 DOMDataTreeCursorAwareTransaction createTransaction(boolean isolated);
63
64     /**
65      * {@inheritDoc}.
66      *
67      * <p>
68      * When invoked on a {@link DOMDataTreeProducer}, this method has additional restrictions. There
69      * may not be an open transaction from this producer. The method needs to be invoked in
70      * appropriate context, e.g. bound or unbound.
71      *
72      * <p>
73      * Specified subtrees must be accessible by this producer. Accessible means they are a subset of
74      * the subtrees specified when the producer is instantiated. The set is further reduced as child
75      * producers are instantiated -- if you create a producer for /a and then a child for /a/b, /a/b
76      * is not accessible from the first producer.
77      * Once this method returns successfully, this (parent) producer loses the ability to access the
78      * specified paths until the resulting (child) producer is shut down.
79      *
80      * @throws IllegalStateException if there is an open transaction
81      * @throws IllegalArgumentException if subtrees contains a subtree which is not accessible by
82      *         this producer
83      * @throws IllegalThreadStateException if the calling thread context does not match the
84      *         lifecycle rules enforced by the producer state (e.g. bound or unbound). This
85      *         exception is thrown on a best effort basis and programs should not rely on it for
86      *         correct operation.
87      */
88     @Override
89     DOMDataTreeProducer createProducer(Collection<DOMDataTreeIdentifier> subtrees);
90
91     /**
92      * {@inheritDoc}.
93      *
94      * @throws DOMDataTreeProducerBusyException when there is an open transaction.
95      */
96     @Override
97     void close() throws DOMDataTreeProducerException;
98 }