Do not generate 'isFoo()' methods
[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 org.eclipse.jdt.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 attempt will fail
39  * the producer is already bound, or it has an open transaction. Once bound, the producer can only be accessed
40  * from within the {@link DataTreeListener} callback on that particular instance. Any transaction which is not submitted
41  * by the time the callback returns will be implicitly cancelled. A producer becomes unbound when the listener it is
42  * bound to becomes unregistered.
43  */
44 public interface DataTreeProducer extends DataTreeProducerFactory, AutoCloseable {
45     /**
46      * Allocate a new open transaction on this producer. Any and all transactions previously
47      * allocated must have been either submitted or cancelled by the time this method is invoked.
48      *
49      * @param isolated Indicates whether this transaction should be a barrier. A barrier transaction
50      *        is processed separately from any preceding transactions. Non-barrier transactions may
51      *        be merged and processed in a batch, such that any observers see the modifications
52      *        contained in them as if the modifications were made in a single transaction.
53      * @return A new {@link CursorAwareWriteTransaction}
54      * @throws IllegalStateException if a previous transaction was not closed.
55      * @throws IllegalThreadStateException if the calling thread context does not match the
56      *         lifecycle rules enforced by the producer state (e.g. bound or unbound). This
57      *         exception is thrown on a best effort basis and programs should not rely on it for
58      *         correct operation.
59      */
60     @NonNull CursorAwareWriteTransaction createTransaction(boolean isolated);
61
62     /**
63      * {@inheritDoc}.
64      *
65      *<p>
66      * When invoked on a {@link DataTreeProducer}, this method has additional restrictions. There
67      * may not be an open transaction from this producer. The method needs to be invoked in
68      * appropriate context, e.g. bound or unbound.
69      *
70      *<p>
71      * Specified subtrees must be accessible by this producer. Accessible means they are a subset of
72      * the subtrees specified when the producer is instantiated. The set is further reduced as child
73      * producers are instantiated -- if you create a producer for /a and then a child for /a/b, /a/b
74      * is not accessible from the first producer.
75      *
76      *<p>
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     DataTreeProducer createProducer(Collection<DataTreeIdentifier<?>> subtrees);
90
91     /**
92      * {@inheritDoc}.
93      *
94      * @throws DataTreeProducerBusyException when there is an open transaction.
95      */
96     @Override
97     void close() throws DataTreeProducerException;
98 }