2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.core.api.data;
12 import org.opendaylight.controller.sal.common.DataStoreIdentifier;
13 import org.opendaylight.controller.sal.core.api.Provider;
14 import org.opendaylight.yangtools.yang.common.RpcResult;
18 * Two phase commit handler (cohort) of the two-phase commit protocol of data.
21 * The provider should expose the implementation of DataCommitHandler if it's
22 * functionality depends on any subset of data stored in data repositories, in
23 * order to participate in {@link DataBrokerService#commit(DataStoreIdentifier)
27 * Operations of two-phase commit handlers should not change data in data store,
28 * this is responsibility of the coordinator (broker or some component of the
31 * The commit handlers are responsible for changing the internal state of the
32 * provider to reflect the commited changes in data.
34 * <h3>Two-phase commit</h3>
36 * <h4>Commit Request Phase</h4>
39 * <li> <code>Consumer</code> edits data by invocation of
40 * <code>DataBrokerService.editCandidateData(DataStoreIdentifier, CompositeNodeModification)</code>
41 * <li> <code>Consumer</code> starts a commit by invoking
42 * <code>DataBrokerService.commit(DataStoreIdentifier)</code>
43 * <li> <code>Broker</code> retrieves a list of all registered
44 * <code>DataCommitHandlers</code>
45 * <li>For each <code>DataCommitHandler</code>
47 * <li><code>Broker</code> invokes a
48 * <code>DataCommitHandler.requestCommit(DataStoreIdentifier)</code> operation.
49 * <li><code>DataCommitHandler</code> returns a <code>RpcResult</code> with
50 * <code>CommitTransaction</code>
51 * <li>If the result was successful, broker adds <code>CommitTransaction</code>
52 * to the list of opened transactions. If not, brokers stops a commit request
53 * phase and starts a rollback phase.
55 * <li><code>Broker</code> starts a commit finish phase
58 * <h4>Commit Finish Phase</h4>
61 * <li>For each <code>CommitTransaction</code> from Commit Request phase
63 * <li><code>Broker</code> broker invokes a
64 * <code>CommitTransaction.finish()</code>
65 * <li>The provider finishes a commit (applies the change) and returns an
66 * <code>RpcResult</code>.
70 * <li>If all returned results means successful, the brokers end two-phase
71 * commit by returning a success commit result to the Consumer.
72 * <li>If error occured, the broker starts a commit rollback phase.
76 * <h4>Commit Rollback Phase</h4>
77 * <li>For each <code>CommitTransaction</code> from Commit Request phase
79 * <li><code>Broker</code>
81 * broker invokes a {@link CommitTransaction#finish()}
82 * <li>The provider rollbacks a commit and returns an {@link RpcResult} of
84 * <li>Broker returns a error result to the consumer.
87 * <h3>Registration of functionality</h3>
88 * The registration could be done by :
90 * <li>returning an instance of implementation in the return value of
91 * {@link Provider#getProviderFunctionality()}
92 * <li>passing an instance of implementation and {@link DataStoreIdentifier} of
93 * rpc as arguments to the
94 * {@link DataProviderService#addCommitHandler(DataStoreIdentifier, DataCommitHandler)}
99 public interface DataCommitHandler extends Provider.ProviderFunctionality {
102 * A set of Data Stores supported by implementation.
104 * The set of {@link DataStoreIdentifier}s which identifies target data
105 * stores which are supported by this commit handler. This set is used, when
106 * {@link Provider} is registered to the SAL, to register and expose the
107 * commit handler functionality to affected data stores.
109 * @return Set of Data Store identifiers
111 Set<DataStoreIdentifier> getSupportedDataStores();
114 * The provider (commit handler) starts a commit transaction.
117 * The commit handler (provider) prepares an commit scenario, rollback
118 * scenario and validates data.
121 * If the provider is aware that at this point the commit would not be
122 * successful, the transaction is not created, but list of errors which
123 * prevented the start of transaction are returned.
126 * @return Transaction object representing this commit, errors otherwise.
128 RpcResult<CommitTransaction> requestCommit(DataStoreIdentifier store);
130 public interface CommitTransaction {
133 * @return Data store affected by the transaction
135 DataStoreIdentifier getDataStore();
138 * Returns the handler associated with this transaction.
142 DataCommitHandler getHandler();
148 * The provider (commit handler) should apply all changes to its state
149 * which are a result of data change-
153 RpcResult<Void> finish() throws IllegalStateException;
156 * Rollbacks a commit.
159 * @throws IllegalStateException
160 * If the method is invoked after {@link #finish()}
162 RpcResult<Void> rollback() throws IllegalStateException;