blob: 66e1f3a2fc9177629df95d7229436058844cbc7a [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 Jampani74da78b2016-02-09 21:18:36 -080029 boolean hasPendingUpdates();
30
31 /**
32 * Executes the prepare phase.
33 * @return {@code true} is successful; {@code false} otherwise
34 */
35 CompletableFuture<Boolean> prepare();
Madan Jampanicadd70b2016-02-08 13:45:43 -080036
37 /**
38 * Attempts to execute the commit phase for previously prepared transaction.
Madan Jampani74da78b2016-02-09 21:18:36 -080039 * @return future that is completed when the operation completes
Madan Jampanicadd70b2016-02-08 13:45:43 -080040 */
Madan Jampani74da78b2016-02-09 21:18:36 -080041 CompletableFuture<Void> commit();
Madan Jampanicadd70b2016-02-08 13:45:43 -080042
43 /**
44 * Attempts to execute the rollback phase for previously prepared transaction.
Madan Jampani74da78b2016-02-09 21:18:36 -080045 * @return future that is completed when the operation completes
Madan Jampanicadd70b2016-02-08 13:45:43 -080046 */
Madan Jampani74da78b2016-02-09 21:18:36 -080047 CompletableFuture<Void> rollback();
Madan Jampanicadd70b2016-02-08 13:45:43 -080048}