blob: c8308af5c4e15a37b35ec73d9c7db7c864559032 [file] [log] [blame]
Madan Jampanicadd70b2016-02-08 13:45:43 -08001/*
2 * Copyright 2016 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.store.primitives.impl;
17
18import java.util.concurrent.CompletableFuture;
19
Madan Jampanicadd70b2016-02-08 13:45:43 -080020/**
21 * Participant in a two-phase commit protocol.
22 */
23public interface TransactionParticipant {
24
25 /**
Madan Jampani74da78b2016-02-09 21:18:36 -080026 * Returns if this participant has updates that need to be committed.
27 * @return {@code true} if yes; {@code false} otherwise
Madan Jampanicadd70b2016-02-08 13:45:43 -080028 */
Madan Jampani542d9e22016-04-05 15:39:55 -070029 default boolean hasPendingUpdates() {
30 return totalUpdates() > 0;
31 }
32
33 /**
34 * Returns the number of updates that need to committed for this participant.
35 * @return update count.
36 */
37 int totalUpdates();
38
39 /**
40 * Executes the prepare and commit steps in a single go.
41 * @return {@code true} is successful i.e updates are committed; {@code false} otherwise
42 */
43 CompletableFuture<Boolean> prepareAndCommit();
Madan Jampani74da78b2016-02-09 21:18:36 -080044
45 /**
46 * Executes the prepare phase.
47 * @return {@code true} is successful; {@code false} otherwise
48 */
49 CompletableFuture<Boolean> prepare();
Madan Jampanicadd70b2016-02-08 13:45:43 -080050
51 /**
52 * Attempts to execute the commit phase for previously prepared transaction.
Madan Jampani74da78b2016-02-09 21:18:36 -080053 * @return future that is completed when the operation completes
Madan Jampanicadd70b2016-02-08 13:45:43 -080054 */
Madan Jampani74da78b2016-02-09 21:18:36 -080055 CompletableFuture<Void> commit();
Madan Jampanicadd70b2016-02-08 13:45:43 -080056
57 /**
58 * Attempts to execute the rollback phase for previously prepared transaction.
Madan Jampani74da78b2016-02-09 21:18:36 -080059 * @return future that is completed when the operation completes
Madan Jampanicadd70b2016-02-08 13:45:43 -080060 */
Madan Jampani74da78b2016-02-09 21:18:36 -080061 CompletableFuture<Void> rollback();
Madan Jampanicadd70b2016-02-08 13:45:43 -080062}