blob: 02da9d9703e7941cf204eaa88c01973cc5ea0926 [file] [log] [blame]
Madan Jampanicadd70b2016-02-08 13:45:43 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Madan Jampanicadd70b2016-02-08 13:45:43 -08003 *
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 /**
Jordan Halterman948d6592017-04-20 17:18:24 -070026 * Returns a boolean indicating whether the participant has pending updates.
27 *
28 * @return indicates whether the participant has pending updates
Madan Jampanicadd70b2016-02-08 13:45:43 -080029 */
Jordan Halterman948d6592017-04-20 17:18:24 -070030 boolean hasPendingUpdates();
Madan Jampani74da78b2016-02-09 21:18:36 -080031
32 /**
33 * Executes the prepare phase.
Jordan Halterman948d6592017-04-20 17:18:24 -070034 *
Madan Jampani74da78b2016-02-09 21:18:36 -080035 * @return {@code true} is successful; {@code false} otherwise
36 */
37 CompletableFuture<Boolean> prepare();
Madan Jampanicadd70b2016-02-08 13:45:43 -080038
39 /**
40 * Attempts to execute the commit phase for previously prepared transaction.
Jordan Halterman948d6592017-04-20 17:18:24 -070041 *
Madan Jampani74da78b2016-02-09 21:18:36 -080042 * @return future that is completed when the operation completes
Madan Jampanicadd70b2016-02-08 13:45:43 -080043 */
Madan Jampani74da78b2016-02-09 21:18:36 -080044 CompletableFuture<Void> commit();
Madan Jampanicadd70b2016-02-08 13:45:43 -080045
46 /**
Jordan Halterman948d6592017-04-20 17:18:24 -070047 * Executes the prepare and commit phases atomically.
48 *
49 * @return {@code true} is successful; {@code false} otherwise
50 */
51 CompletableFuture<Boolean> prepareAndCommit();
52
53 /**
Madan Jampanicadd70b2016-02-08 13:45:43 -080054 * Attempts to execute the rollback phase for previously prepared transaction.
Jordan Halterman948d6592017-04-20 17:18:24 -070055 *
Madan Jampani74da78b2016-02-09 21:18:36 -080056 * @return future that is completed when the operation completes
Madan Jampanicadd70b2016-02-08 13:45:43 -080057 */
Madan Jampani74da78b2016-02-09 21:18:36 -080058 CompletableFuture<Void> rollback();
Jordan Halterman948d6592017-04-20 17:18:24 -070059
Madan Jampanicadd70b2016-02-08 13:45:43 -080060}