65dad6eebe591ac4fb3262d9030be1cceef3cc2c
[mdsal.git] / dom / mdsal-dom-spi / src / main / java / org / opendaylight / mdsal / dom / spi / store / DOMStoreThreePhaseCommitCohort.java
1 /*
2  * Copyright (c) 2014 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.spi.store;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11
12 /**
13  * Interface implemented by the {@link DOMStore} and exposed for each
14  * {@link DOMStoreWriteTransaction} upon its transition to Ready state. The frontend (DOMStore user)
15  * uses this interface to drive the commit procedure across potentially multiple DOMStores using the
16  * Three-Phase-Commit (3PC) Protocol, as described in <a
17  * href="https://en.wikipedia.org/wiki/Three-phase_commit">Three phase Commit</a>.
18  */
19 public interface DOMStoreThreePhaseCommitCohort {
20
21     /**
22      * Sends transaction associated with this three phase commit instance to the participant,
23      * participant votes on the transaction, if the transaction should be committed or aborted.
24      *
25      * @return ListenableFuture with vote of the participant. Vote {@link ListenableFuture#get()} is
26      *         following:
27      *         <ul>
28      *         <li>
29      *         true if transaction is approved by data store.
30      *         <li>false if the transaction is not approved by data store and should be aborted.
31      *         </ul>
32      */
33     ListenableFuture<Boolean> canCommit();
34
35     /**
36      * Initiates a pre-commit phase of associated transaction on datastore.
37      *
38      * <p>
39      * This message is valid only and only if the participant responded
40      * on {@link #canCommit()} call with positive response.
41      *
42      * @return ListenableFuture representing acknowledgment for participant
43      *        that pre-commit message was received and processed.
44      */
45     ListenableFuture<Void> preCommit();
46
47     /**
48      * Initiates a abort phase of associated transaction on data store.
49      *
50      * @return ListenableFuture representing acknowledgment for participant
51      *        that abort message was received.
52      */
53     ListenableFuture<Void> abort();
54
55     /**
56      * Initiates a commit phase on of associated transaction on data store.
57      *
58      * @return ListenableFuture representing acknowledgment for participant
59      *        that commit message was received and commit of transaction was
60      *        processed.
61      */
62     ListenableFuture<Void> commit();
63 }