Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.store.primitives.impl; |
| 17 | |
| 18 | import java.util.concurrent.CompletableFuture; |
| 19 | |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 20 | /** |
| 21 | * Participant in a two-phase commit protocol. |
| 22 | */ |
| 23 | public interface TransactionParticipant { |
| 24 | |
| 25 | /** |
Madan Jampani | 74da78b | 2016-02-09 21:18:36 -0800 | [diff] [blame] | 26 | * Returns if this participant has updates that need to be committed. |
| 27 | * @return {@code true} if yes; {@code false} otherwise |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 28 | */ |
Madan Jampani | 542d9e2 | 2016-04-05 15:39:55 -0700 | [diff] [blame] | 29 | 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 Jampani | 74da78b | 2016-02-09 21:18:36 -0800 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * Executes the prepare phase. |
| 47 | * @return {@code true} is successful; {@code false} otherwise |
| 48 | */ |
| 49 | CompletableFuture<Boolean> prepare(); |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Attempts to execute the commit phase for previously prepared transaction. |
Madan Jampani | 74da78b | 2016-02-09 21:18:36 -0800 | [diff] [blame] | 53 | * @return future that is completed when the operation completes |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 54 | */ |
Madan Jampani | 74da78b | 2016-02-09 21:18:36 -0800 | [diff] [blame] | 55 | CompletableFuture<Void> commit(); |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Attempts to execute the rollback phase for previously prepared transaction. |
Madan Jampani | 74da78b | 2016-02-09 21:18:36 -0800 | [diff] [blame] | 59 | * @return future that is completed when the operation completes |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 60 | */ |
Madan Jampani | 74da78b | 2016-02-09 21:18:36 -0800 | [diff] [blame] | 61 | CompletableFuture<Void> rollback(); |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 62 | } |