blob: a6e1fbd12499e97c6da46dc969ef480d8f316338 [file] [log] [blame]
Jordan Halterman948d6592017-04-20 17:18:24 -07001/*
2 * Copyright 2017-present 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.service;
17
18import java.util.concurrent.CompletableFuture;
19
20import org.onosproject.store.primitives.TransactionId;
21
22/**
23 * Interface for transactional primitives.
24 */
25public interface Transactional<T> {
26
27 /**
28 * Begins the transaction.
29 *
30 * @param transactionId the transaction identifier for the transaction to begin
31 * @return a completable future to be completed with the lock version
32 */
33 CompletableFuture<Version> begin(TransactionId transactionId);
34
35 /**
36 * Prepares a transaction for commitment.
37 *
38 * @param transactionLog transaction log
39 * @return {@code true} if prepare is successful and transaction is ready to be committed
40 * {@code false} otherwise
41 */
42 CompletableFuture<Boolean> prepare(TransactionLog<T> transactionLog);
43
44 /**
45 * Prepares and commits a transaction.
46 *
47 * @param transactionLog transaction log
48 * @return {@code true} if prepare is successful and transaction was committed
49 * {@code false} otherwise
50 */
51 CompletableFuture<Boolean> prepareAndCommit(TransactionLog<T> transactionLog);
52
53 /**
54 * Commits a previously prepared transaction and unlocks the object.
55 *
56 * @param transactionId transaction identifier
57 * @return future that will be completed when the operation finishes
58 */
59 CompletableFuture<Void> commit(TransactionId transactionId);
60
61 /**
62 * Aborts a previously prepared transaction and unlocks the object.
63 *
64 * @param transactionId transaction identifier
65 * @return future that will be completed when the operation finishes
66 */
67 CompletableFuture<Void> rollback(TransactionId transactionId);
68
69}