Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -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 | |
| 17 | package org.onosproject.store.service; |
| 18 | |
Madan Jampani | 3780d4b | 2016-04-04 18:18:24 -0700 | [diff] [blame] | 19 | import java.util.concurrent.CompletableFuture; |
| 20 | |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 21 | import org.onosproject.store.primitives.TransactionId; |
| 22 | |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 23 | /** |
| 24 | * Provides a context for transactional operations. |
| 25 | * <p> |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 26 | * A transaction context is a vehicle for grouping operations into a unit with the |
| 27 | * properties of atomicity, isolation, and durability. Transactions also provide the |
| 28 | * ability to maintain an application's invariants or integrity constraints, |
| 29 | * supporting the property of consistency. Together these properties are known as ACID. |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 30 | * <p> |
| 31 | * A transaction context provides a boundary within which transactions |
| 32 | * are run. It also is a place where all modifications made within a transaction |
| 33 | * are cached until the point when the transaction commits or aborts. It thus ensures |
| 34 | * isolation of work happening with in the transaction boundary. Within a transaction |
| 35 | * context isolation level is REPEATABLE_READS i.e. only data that is committed can be read. |
| 36 | * The only uncommitted data that can be read is the data modified by the current transaction. |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 37 | */ |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 38 | public interface TransactionContext extends DistributedPrimitive { |
| 39 | |
| 40 | @Override |
Madan Jampani | 39fff10 | 2016-02-14 13:17:28 -0800 | [diff] [blame] | 41 | default DistributedPrimitive.Type primitiveType() { |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 42 | return DistributedPrimitive.Type.TRANSACTION_CONTEXT; |
| 43 | } |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 44 | |
| 45 | /** |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 46 | * Returns the transaction identifier. |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 47 | * |
| 48 | * @return transaction id |
| 49 | */ |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 50 | TransactionId transactionId(); |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 53 | * Returns if this transaction context is open. |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 54 | * |
| 55 | * @return true if open, false otherwise |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 56 | */ |
| 57 | boolean isOpen(); |
| 58 | |
| 59 | /** |
| 60 | * Starts a new transaction. |
| 61 | */ |
| 62 | void begin(); |
| 63 | |
| 64 | /** |
| 65 | * Commits a transaction that was previously started thereby making its changes permanent |
| 66 | * and externally visible. |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 67 | * |
Madan Jampani | 3780d4b | 2016-04-04 18:18:24 -0700 | [diff] [blame] | 68 | * @return A future that will be completed when the operation completes |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 69 | */ |
Madan Jampani | 3780d4b | 2016-04-04 18:18:24 -0700 | [diff] [blame] | 70 | CompletableFuture<CommitStatus> commit(); |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 71 | |
| 72 | /** |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 73 | * Aborts any changes made in this transaction context and discarding all locally cached updates. |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 74 | */ |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 75 | void abort(); |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 76 | |
| 77 | /** |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 78 | * Returns a transactional map data structure with the specified name. |
| 79 | * |
Ray Milkey | 144eec5 | 2015-02-20 11:22:32 -0800 | [diff] [blame] | 80 | * @param <K> key type |
| 81 | * @param <V> value type |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 82 | * @param mapName name of the transactional map |
| 83 | * @param serializer serializer to use for encoding/decoding keys and values of the map |
| 84 | * @return Transactional Map |
Madan Jampani | 6468955 | 2015-02-17 10:00:27 -0800 | [diff] [blame] | 85 | */ |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 86 | <K, V> TransactionalMap<K, V> getTransactionalMap(String mapName, Serializer serializer); |
Ray Milkey | 144eec5 | 2015-02-20 11:22:32 -0800 | [diff] [blame] | 87 | } |