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.md.sal.common.api.data;
10 import org.opendaylight.controller.sal.common.DataStoreIdentifier;
11 import org.opendaylight.yangtools.concepts.Path;
12 import org.opendaylight.yangtools.yang.common.RpcResult;
14 * Two phase commit handler (cohort) of the two-phase commit protocol of data.
17 * The provider should expose the implementation of DataCommitHandler if it's
18 * functionality depends on any subset of data stored in data repositories, in
19 * order to participate in {@link DataBrokerService#commit(DataStoreIdentifier)
23 * Operations of two-phase commit handlers should not change data in data store,
24 * this is responsibility of the coordinator (broker or some component of the
27 * The commit handlers are responsible for changing the internal state of the
28 * provider to reflect the commited changes in data.
30 * <h3>Two-phase commit</h3>
32 * <h4>Commit Request Phase</h4>
35 * <li> <code>Consumer</code> edits data by invocation of
36 * <code>DataBrokerService.editCandidateData(DataStoreIdentifier, DataRoot)</code>
37 * <li> <code>Consumer</code> starts a commit by invoking
38 * <code>DataBrokerService.commit(DataStoreIdentifier)</code>
39 * <li> <code>Broker</code> retrieves a list of all registered
40 * <code>DataCommitHandlers</code>
41 * <li>For each <code>DataCommitHandler</code>
43 * <li><code>Broker</code> invokes a
44 * <code>DataCommitHandler.requestCommit(DataStoreIdentifier)</code> operation.
45 * <li><code>DataCommitHandler</code> returns a <code>RpcResult</code> with
46 * <code>CommitTransaction</code>
47 * <li>If the result was successful, broker adds <code>CommitTransaction</code>
48 * to the list of opened transactions. If not, brokers stops a commit request
49 * phase and starts a rollback phase.
51 * <li><code>Broker</code> starts a commit finish phase
54 * <h4>Commit Finish Phase</h4>
57 * <li>For each <code>CommitTransaction</code> from Commit Request phase
59 * <li><code>Broker</code> broker invokes a
60 * <code>CommitTransaction.finish()</code>
61 * <li>The provider finishes a commit (applies the change) and returns an
62 * <code>RpcResult</code>.
66 * <li>If all returned results means successful, the brokers end two-phase
67 * commit by returning a success commit result to the Consumer.
68 * <li>If error occured, the broker starts a commit rollback phase.
72 * <h4>Commit Rollback Phase</h4>
73 * <li>For each <code>DataCommitTransaction</code> from Commit Request phase
75 * <li><code>Broker</code>
76 * broker invokes a {@link DataCommitTransaction#finish()}
77 * <li>The provider rollbacks a commit and returns an {@link RpcResult} of
79 * <li>Broker returns a error result to the consumer.
81 * @param <P> Class representing a path
82 * @param <D> Superclass from which all data objects are derived from.
84 public interface DataCommitHandler<P extends Path<P>, D> {
87 DataCommitTransaction<P, D> requestCommit(DataModification<P,D> modification);
89 public interface DataCommitTransaction<P extends Path<P>, D> {
91 DataModification<P,D> getModification();
97 * This callback is invoked by commit coordinator to finish commit action.
99 * The implementation is required to finish transaction or return unsuccessful
100 * rpc result if something went wrong.
102 * The provider (commit handler) should apply all changes to its state
103 * which are a result of data change-
107 RpcResult<Void> finish() throws IllegalStateException;
110 * Rollbacks a commit.
112 * This callback is invoked by commit coordinator to finish commit action.
114 * The provider (commit handler) should rollback all changes to its state
115 * which were a result of previous request commit.
118 * @throws IllegalStateException
119 * If the method is invoked after {@link #finish()}
121 RpcResult<Void> rollback() throws IllegalStateException;